Skip to content

Commit fb276dc

Browse files
authored
Merge pull request #160 from mm-zacharydavison/zachary/fetch-deleted-commits-in-github-ci
In GitHub CI: Fetch deleted commits using GitHub PR refs
2 parents 66324c9 + 968c642 commit fb276dc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/ci/github.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct GithubCiEventPayload {
1616

1717
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
1818
struct GithubCiPullRequest {
19+
number: u32,
1920
base: GithubCiPullRequestReference,
2021
head: GithubCiPullRequestReference,
2122
merged: bool,
@@ -54,6 +55,7 @@ pub fn get_github_ci_context() -> Result<Option<CiContext>, GitAiError> {
5455
return Ok(None);
5556
}
5657

58+
let pr_number = pull_request.number;
5759
let head_ref = pull_request.head.ref_name;
5860
let head_sha = pull_request.head.sha;
5961
let base_ref = pull_request.base.ref_name;
@@ -78,6 +80,17 @@ pub fn get_github_ci_context() -> Result<Option<CiContext>, GitAiError> {
7880
clone_dir.clone(),
7981
])?;
8082

83+
// Fetch PR commits using GitHub's special PR refs
84+
// This is necessary because the PR branch may be deleted after merge
85+
// but GitHub keeps the commits accessible via pull/{number}/head
86+
exec_git(&[
87+
"-C".to_string(),
88+
clone_dir.clone(),
89+
"fetch".to_string(),
90+
"origin".to_string(),
91+
format!("pull/{}/head", pr_number),
92+
])?;
93+
8194
let repo = find_repository_in_path(&clone_dir.clone())?;
8295

8396
Ok(Some(CiContext {

0 commit comments

Comments
 (0)