@@ -134,40 +134,67 @@ impl Repository {
134134 pub async fn git_auto ( url : Url ) -> Self {
135135 let url2 = url. clone ( ) ;
136136 match ( url. scheme ( ) , url. domain ( ) ) {
137- ( "http" | "https" , Some ( "github.com" ) ) => Self :: github_from_url ( url) ,
138- ( "http" | "https" , Some ( "gitlab.com" ) ) => Self :: gitlab_from_url ( url) ,
139- ( "http" | "https" , Some ( "codeberg.org" ) ) => Self :: forgejo_from_url ( url) ,
137+ ( "http" | "https" , Some ( "github.com" ) ) => {
138+ log:: debug!( "Trying to parse URL as GitHub repository based on the domain name (github.com)" ) ;
139+ Self :: github_from_url ( url)
140+ . inspect ( |_| log:: info!( "Auto-detected GitHub repository (github.com)" ) )
141+ } ,
142+ ( "http" | "https" , Some ( "gitlab.com" ) ) => {
143+ log:: debug!( "Trying to parse URL as GitLab repository based on the domain name (gitlab.com)" ) ;
144+ Self :: gitlab_from_url ( url)
145+ . inspect ( |_| log:: info!( "Auto-detected GitLab repository (gitlab.com)" ) )
146+ } ,
147+ ( "http" | "https" , Some ( "codeberg.org" ) ) => {
148+ log:: debug!( "Trying to parse URL as Forgejo repository based on the domain name (codeberg.org)" ) ;
149+ Self :: forgejo_from_url ( url)
150+ . inspect ( |_| log:: info!( "Auto-detected Forgejo repository (codeberg.org)" ) )
151+ } ,
140152 ( "http" | "https" , _) => Self :: probe_forge ( url) . await ,
141153 _ => None ,
142154 }
143- . unwrap_or ( Self :: git ( url2) )
155+ . unwrap_or_else ( || {
156+ log:: info!( "No forge was auto-detected, treating as plain git repository" ) ;
157+ Self :: git ( url2)
158+ } )
144159 }
145160
146161 ///
147162 /// Takes in a URL of unknown forge and tries to determine which forge the hoster is
148163 /// And then parse the url into the according Repository Variant
149164 async fn probe_forge ( url : Url ) -> Option < Self > {
150- async fn probe ( mut test_url : Url , path : & str ) -> Result < ( ) > {
151- test_url. set_path ( path) ;
152- let _: serde_json:: Value = get_and_deserialize ( test_url) . await ?;
153- Ok ( ( ) )
154- }
165+ log:: debug!( "Probing {url} for Forgejo and GitLab API endpoints" ) ;
155166
156167 /* We probe some known endpoints unique to the respective GitLab and Forgejo APIs to determine if a corresponding server is running */
157168 let distinct_api_endpoints = [
158169 (
170+ "GitLab" ,
159171 "/api/v4/projects" ,
160172 Self :: gitlab_from_url as fn ( Url ) -> Option < Self > ,
161173 ) ,
162174 (
175+ "Forgejo" ,
163176 "/api/v1/settings/api" ,
164177 Self :: forgejo_from_url as fn ( Url ) -> Option < Self > ,
165178 ) ,
166179 ] ;
167180
168- for ( path, func) in distinct_api_endpoints {
169- match probe ( url. clone ( ) , path) . await {
170- Ok ( _) => return func ( url) ,
181+ for ( forge_type, path, func) in distinct_api_endpoints {
182+ let probe = |mut test_url : Url | async {
183+ test_url. set_path ( path) ;
184+ log:: debug!( "Probing {test_url} to check for {forge_type}" ) ;
185+ let _: serde_json:: Value = get_and_deserialize ( test_url) . await ?;
186+ Ok :: < ( ) , anyhow:: Error > ( ( ) )
187+ } ;
188+
189+ match probe ( url. clone ( ) ) . await {
190+ Ok ( _) => {
191+ return func ( url. clone ( ) ) . inspect ( |_| {
192+ log:: info!(
193+ "Auto-detected {forge_type} repository ({})" ,
194+ url. domain( ) . unwrap( )
195+ )
196+ } )
197+ } ,
171198 _ => { } ,
172199 }
173200 }
0 commit comments