From d038baabcf6d87e128c2934166b9f26919d76813 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Wed, 23 Oct 2024 13:44:20 +0100 Subject: [PATCH 1/3] feat: Use emoji to signal bot or human user Following on from #36, this change keeps the message structure more uniform. This should mean the messages are slightly easier to visually parse. --- src/main.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index e76c154..ef75182 100644 --- a/src/main.rs +++ b/src/main.rs @@ -205,15 +205,8 @@ async fn main() -> Result<(), Error> { } fn make_message(pull_request: GithubPullRequest, show_pr_age: bool) -> String { - let prefix = if pull_request.user.login.contains("[bot]") { - "🤖🤖🤖 ".to_string() - } else { - "".to_string() - }; - let message = format!( - "{}<{}|{}#{}> - {}", - prefix, + "<{}|{}#{}> - {}", pull_request.html_url.replace("https://", ""), pull_request.head.repo.name, pull_request.number, @@ -226,10 +219,17 @@ fn make_message(pull_request: GithubPullRequest, show_pr_age: bool) -> String { "".to_string() }; - format!( - "{}{} \n\nby {}\n", - message, age_output, pull_request.user.login - ) + let user = format!( + "{} {}", + if pull_request.user.login.contains("[bot]") { + "🤖" + } else { + "👤" + }, + pull_request.user.login + ); + + format!("{}{} \n\n{}\n", message, age_output, user) } fn get_age(d1: DateTime, d2: DateTime) -> String { From 7afe69d1f0271ac0725486efe7f30f94ef25f8ad Mon Sep 17 00:00:00 2001 From: akash1810 Date: Wed, 23 Oct 2024 13:57:15 +0100 Subject: [PATCH 2/3] refactor: Improve readability --- src/main.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index ef75182..8e3bfa7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -219,15 +219,11 @@ fn make_message(pull_request: GithubPullRequest, show_pr_age: bool) -> String { "".to_string() }; - let user = format!( - "{} {}", - if pull_request.user.login.contains("[bot]") { - "🤖" - } else { - "👤" - }, - pull_request.user.login - ); + let user = if pull_request.user.login.contains("[bot]") { + format!("🤖 {}", pull_request.user.login) + } else { + format!("👤 {}", pull_request.user.login) + }; format!("{}{} \n\n{}\n", message, age_output, user) } From b08480d17b2a013bc9b8f7d5c9dd444d29e92322 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Wed, 23 Oct 2024 19:58:51 +0100 Subject: [PATCH 3/3] refactor: More reliable identification of user type --- src/github.rs | 1 + src/main.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/github.rs b/src/github.rs index e47dbaa..019dbbb 100644 --- a/src/github.rs +++ b/src/github.rs @@ -36,6 +36,7 @@ pub struct GithubLabel { pub struct GithubUser { pub id: usize, pub login: String, + pub r#type: String, } #[derive(Deserialize, Debug)] diff --git a/src/main.rs b/src/main.rs index 8e3bfa7..e136030 100644 --- a/src/main.rs +++ b/src/main.rs @@ -219,7 +219,7 @@ fn make_message(pull_request: GithubPullRequest, show_pr_age: bool) -> String { "".to_string() }; - let user = if pull_request.user.login.contains("[bot]") { + let user = if pull_request.user.r#type.to_lowercase() == "bot" { format!("🤖 {}", pull_request.user.login) } else { format!("👤 {}", pull_request.user.login)