@@ -51,6 +51,30 @@ impl Git {
51
51
} )
52
52
}
53
53
54
+ pub fn extract_slug_from_remote ( output : String ) -> Result < String , VcsError > {
55
+ // [email protected] :moonrepo/moon.git
56
+ let remote = if output. starts_with ( "git@" ) {
57
+ format ! ( "https://{}" , output. replace( ':' , "/" ) )
58
+ // https://github.com/moonrepo/moon
59
+ } else {
60
+ output
61
+ } ;
62
+
63
+ let url = url:: Url :: parse ( & remote)
64
+ . map_err ( |e| VcsError :: FailedToParseGitRemote ( e. to_string ( ) ) ) ?;
65
+ let mut slug = url. path ( ) ;
66
+
67
+ if slug. starts_with ( '/' ) {
68
+ slug = & slug[ 1 ..] ;
69
+ }
70
+
71
+ if slug. ends_with ( ".git" ) {
72
+ slug = & slug[ 0 ..( slug. len ( ) - 4 ) ] ;
73
+ }
74
+
75
+ Ok ( slug. to_owned ( ) )
76
+ }
77
+
54
78
async fn get_merge_base ( & self , base : & str , head : & str ) -> VcsResult < String > {
55
79
let mut args = string_vec ! [ "merge-base" , head] ;
56
80
let mut candidates = string_vec ! [ base. to_owned( ) ] ;
@@ -240,27 +264,7 @@ impl Vcs for Git {
240
264
)
241
265
. await ?;
242
266
243
- // [email protected] :moonrepo/moon.git
244
- let remote = if output. starts_with ( "git@" ) {
245
- format ! ( "https://{}" , output. replace( ':' , "/" ) )
246
- // https://github.com/moonrepo/moon
247
- } else {
248
- output
249
- } ;
250
-
251
- let url = url:: Url :: parse ( & remote)
252
- . map_err ( |e| VcsError :: FailedToParseGitRemote ( e. to_string ( ) ) ) ?;
253
- let mut slug = url. path ( ) ;
254
-
255
- if slug. starts_with ( '/' ) {
256
- slug = & slug[ 1 ..] ;
257
- }
258
-
259
- if slug. ends_with ( ".git" ) {
260
- slug = & slug[ 0 ..( slug. len ( ) - 4 ) ] ;
261
- }
262
-
263
- Ok ( slug. to_owned ( ) )
267
+ Self :: extract_slug_from_remote ( output)
264
268
}
265
269
266
270
// https://git-scm.com/docs/git-status#_short_format
0 commit comments