flams_git/
lib.rs

1#![cfg_attr(docsrs, feature(doc_auto_cfg))]
2
3#[cfg(feature = "gitlab")]
4pub mod gl;
5
6#[cfg(feature = "git2")]
7pub mod repos;
8
9lazy_static::lazy_static! {
10    pub(crate) static ref REMOTE_SPAN:tracing::Span = {
11            //println!("Here!");
12            tracing::info_span!(target:"git",parent:None,"git")
13    };
14}
15
16#[cfg(any(feature = "git2", feature = "gitlab"))]
17pub trait GitUrlExt {
18    fn into_https(self) -> Self;
19}
20#[cfg(any(feature = "git2", feature = "gitlab"))]
21impl GitUrlExt for git_url_parse::GitUrl {
22    fn into_https(mut self) -> Self {
23        self = self.trim_auth();
24        self.scheme = git_url_parse::Scheme::Https;
25        self.scheme_prefix = true;
26        if !self.path.starts_with('/') {
27            self.path = format!("/{}", self.path);
28        }
29        self
30    }
31}
32
33#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
34pub struct Project {
35    pub id: u64,
36    pub name: String,
37    #[serde(rename = "path_with_namespace")]
38    pub path: String,
39    #[serde(rename = "http_url_to_repo")]
40    pub url: String,
41    pub default_branch: Option<String>,
42}
43
44/*
45[{
46    "id":4,
47    "description":null,
48    "name":"third",
49    "name_with_namespace":"some / third",
50    "path":"third",
51    "path_with_namespace":"some/third",
52    "created_at":"2024-12-23T10:43:32.858Z",
53    "default_branch":"main",
54    "tag_list":[],
55    "topics":[],
56    "ssh_url_to_repo":"git@gitlab.example.com:some/third.git",
57    "http_url_to_repo":"http://gitlab.example.com/some/third.git",
58    "web_url":"http://gitlab.example.com/some/third",
59    "readme_url":null,
60    "forks_count":0,
61    "avatar_url":null,
62    "star_count":0,
63    "last_activity_at":
64    "2024-12-23T10:43:32.822Z",
65    "namespace":{
66        "id":3,
67        "name":"some",
68        "path":"some",
69        "kind":"group",
70        "full_path":"some",
71        "parent_id":null,
72        "avatar_url":null,
73        "web_url":"http://gitlab.example.com/groups/some"
74    },
75    "repository_storage":"default",
76    "_links":{
77        "self":"http://gitlab.example.com/api/v4/projects/4",
78        "issues":"http://gitlab.example.com/api/v4/projects/4/issues",
79        "merge_requests":"http://gitlab.example.com/api/v4/projects/4/merge_requests",
80        "repo_branches":"http://gitlab.example.com/api/v4/projects/4/repository/branches",
81        "labels":"http://gitlab.example.com/api/v4/projects/4/labels",
82        "events":"http://gitlab.example.com/api/v4/projects/4/events",
83        "members":"http://gitlab.example.com/api/v4/projects/4/members",
84        "cluster_agents":"http://gitlab.example.com/api/v4/projects/4/cluster_agents"
85    },
86    "packages_enabled":true,
87    "empty_repo":false,
88    "archived":false,
89    "visibility":"public",
90    "resolve_outdated_diff_discussions":false,
91    "container_expiration_policy":{
92        "cadence":"1d","enabled":false,"keep_n":10,"older_than":"90d","name_regex":".*",
93        "name_regex_keep":null,"next_run_at":"2024-12-24T10:43:32.880Z"
94    },
95    "repository_object_format":"sha1",
96    "issues_enabled":true,
97    "merge_requests_enabled":true,
98    "wiki_enabled":true,
99    "jobs_enabled":true,
100    "snippets_enabled":true,
101    "container_registry_enabled":true,
102    "service_desk_enabled":false,
103    "service_desk_address":null,
104    "can_create_merge_request_in":true,
105    "issues_access_level":"enabled",
106    "repository_access_level":"enabled",
107    "merge_requests_access_level":"enabled",
108    "forking_access_level":"enabled",
109    "wiki_access_level":"enabled",
110    "builds_access_level":"enabled",
111    "snippets_access_level":"enabled",
112    "pages_access_level":"private",
113    "analytics_access_level":"enabled",
114    "container_registry_access_level":"enabled",
115    "security_and_compliance_access_level":"private",
116    "releases_access_level":"enabled",
117    "environments_access_level":"enabled",
118    "feature_flags_access_level":"enabled",
119    "infrastructure_access_level":"enabled",
120    "monitor_access_level":"enabled",
121    "model_experiments_access_level":"enabled",
122    "model_registry_access_level":"enabled",
123    "emails_disabled":false,
124    "emails_enabled":true,
125    "shared_runners_enabled":true,
126    "lfs_enabled":true,
127    "creator_id":2,
128    "import_url":null,
129    "import_type":null,
130    "import_status":"none",
131    "open_issues_count":0,
132    "description_html":"",
133    "updated_at":"2024-12-23T10:44:06.647Z",
134    "ci_default_git_depth":20,
135    "ci_delete_pipelines_in_seconds":null,
136    "ci_forward_deployment_enabled":true,
137    "ci_forward_deployment_rollback_allowed":true,
138    "ci_job_token_scope_enabled":false,
139    "ci_separated_caches":true,
140    "ci_allow_fork_pipelines_to_run_in_parent_project":true,
141    "ci_id_token_sub_claim_components":["project_path","ref_type","ref"],
142    "build_git_strategy":"fetch",
143    "keep_latest_artifact":true,
144    "restrict_user_defined_variables":true,
145    "ci_pipeline_variables_minimum_override_role":"developer",
146    "runners_token":"GR1348941Q6BMWPWzxwoMbcceaybe",
147    "runner_token_expiration_interval":null,
148    "group_runners_enabled":true,
149    "auto_cancel_pending_pipelines":"enabled",
150    "build_timeout":3600,
151    "auto_devops_enabled":true,
152    "auto_devops_deploy_strategy":"continuous",
153    "ci_push_repository_for_job_token_allowed":false,
154    "ci_config_path":null,
155    "public_jobs":true,
156    "shared_with_groups":[],
157    "only_allow_merge_if_pipeline_succeeds":false,
158    "allow_merge_on_skipped_pipeline":null,
159    "request_access_enabled":true,
160    "only_allow_merge_if_all_discussions_are_resolved":false,
161    "remove_source_branch_after_merge":true,
162    "printing_merge_request_link_enabled":true,
163    "merge_method":"merge",
164    "squash_option":"default_off",
165    "enforce_auth_checks_on_uploads":true,
166    "suggestion_commit_message":null,
167    "merge_commit_template":null,
168    "squash_commit_template":null,
169    "issue_branch_template":null,
170    "warn_about_potentially_unwanted_characters":true,
171    "autoclose_referenced_issues":true,
172    "permissions":{"project_access":null,"group_access":null}
173}]
174*/
175
176#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
177pub struct Branch {
178    pub name: String,
179    pub default: bool,
180    pub commit: Commit,
181}
182
183#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
184pub struct Commit {
185    pub id: String,
186    pub created_at: chrono::DateTime<chrono::Utc>,
187    pub parent_ids: Vec<String>,
188    pub title: String,
189    pub message: String,
190    pub author_name: String,
191}
192
193/*
194[
195    {
196        "name":"main",
197        "commit":{
198            "id":"2c10ef48497cb4af1068e194cfe49ea1444321de",
199            "short_id":"2c10ef48",
200            "created_at":"2024-12-23T11:44:01.000+01:00",
201            "parent_ids":[],
202            "title":"init",
203            "message":"init\n",
204            "author_name":"Jazzpirate",
205            "author_email":"raupi@jazzpirate.com",
206            "authored_date":"2024-12-23T11:44:01.000+01:00",
207            "committer_name":"Jazzpirate",
208            "committer_email":"raupi@jazzpirate.com",
209            "committed_date":"2024-12-23T11:44:01.000+01:00",
210            "trailers":{},
211            "extended_trailers":{},
212            "web_url":"http://gitlab.example.com/some/third/-/commit/2c10ef48497cb4af1068e194cfe49ea1444321de"
213        },
214        "merged":false,
215        "protected":true,
216        "developers_can_push":false,
217        "developers_can_merge":false,
218        "can_push":true,
219        "default":true,
220        "web_url":"http://gitlab.example.com/some/third/-/tree/main"
221    }
222]
223     */
224
225#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
226struct TreeEntry {
227    name: String,
228    path: String,
229    #[serde(rename = "type")]
230    kind: DirOrFile,
231}
232
233#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
234enum DirOrFile {
235    #[serde(rename = "tree")]
236    Dir,
237    #[serde(rename = "blob")]
238    File,
239}
240
241/*
242{
243    "id":"2f3cbdf17d7970bda62c7e749b9395295980a5ee",
244    "name":"META-INF",
245    "type":"tree"|"blob",
246    "path":"META-INF",
247    "mode":"040000"
248}
249*/