File tree Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -91,9 +91,13 @@ impl FromStr for GitHubRepo {
91
91
type Err = :: failure:: Error ;
92
92
93
93
fn from_str ( input : & str ) -> Fallible < Self > {
94
- let mut components = input. split ( '/' ) . collect :: < Vec < _ > > ( ) ;
95
- let name = components. pop ( ) ;
94
+ let mut components = input
95
+ . trim_start_matches ( "https://github.com/" )
96
+ . split ( '/' )
97
+ . rev ( )
98
+ . collect :: < Vec < _ > > ( ) ;
96
99
let org = components. pop ( ) ;
100
+ let name = components. pop ( ) ;
97
101
let sha = components. pop ( ) ;
98
102
99
103
if let ( Some ( org) , Some ( name) ) = ( org, name) {
@@ -107,3 +111,29 @@ impl FromStr for GitHubRepo {
107
111
}
108
112
}
109
113
}
114
+
115
+ #[ cfg( test) ]
116
+ mod tests {
117
+ use super :: GitHubRepo ;
118
+ use std:: str:: FromStr ;
119
+
120
+ #[ test]
121
+ fn test_from_str ( ) {
122
+ assert_eq ! (
123
+ GitHubRepo :: from_str( "https://github.com/dummy_org/dummy/dummy_sha" ) . unwrap( ) ,
124
+ GitHubRepo {
125
+ org: "dummy_org" . to_string( ) ,
126
+ name: "dummy" . to_string( ) ,
127
+ sha: Some ( "dummy_sha" . to_string( ) )
128
+ }
129
+ ) ;
130
+ assert_eq ! (
131
+ GitHubRepo :: from_str( "https://github.com/dummy_org/dummy" ) . unwrap( ) ,
132
+ GitHubRepo {
133
+ org: "dummy_org" . to_string( ) ,
134
+ name: "dummy" . to_string( ) ,
135
+ sha: None
136
+ }
137
+ ) ;
138
+ }
139
+ }
You can’t perform that action at this time.
0 commit comments