Skip to content

Commit

Permalink
fix: handle cargo milestone update for PR from GitHub merge queue
Browse files Browse the repository at this point in the history
Cargo has migrated to GitHub merge queue:
rust-lang/cargo#14718

The regex doesn't work for merge commit made by GitHub merge queue.
This PR adds extra regex pattern to capture that.

This regex has been proved working locally.
See <ehuss/cargo-new-release#2>
  • Loading branch information
weihanglo committed Nov 28, 2024
1 parent d7d4bab commit b98a33a
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/handlers/milestone_prs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,34 @@ 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| {
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)
.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 b98a33a

Please sign in to comment.