Skip to content

Commit b491703

Browse files
committed
Remove .git with split from github repo name
Previous regex was removing everything after a dot. This caused incorrect repository stats (docopt.rs for example). Fixes: #32
1 parent f43e33f commit b491703

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/utils/github_updater.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,17 @@ fn get_github_fields(path: &str) -> Result<GitHubFields, DocBuilderError> {
120120

121121

122122
fn get_github_path(url: &str) -> Option<String> {
123-
let re = Regex::new(r"https*://github.com/([\w_-]+)/([\w_-]+)(.git)*").unwrap();
123+
let re = Regex::new(r"https?://github\.com/([\w\._-]+)/([\w\._-]+)").unwrap();
124124
match re.captures(url) {
125-
Some(cap) => Some(format!("{}/{}", cap.at(1).unwrap(), cap.at(2).unwrap())),
125+
Some(cap) => {
126+
let username = cap.at(1).unwrap();
127+
let reponame = cap.at(2).unwrap();
128+
Some(format!("{}/{}", username, if reponame.ends_with(".git") {
129+
reponame.split(".git").nth(0).unwrap()
130+
} else {
131+
reponame
132+
}))
133+
},
126134
None => None,
127135
}
128136
}
@@ -144,6 +152,8 @@ mod test {
144152
Some("onur/cratesfyi".to_string()));
145153
assert_eq!(get_github_path("https://github.com/onur23cmD_M_R_L_/crates_fy-i"),
146154
Some("onur23cmD_M_R_L_/crates_fy-i".to_string()));
155+
assert_eq!(get_github_path("https://github.com/docopt/docopt.rs"),
156+
Some("docopt/docopt.rs".to_string()));
147157
}
148158

149159

0 commit comments

Comments
 (0)