@@ -4,6 +4,10 @@ use serde::{Deserialize, Serialize};
4
4
5
5
use crate :: Commit ;
6
6
7
+ #[ derive( Serialize , Deserialize , Debug ) ]
8
+ struct GithubCommitComparison {
9
+ merge_base_commit : GithubCommitElem ,
10
+ }
7
11
#[ derive( Serialize , Deserialize , Debug ) ]
8
12
struct GithubCommitElem {
9
13
commit : GithubCommit ,
@@ -53,11 +57,11 @@ fn headers() -> Result<reqwest::header::HeaderMap, Error> {
53
57
}
54
58
55
59
pub ( crate ) fn get_commit ( sha : & str ) -> Result < Commit , Error > {
56
- let url = SingleCommitUrl { sha } . url ( ) ;
60
+ let url = CommitDetailsUrl { sha } . url ( ) ;
57
61
let client = Client :: builder ( ) . default_headers ( headers ( ) ?) . build ( ) ?;
58
62
let response: Response = client. get ( & url) . send ( ) ?;
59
- let elem: GithubCommitElem = response. json ( ) ?;
60
- elem. git_commit ( )
63
+ let elem: GithubCommitComparison = response. json ( ) ?;
64
+ elem. merge_base_commit . git_commit ( )
61
65
}
62
66
63
67
#[ derive( Copy , Clone , Debug ) ]
@@ -89,7 +93,7 @@ struct CommitsUrl<'a> {
89
93
since : & ' a str ,
90
94
sha : & ' a str ,
91
95
}
92
- struct SingleCommitUrl < ' a > {
96
+ struct CommitDetailsUrl < ' a > {
93
97
sha : & ' a str ,
94
98
}
95
99
@@ -110,25 +114,23 @@ impl<'a> ToUrl for CommitsUrl<'a> {
110
114
}
111
115
}
112
116
113
- impl < ' a > ToUrl for SingleCommitUrl < ' a > {
117
+ impl < ' a > ToUrl for CommitDetailsUrl < ' a > {
114
118
fn url ( & self ) -> String {
115
119
// "origin/master" is set as `sha` when there is no `--end=` definition
116
120
// specified on the command line. We define the GitHub master branch
117
121
// 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/master" ,
121
- OWNER = OWNER ,
122
- REPO = REPO ,
123
- )
122
+ let reference = if self . sha == "origin/master" {
123
+ "master"
124
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
- }
125
+ self . sha
126
+ } ;
127
+
128
+ format ! (
129
+ "https://api.github.com/repos/{OWNER}/{REPO}/compare/master...{REF}" ,
130
+ OWNER = OWNER ,
131
+ REPO = REPO ,
132
+ REF = reference
133
+ )
132
134
}
133
135
}
134
136
0 commit comments