Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle cargo milestone update for PR from GitHub merge queue #1861

Merged
merged 3 commits into from
Nov 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines +155 to +159
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the regex below has been proved working, this filter hasn't. This may not be necessary. I added because for preventive purpose.

.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