Skip to content

Commit c019cf0

Browse files
committed
fix GitHubRepo::from_string
1 parent c5ca992 commit c019cf0

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/crates/sources/github.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ impl FromStr for GitHubRepo {
9191
type Err = ::failure::Error;
9292

9393
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<_>>();
9699
let org = components.pop();
100+
let name = components.pop();
97101
let sha = components.pop();
98102

99103
if let (Some(org), Some(name)) = (org, name) {
@@ -107,3 +111,29 @@ impl FromStr for GitHubRepo {
107111
}
108112
}
109113
}
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+
}

0 commit comments

Comments
 (0)