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 changelog generator #2958

Merged
merged 1 commit into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/changelog/src/cli.rs
Expand Up @@ -27,7 +27,7 @@ pub struct Cli {
pub to: String,

/// Path to changelog file
#[clap(short = 'f', long, default_value = "CHANGELOG.md")]
#[clap(short = 'f', long, default_value = "../CHANGELOG.md")]
pub changelog_path: String,

/// Skip writing changelog file
Expand Down
26 changes: 14 additions & 12 deletions tools/changelog/src/create_log_line.rs
Expand Up @@ -6,12 +6,10 @@ use once_cell::sync::Lazy;
use regex::Regex;

use crate::github_issue_labels_fetcher::GitHubIssueLabelsFetcher;
use crate::github_user_fetcher::GitHubUsersFetcher;
use crate::log_line::LogLine;

static REGEX_FOR_ISSUE_ID_CAPTURE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"\s*\(#(\d+)\)").unwrap());
static GITHUB_USERS_FETCHER: Lazy<Mutex<GitHubUsersFetcher>> = Lazy::new(Default::default);
static GITHUB_ISSUE_LABELS_FETCHER: Lazy<Mutex<GitHubIssueLabelsFetcher>> =
Lazy::new(Default::default);

Expand All @@ -21,6 +19,7 @@ pub fn create_log_line(
oid: Result<Oid, Error>,
token: Option<String>,
) -> Result<Option<LogLine>> {
println!("Commit oid: {:?}", oid);
let oid = oid?;
let commit = repo.find_commit(oid)?;
let commit_first_line = commit
Expand All @@ -31,9 +30,16 @@ pub fn create_log_line(
.context("Missing commit message")?
.to_string();
let author = commit.author();
let author_name = author.name().unwrap_or("Unknown");
let email = author.email().context("Missing author's email")?;

if email.contains("dependabot") || email.contains("github-action") {
if email.contains("dependabot") {
println!("email contains dependabot");
return Ok(None);
}

if email.contains("github-action") {
println!("email contains github-action");
return Ok(None);
}

Expand All @@ -44,7 +50,7 @@ pub fn create_log_line(
let captures = match mb_captures {
Some(some) => some,
None => {
eprintln!("Missing issue for commit: {}", oid);
eprintln!("Missing issue for commit: {oid}");
return Ok(None);
}
};
Expand All @@ -61,13 +67,6 @@ pub fn create_log_line(
.as_str()
.to_string();

let user = GITHUB_USERS_FETCHER
.lock()
.map_err(|err| anyhow!("Failed to lock GITHUB_USERS_FETCHER: {}", err))?
.fetch_user_by_commit_author(email, oid.to_string(), token.clone())
.with_context(|| format!("Could not find GitHub user for commit: {}", oid))?
.to_string();

let issue_labels = GITHUB_ISSUE_LABELS_FETCHER
.lock()
.map_err(|err| anyhow!("Failed to lock GITHUB_ISSUE_LABELS_FETCHER: {}", err))?
Expand All @@ -79,14 +78,17 @@ pub fn create_log_line(
.any(|label| package_labels.contains(&label.as_str()));

if !is_issue_for_this_package {
println!("Issue {issue_id} is not for {package_labels:?} packages");
return Ok(None);
}

let log_line = LogLine {
message,
user,
user: author_name.to_string(),
issue_id,
};

println!("{log_line:?}");

Ok(Some(log_line))
}
1 change: 1 addition & 0 deletions tools/changelog/src/log_line.rs
@@ -1,3 +1,4 @@
#[derive(Debug)]
pub struct LogLine {
pub message: String,
pub user: String,
Expand Down
2 changes: 1 addition & 1 deletion tools/changelog/src/write_changelog_file.rs
Expand Up @@ -9,7 +9,7 @@ pub fn write_changelog(changelog_path: &str, version_changelog: &[u8]) -> Result
.context(format!("could not open {} for reading", changelog_path))?;
let old_changelog_reader = BufReader::new(old_changelog);

let changelog_path_new = &format!("{}.new", changelog_path);
let changelog_path_new = &format!("../{}.new", changelog_path);

let mut new_changelog = fs::OpenOptions::new()
.write(true)
Expand Down