@@ -320,6 +320,18 @@ pub struct FileDiff {
320
320
pub diff : String ,
321
321
}
322
322
323
+ /// The return from GitHub compare API
324
+ #[ derive( Debug , serde:: Deserialize ) ]
325
+ pub struct GithubCompare {
326
+ /// The base commit of the PR
327
+ pub base_commit : GithubCommit ,
328
+ /// The merge base commit
329
+ ///
330
+ /// See <https://git-scm.com/docs/git-merge-base> for more details
331
+ pub merge_base_commit : GithubCommit ,
332
+ // FIXME: Also retrieve and use the files list (see our diff function)
333
+ }
334
+
323
335
impl PullRequestDetails {
324
336
pub fn new ( ) -> PullRequestDetails {
325
337
PullRequestDetails {
@@ -994,6 +1006,23 @@ impl Issue {
994
1006
Ok ( Some ( diff) )
995
1007
}
996
1008
1009
+ /// Returns the comparison of this event.
1010
+ ///
1011
+ /// Returns `None` if the issue is not a PR.
1012
+ pub async fn compare ( & self , client : & GithubClient ) -> anyhow:: Result < Option < GithubCompare > > {
1013
+ let ( before, after) = if let ( Some ( base) , Some ( head) ) = ( & self . base , & self . head ) {
1014
+ ( & base. sha , & head. sha )
1015
+ } else {
1016
+ return Ok ( None ) ;
1017
+ } ;
1018
+
1019
+ let req = client. get ( & format ! (
1020
+ "{}/compare/{before}...{after}" ,
1021
+ self . repository( ) . url( client)
1022
+ ) ) ;
1023
+ Ok ( Some ( client. json ( req) . await ?) )
1024
+ }
1025
+
997
1026
/// Returns the commits from this pull request (no commits are returned if this `Issue` is not
998
1027
/// a pull request).
999
1028
pub async fn commits ( & self , client : & GithubClient ) -> anyhow:: Result < Vec < GithubCommit > > {
0 commit comments