Skip to content

Commit a7e8a8d

Browse files
committed
ref(vcs): Make extract_pr_base_sha_from_event like extract_pr_head_sha_from_event
1 parent 0a539c6 commit a7e8a8d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/utils/vcs.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -1733,10 +1737,7 @@ mod tests {
17331737
}
17341738
}"#;
17351739

1736-
assert_eq!(
1737-
extract_pr_base_sha_from_event(incomplete_json).unwrap(),
1738-
None
1739-
);
1740+
assert_eq!(extract_pr_base_sha_from_event(incomplete_json), None);
17401741
}
17411742

17421743
#[test]

0 commit comments

Comments
 (0)