Fix links to authors in the changelog generator (#3421)

* fixed formation of links to authors' Github accounts

* fixed formatting
This commit is contained in:
Tim Kurdov 2023-09-29 12:31:30 +01:00 committed by GitHub
parent 4c3bcdc692
commit fef685ba7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 8 deletions

View File

@ -6,6 +6,7 @@ use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use crate::github_issue_labels_fetcher::GitHubIssueLabelsFetcher; use crate::github_issue_labels_fetcher::GitHubIssueLabelsFetcher;
use crate::github_user_fetcher::GitHubUsersFetcher;
use crate::log_line::LogLine; use crate::log_line::LogLine;
static REGEX_FOR_ISSUE_ID_CAPTURE: Lazy<Regex> = static REGEX_FOR_ISSUE_ID_CAPTURE: Lazy<Regex> =
@ -18,6 +19,7 @@ pub fn create_log_line(
package_labels: &'static [&'static str], package_labels: &'static [&'static str],
oid: Result<Oid, Error>, oid: Result<Oid, Error>,
token: Option<String>, token: Option<String>,
user_fetcher: &mut GitHubUsersFetcher,
) -> Result<Option<LogLine>> { ) -> Result<Option<LogLine>> {
println!("Commit oid: {oid:?}"); println!("Commit oid: {oid:?}");
let oid = oid?; let oid = oid?;
@ -31,6 +33,9 @@ pub fn create_log_line(
.to_string(); .to_string();
let author = commit.author(); let author = commit.author();
let author_name = author.name().unwrap_or("Unknown"); let author_name = author.name().unwrap_or("Unknown");
let author_id = user_fetcher
.fetch_user_by_commit_author(author_name, commit.id().to_string(), token.clone())
.context("Missing author's GitHub ID")?;
let email = author.email().context("Missing author's email")?; let email = author.email().context("Missing author's email")?;
if email.contains("dependabot") { if email.contains("dependabot") {
@ -96,6 +101,7 @@ pub fn create_log_line(
let log_line = LogLine { let log_line = LogLine {
message, message,
user: author_name.to_string(), user: author_name.to_string(),
user_id: author_id.to_string(),
issue_id, issue_id,
is_breaking_change, is_breaking_change,
}; };

View File

@ -2,6 +2,7 @@ use anyhow::{Context, Result};
use git2::{Repository, Sort}; use git2::{Repository, Sort};
use crate::create_log_line::create_log_line; use crate::create_log_line::create_log_line;
use crate::github_user_fetcher::GitHubUsersFetcher;
use crate::log_line::LogLine; use crate::log_line::LogLine;
pub fn create_log_lines( pub fn create_log_lines(
@ -12,6 +13,7 @@ pub fn create_log_lines(
) -> Result<Vec<LogLine>> { ) -> Result<Vec<LogLine>> {
let repo = Repository::open_from_env()?; let repo = Repository::open_from_env()?;
let mut user_fetcher = GitHubUsersFetcher::default();
let from_oid = repo let from_oid = repo
.revparse_single(&from) .revparse_single(&from)
.context("Could not find `from` revision")? .context("Could not find `from` revision")?
@ -28,6 +30,9 @@ pub fn create_log_lines(
revwalk.push(to_oid)?; revwalk.push(to_oid)?;
revwalk revwalk
.filter_map(|oid| create_log_line(&repo, package_labels, oid, token.clone()).transpose()) .filter_map(|oid| {
create_log_line(&repo, package_labels, oid, token.clone(), &mut user_fetcher)
.transpose()
})
.collect() .collect()
} }

View File

@ -1,4 +1,4 @@
use anyhow::Result; use anyhow::{Context, Result};
use git2::Repository; use git2::Repository;
use semver::{Error, Version}; use semver::{Error, Version};
@ -8,7 +8,7 @@ pub fn get_latest_version(package: &YewPackage) -> Result<Version> {
let common_tag_pattern = format!("{package}-v"); let common_tag_pattern = format!("{package}-v");
let search_pattern = format!("{common_tag_pattern}*"); let search_pattern = format!("{common_tag_pattern}*");
let mut tags: Vec<Version> = Repository::open_from_env()? let tags: Vec<Version> = Repository::open_from_env()?
.tag_names(Some(&search_pattern))? .tag_names(Some(&search_pattern))?
.iter() .iter()
.filter_map(|mb_tag| { .filter_map(|mb_tag| {
@ -19,8 +19,5 @@ pub fn get_latest_version(package: &YewPackage) -> Result<Version> {
}) })
.collect::<Result<Vec<Version>, Error>>()?; .collect::<Result<Vec<Version>, Error>>()?;
tags.sort(); tags.into_iter().max().context("no version found")
tags.reverse();
Ok(tags[0].clone())
} }

View File

@ -2,6 +2,7 @@
pub struct LogLine { pub struct LogLine {
pub message: String, pub message: String,
pub user: String, pub user: String,
pub user_id: String,
pub issue_id: String, pub issue_id: String,
pub is_breaking_change: bool, pub is_breaking_change: bool,
} }

View File

@ -10,12 +10,13 @@ pub fn write_log_lines(log_lines: Vec<LogLine>) -> Result<Vec<u8>> {
message, message,
user, user,
issue_id, issue_id,
user_id,
.. ..
} in log_lines } in log_lines
{ {
writeln!( writeln!(
logs_list, logs_list,
"- {message}. [[@{user}](https://github.com/{user}), [#{issue_id}](https://github.com/yewstack/yew/pull/{issue_id})]", "- {message}. [[@{user}](https://github.com/{user_id}), [#{issue_id}](https://github.com/yewstack/yew/pull/{issue_id})]",
)?; )?;
} }
Ok(logs_list) Ok(logs_list)