@@ -4,6 +4,10 @@ use serde::{Deserialize, Serialize};
44
55use crate :: Commit ;
66
7+ #[ derive( Serialize , Deserialize , Debug ) ]
8+ struct GithubCommitComparison {
9+ merge_base_commit : GithubCommitElem ,
10+ }
711#[ derive( Serialize , Deserialize , Debug ) ]
812struct GithubCommitElem {
913 commit : GithubCommit ,
@@ -53,11 +57,11 @@ fn headers() -> Result<reqwest::header::HeaderMap, Error> {
5357}
5458
5559pub ( crate ) fn get_commit ( sha : & str ) -> Result < Commit , Error > {
56- let url = SingleCommitUrl { sha } . url ( ) ;
60+ let url = CommitDetailsUrl { sha } . url ( ) ;
5761 let client = Client :: builder ( ) . default_headers ( headers ( ) ?) . build ( ) ?;
5862 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 ( )
6165}
6266
6367#[ derive( Copy , Clone , Debug ) ]
@@ -89,7 +93,7 @@ struct CommitsUrl<'a> {
8993 since : & ' a str ,
9094 sha : & ' a str ,
9195}
92- struct SingleCommitUrl < ' a > {
96+ struct CommitDetailsUrl < ' a > {
9397 sha : & ' a str ,
9498}
9599
@@ -110,25 +114,23 @@ impl<'a> ToUrl for CommitsUrl<'a> {
110114 }
111115}
112116
113- impl < ' a > ToUrl for SingleCommitUrl < ' a > {
117+ impl < ' a > ToUrl for CommitDetailsUrl < ' a > {
114118 fn url ( & self ) -> String {
115119 // "origin/master" is set as `sha` when there is no `--end=` definition
116120 // specified on the command line. We define the GitHub master branch
117121 // 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"
124124 } 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+ )
132134 }
133135}
134136
0 commit comments