@@ -753,6 +753,52 @@ pub struct IssuesEvent {
753753 pub repository : Repository ,
754754 /// Some if action is IssuesAction::Labeled, for example
755755 pub label : Option < Label > ,
756+
757+ // These fields are the sha fields before/after a synchronize operation,
758+ // used to compute the diff between these two commits.
759+ #[ serde( default ) ]
760+ before : Option < String > ,
761+ #[ serde( default ) ]
762+ after : Option < String > ,
763+
764+ #[ serde( default ) ]
765+ base : Option < CommitBase > ,
766+ #[ serde( default ) ]
767+ head : Option < CommitBase > ,
768+ }
769+
770+ #[ derive( Default , Clone , Debug , serde:: Deserialize ) ]
771+ pub struct CommitBase {
772+ sha : String ,
773+ }
774+
775+ impl IssuesEvent {
776+ /// Returns the diff in this event, for Open and Synchronize events for now.
777+ pub async fn diff_between ( & self , client : & GithubClient ) -> anyhow:: Result < Option < String > > {
778+ let ( before, after) = if self . action == IssuesAction :: Synchronize {
779+ (
780+ self . before . clone ( ) . unwrap_or_default ( ) ,
781+ self . after . clone ( ) . unwrap_or_default ( ) ,
782+ )
783+ } else if self . action == IssuesAction :: Opened {
784+ (
785+ self . base . clone ( ) . unwrap_or_default ( ) . sha ,
786+ self . head . clone ( ) . unwrap_or_default ( ) . sha ,
787+ )
788+ } else {
789+ return Ok ( None ) ;
790+ } ;
791+
792+ let mut req = client. get ( & format ! (
793+ "{}/compare/{}...{}" ,
794+ self . issue. repository( ) . url( ) ,
795+ before,
796+ after
797+ ) ) ;
798+ req = req. header ( "Accept" , "application/vnd.github.v3.diff" ) ;
799+ let diff = client. send_req ( req) . await ?;
800+ Ok ( Some ( String :: from ( String :: from_utf8_lossy ( & diff) ) ) )
801+ }
756802}
757803
758804#[ derive( Debug , serde:: Deserialize ) ]
0 commit comments