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

Use PR number for matching commits to PRs in release/guide generator #1852

Merged
merged 1 commit into from
Nov 26, 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
21 changes: 12 additions & 9 deletions generate-release/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ pub fn get_merged_prs(

let mut out = vec![];
for commit in &commits {
let Some(title) = get_pr_title_from_commit(commit) else {
let Some((title, number)) = get_title_parts_from_commit(commit) else {
continue;
};

// Get the PR associated with the commit based on it's title
let Some(pr) = prs.iter().find(|pr| pr.title.contains(&title)) else {
let Some(pr) = prs.iter().find(|pr| pr.number == number) else {
// If there's no label, then not finding a PR is an issue because this means we want all PRs
// If there's a label then it just means the commit is not a PR with the label
if label.is_none() {
Expand All @@ -62,22 +62,25 @@ pub fn get_merged_prs(
Ok(out)
}

fn get_pr_title_from_commit(commit: &GithubCommitResponse) -> Option<String> {
/// Parses the commit message and returns the text without the PR number and the PR
/// number.
fn get_title_parts_from_commit(commit: &GithubCommitResponse) -> Option<(String, u64)> {
let mut message_lines = commit.commit.message.lines();

// Title is always the first line of a commit message
let title = message_lines.next().expect("Commit message empty");

// Get the pr number at the end of the title
let re = Regex::new(r"\(#([\d]*)\)").unwrap();
// Capture the title leading up to the PR number and the PR number
let re = Regex::new(r"(.+?)\(#([\d]*)\)$").unwrap();
let Some(cap) = re.captures_iter(title).last() else {
// This means there wasn't a PR associated with the commit
return None;
};
// remove PR number from title
let title = title.replace(&cap[0].to_string(), "");
let title = title.trim_end();
Some(title.to_string())

let title = cap[1].trim_end().to_string();
let number = cap[2].parse().unwrap();

Some((title, number))
}

/// Returns all the area label for a PR as a list separated with ' + '
Expand Down