@@ -575,7 +575,7 @@ pub fn find_base_sha() -> Result<Option<String>> {
575575 . and_then ( |event_path| std:: fs:: read_to_string ( event_path) . map_err ( Error :: from) )
576576 . context ( "Failed to read GitHub event path" ) ?;
577577
578- extract_pr_base_sha_from_event ( & github_event)
578+ Ok ( extract_pr_base_sha_from_event ( & github_event) )
579579}
580580
581581/// Extracts the PR head SHA from GitHub Actions event payload JSON.
@@ -595,15 +595,19 @@ fn extract_pr_head_sha_from_event(json_content: &str) -> Option<String> {
595595}
596596
597597/// Extracts the PR base SHA from GitHub Actions event payload JSON.
598- /// Returns Ok(None) if not a PR event or if SHA cannot be extracted.
599- /// Returns an error if we cannot parse the JSON.
600- fn extract_pr_base_sha_from_event ( json_content : & str ) -> Result < Option < String > > {
601- let v: Value = serde_json:: from_str ( json_content)
602- . context ( "Failed to parse GitHub event payload as JSON" ) ?;
598+ /// Returns None if not a PR event or if SHA cannot be extracted.
599+ fn extract_pr_base_sha_from_event ( json_content : & str ) -> Option < String > {
600+ let v: Value = match serde_json:: from_str ( json_content) {
601+ Ok ( v) => v,
602+ Err ( _) => {
603+ debug ! ( "Failed to parse GitHub event payload as JSON" ) ;
604+ return None ;
605+ }
606+ } ;
603607
604- Ok ( v. pointer ( "/pull_request/base/sha" )
608+ v. pointer ( "/pull_request/base/sha" )
605609 . and_then ( |s| s. as_str ( ) )
606- . map ( |s| s. to_owned ( ) ) )
610+ . map ( |s| s. to_owned ( ) )
607611}
608612
609613/// Given commit specs, repos and remote_name this returns a list of head
@@ -1734,7 +1738,7 @@ mod tests {
17341738}"# ;
17351739
17361740 assert_eq ! (
1737- extract_pr_base_sha_from_event( incomplete_json) . unwrap ( ) ,
1741+ extract_pr_base_sha_from_event( incomplete_json) ,
17381742 None
17391743 ) ;
17401744 }
0 commit comments