Skip to content

Commit 1b966b3

Browse files
committed
[github] fix git end commit retrieval from GitHub when end commit sha is not specified
addresses the bug in #74
1 parent 9533366 commit 1b966b3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/github.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,23 @@ impl<'a> ToUrl for CommitsUrl<'a> {
112112

113113
impl<'a> ToUrl for SingleCommitUrl<'a> {
114114
fn url(&self) -> String {
115-
format!(
116-
"https://api.github.com/repos/{OWNER}/{REPO}/commits/{REF}",
117-
OWNER = OWNER,
118-
REPO = REPO,
119-
REF = self.sha
120-
)
115+
// "origin/master" is set as `sha` when there is no `--end=` definition
116+
// specified on the command line. We define the GitHub master branch
117+
// HEAD commit as the end commit in this case
118+
if &self.sha == &"origin/master" {
119+
format!(
120+
"https://api.github.com/repos/{OWNER}/{REPO}/commits/HEAD",
121+
OWNER = OWNER,
122+
REPO = REPO,
123+
)
124+
} else {
125+
format!(
126+
"https://api.github.com/repos/{OWNER}/{REPO}/commits/{REF}",
127+
OWNER = OWNER,
128+
REPO = REPO,
129+
REF = self.sha
130+
)
131+
}
121132
}
122133
}
123134

0 commit comments

Comments
 (0)