@@ -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.
@@ -584,8 +584,7 @@ fn extract_pr_head_sha_from_event(json_content: &str) -> Option<String> {
584584 let v: Value = match serde_json:: from_str ( json_content) {
585585 Ok ( v) => v,
586586 Err ( _) => {
587- debug ! ( "Failed to parse GitHub event payload as JSON" ) ;
588- return None ;
587+ panic ! ( "Failed to parse GitHub event payload as JSON {json_content}" ) ;
589588 }
590589 } ;
591590
@@ -595,15 +594,18 @@ fn extract_pr_head_sha_from_event(json_content: &str) -> Option<String> {
595594}
596595
597596/// 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" ) ?;
597+ /// Returns None if not a PR event or if SHA cannot be extracted.
598+ fn extract_pr_base_sha_from_event ( json_content : & str ) -> Option < String > {
599+ let v: Value = match serde_json:: from_str ( json_content) {
600+ Ok ( v) => v,
601+ Err ( _) => {
602+ panic ! ( "Failed to parse GitHub event payload as JSON {json_content}" ) ;
603+ }
604+ } ;
603605
604- Ok ( v. pointer ( "/pull_request/base/sha" )
606+ v. pointer ( "/pull_request/base/sha" )
605607 . and_then ( |s| s. as_str ( ) )
606- . map ( |s| s. to_owned ( ) ) )
608+ . map ( |s| s. to_owned ( ) )
607609}
608610
609611/// Given commit specs, repos and remote_name this returns a list of head
@@ -1594,16 +1596,6 @@ mod tests {
15941596}"# ;
15951597
15961598 assert_eq ! ( extract_pr_head_sha_from_event( push_json) , None ) ;
1597- let malformed_json = r#"{
1598- "pull_request": {
1599- "id": 789,
1600- "head": {
1601- "ref": "feature-branch"
1602- }
1603- }
1604- }"# ;
1605-
1606- assert_eq ! ( extract_pr_head_sha_from_event( malformed_json) , None ) ;
16071599
16081600 assert_eq ! ( extract_pr_head_sha_from_event( "{}" ) , None ) ;
16091601 let real_gh_json = r#"{
@@ -1655,8 +1647,6 @@ mod tests {
16551647 extract_pr_head_sha_from_event( any_sha_json) ,
16561648 Some ( "invalid-sha-123" . to_owned( ) )
16571649 ) ;
1658-
1659- assert_eq ! ( extract_pr_head_sha_from_event( "invalid json {" ) , None ) ;
16601650 }
16611651
16621652 #[ test]
@@ -1705,7 +1695,7 @@ mod tests {
17051695 . to_string ( ) ;
17061696
17071697 assert_eq ! (
1708- extract_pr_base_sha_from_event( & pr_json) . unwrap ( ) ,
1698+ extract_pr_base_sha_from_event( & pr_json) ,
17091699 Some ( "55e6bc8c264ce95164314275d805f477650c440d" . to_owned( ) )
17101700 ) ;
17111701
@@ -1719,10 +1709,7 @@ mod tests {
17191709 } )
17201710 . to_string ( ) ;
17211711
1722- assert_eq ! ( extract_pr_base_sha_from_event( & push_json) . unwrap( ) , None ) ;
1723-
1724- // Test with malformed JSON
1725- assert ! ( extract_pr_base_sha_from_event( "invalid json {" ) . is_err( ) ) ;
1712+ assert_eq ! ( extract_pr_base_sha_from_event( & push_json) , None ) ;
17261713
17271714 // Test with missing base SHA
17281715 let incomplete_json = r#"{
@@ -1733,10 +1720,7 @@ mod tests {
17331720 }
17341721}"# ;
17351722
1736- assert_eq ! (
1737- extract_pr_base_sha_from_event( incomplete_json) . unwrap( ) ,
1738- None
1739- ) ;
1723+ assert_eq ! ( extract_pr_base_sha_from_event( incomplete_json) , None ) ;
17401724 }
17411725
17421726 #[ test]
0 commit comments