Skip to content
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