Skip to content

Commit

Permalink
Merge pull request #1861 from weihanglo/milestone-cargo
Browse files Browse the repository at this point in the history
fix: handle cargo milestone update for PR from GitHub merge queue
  • Loading branch information
ehuss authored Nov 30, 2024
2 parents d7d4bab + 6015826 commit 4b28086
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/handlers/milestone_prs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,29 @@ async fn milestone_cargo(
// <https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit>,
// but it is a little awkward to use, only works on the default branch,
// and this is a bit simpler/faster. However, it is sensitive to the
// specific messages generated by bors, and won't catch things merged
// without bors.
let merge_re = Regex::new("(?:Auto merge of|Merge pull request) #([0-9]+)").unwrap();

let pr_nums = commits.iter().filter_map(|commit| {
log::info!(
"getting PR number for cargo commit {} (len={})",
commit.sha,
commit.commit.message.len()
);
merge_re.captures(&commit.commit.message).map(|cap| {
cap.get(1)
.unwrap()
.as_str()
.parse::<u64>()
.expect("digits only")
})
});
// specific messages generated by bors or GitHub merge queue, and won't
// catch things merged beyond them.
let merge_re =
Regex::new(r"(?:Auto merge of|Merge pull request) #([0-9]+)|\(#([0-9]+)\)$").unwrap();

let pr_nums = commits
.iter()
.filter(|commit|
// Assumptions:
// * A merge commit always has two parent commits.
// * Cargo's PR never got merged as fast-forward / rebase / squash merge.
commit.parents.len() == 2)
.filter_map(|commit| {
let first = commit.commit.message.lines().next().unwrap_or_default();
merge_re.captures(first).map(|cap| {
cap.get(1)
.or_else(|| cap.get(2))
.unwrap()
.as_str()
.parse::<u64>()
.expect("digits only")
})
});
let milestone = cargo_repo
.get_or_create_milestone(gh, release_version, "closed")
.await?;
Expand Down

0 comments on commit 4b28086

Please sign in to comment.