@@ -136,40 +136,65 @@ impl Repository {
136136 pub async fn git_auto ( url : Url ) -> Self {
137137 let url2 = url. clone ( ) ;
138138 match ( url. scheme ( ) , url. domain ( ) ) {
139- ( "http" | "https" , Some ( "github.com" ) ) => Self :: github_from_url ( url) ,
140- ( "http" | "https" , Some ( "gitlab.com" ) ) => Self :: gitlab_from_url ( url) ,
141- ( "http" | "https" , Some ( "codeberg.org" ) ) => Self :: forgejo_from_url ( url) ,
139+ ( "http" | "https" , Some ( "github.com" ) ) => {
140+ log:: debug!( "Trying to parse URL as GitHub repository based on the domain name (github.com)" ) ;
141+ Self :: github_from_url ( url)
142+ . inspect ( |_| log:: info!( "Auto-detected GitHub repository (github.com)" ) )
143+ } ,
144+ ( "http" | "https" , Some ( "gitlab.com" ) ) => {
145+ log:: debug!( "Trying to parse URL as GitLab repository based on the domain name (gitlab.com)" ) ;
146+ Self :: gitlab_from_url ( url)
147+ . inspect ( |_| log:: info!( "Auto-detected GitLab repository (gitlab.com)" ) )
148+ } ,
149+ ( "http" | "https" , Some ( "codeberg.org" ) ) => {
150+ log:: debug!( "Trying to parse URL as Forgejo repository based on the domain name (codeberg.org)" ) ;
151+ Self :: forgejo_from_url ( url)
152+ . inspect ( |_| log:: info!( "Auto-detected Forgejo repository (codeberg.org)" ) )
153+ } ,
142154 ( "http" | "https" , _) => Self :: probe_forge ( url) . await ,
143155 _ => None ,
144156 }
145- . unwrap_or ( Self :: git ( url2) )
157+ . unwrap_or_else ( || {
158+ log:: info!( "No forge was auto-detected, treating as plain git repository" ) ;
159+ Self :: git ( url2)
160+ } )
146161 }
147162
148163 ///
149164 /// Takes in a URL of unknown forge and tries to determine which forge the hoster is
150165 /// And then parse the url into the according Repository Variant
151166 async fn probe_forge ( url : Url ) -> Option < Self > {
152- async fn probe ( mut test_url : Url , path : & str ) -> Result < ( ) > {
153- test_url. set_path ( path) ;
154- let _: serde_json:: Value = get_and_deserialize ( test_url) . await ?;
155- Ok ( ( ) )
156- }
167+ log:: debug!( "Probing {url} for Forgejo and GitLab API endpoints" ) ;
157168
158169 /* We probe some known endpoints unique to the respective GitLab and Forgejo APIs to determine if a corresponding server is running */
159170 let distinct_api_endpoints = [
160171 (
172+ "GitLab" ,
161173 "/api/v4/projects" ,
162174 Self :: gitlab_from_url as fn ( Url ) -> Option < Self > ,
163175 ) ,
164176 (
177+ "Forgejo" ,
165178 "/api/v1/settings/api" ,
166179 Self :: forgejo_from_url as fn ( Url ) -> Option < Self > ,
167180 ) ,
168181 ] ;
169182
170- for ( path, func) in distinct_api_endpoints {
171- if probe ( url. clone ( ) , path) . await . is_ok ( ) {
172- return func ( url) ;
183+ for ( forge_type, path, func) in distinct_api_endpoints {
184+ let probe = |mut test_url : Url | async {
185+ test_url. set_path ( path) ;
186+ log:: debug!( "Probing {test_url} to check for {forge_type}" ) ;
187+ let _: serde_json:: Value = get_and_deserialize ( test_url) . await ?;
188+ Ok :: < ( ) , anyhow:: Error > ( ( ) )
189+ } ;
190+
191+ if probe ( url. clone ( ) ) . await . is_ok ( ) {
192+ return func ( url. clone ( ) ) . inspect ( |_| {
193+ log:: info!(
194+ "Auto-detected {forge_type} repository ({})" ,
195+ url. domain( ) . unwrap( )
196+ )
197+ } )
173198 }
174199 }
175200 None
0 commit comments