diff --git a/src/handlers/check_commits.rs b/src/handlers/check_commits.rs index 281378c21..a1164dd70 100644 --- a/src/handlers/check_commits.rs +++ b/src/handlers/check_commits.rs @@ -204,6 +204,7 @@ async fn handle_warnings_and_labels( fn warning_from_warnings(warnings: &[String]) -> String { let warnings: Vec<_> = warnings .iter() + .map(|warning| warning.trim().replace("\n", "\n ")) .map(|warning| format!("* {warning}")) .collect(); format!(":warning: **Warning** :warning:\n\n{}", warnings.join("\n")) @@ -241,3 +242,45 @@ fn dummy_commit_from_body(sha: &str, body: &str) -> GithubCommit { parents: vec![], } } + +#[test] +#[rustfmt::skip] +fn test_warning_from_warnings() { + assert_eq!( + warning_from_warnings( + &[ +r#"This line should NOT be intend with 4 spaces, +but this line should!"# + .to_string() + ] + ), +r#":warning: **Warning** :warning: + +* This line should NOT be intend with 4 spaces, + but this line should!"# + ); + + assert_eq!( + warning_from_warnings(&[ +r#"This is warning 1. + +Look at this list: + - 12 + - 13"# + .to_string(), +r#"This is warning 2. + - 123456789 +"# + .to_string() + ]), +r#":warning: **Warning** :warning: + +* This is warning 1. + + Look at this list: + - 12 + - 13 +* This is warning 2. + - 123456789"# + ); +} diff --git a/src/handlers/check_commits/behind_upstream.rs b/src/handlers/check_commits/behind_upstream.rs index efb77bcd2..34dc28dc2 100644 --- a/src/handlers/check_commits/behind_upstream.rs +++ b/src/handlers/check_commits/behind_upstream.rs @@ -29,7 +29,7 @@ pub(super) async fn behind_upstream( return Some(format!( r"This PR is based on an upstream commit that is {} days old. - *It's recommended to update your branch according to the [rustc_dev_guide](https://rustc-dev-guide.rust-lang.org/contributing.html#keeping-your-branch-up-to-date).*", +*It's recommended to update your branch according to the [rustc_dev_guide](https://rustc-dev-guide.rust-lang.org/contributing.html#keeping-your-branch-up-to-date).*", days_old )); } diff --git a/src/handlers/check_commits/issue_links.rs b/src/handlers/check_commits/issue_links.rs index 4d2b91a73..514ed6ad0 100644 --- a/src/handlers/check_commits/issue_links.rs +++ b/src/handlers/check_commits/issue_links.rs @@ -21,7 +21,7 @@ pub(super) fn issue_links_in_commits( .any(|i| c.commit.message.starts_with(i)) }) .filter(|c| LINKED_RE.is_match(&c.commit.message)) - .map(|c| format!(" - {}\n", c.sha)) + .map(|c| format!("- {}\n", c.sha)) .collect::(); if issue_links_commits.is_empty() { @@ -29,7 +29,7 @@ pub(super) fn issue_links_in_commits( } else { Some(format!( r"There are issue links (such as `#123`) in the commit messages of the following commits. - *Please remove them as they will spam the issue with references to the commit.* +*Please remove them as they will spam the issue with references to the commit.* {issue_links_commits}", )) } @@ -72,8 +72,8 @@ fn test_mentions_in_commits() { issue_links_in_commits(&config, &commits), Some( r"There are issue links (such as `#123`) in the commit messages of the following commits. - *Please remove them as they will spam the issue with references to the commit.* - - d7daa17bc97df9377640b0d33cbd0bbeed703c3a +*Please remove them as they will spam the issue with references to the commit.* +- d7daa17bc97df9377640b0d33cbd0bbeed703c3a ".to_string() ) ); @@ -87,9 +87,9 @@ fn test_mentions_in_commits() { issue_links_in_commits(&config, &commits), Some( r"There are issue links (such as `#123`) in the commit messages of the following commits. - *Please remove them as they will spam the issue with references to the commit.* - - d7daa17bc97df9377640b0d33cbd0bbeed703c3a - - 891f0916a07c215ae8173f782251422f1fea6acb +*Please remove them as they will spam the issue with references to the commit.* +- d7daa17bc97df9377640b0d33cbd0bbeed703c3a +- 891f0916a07c215ae8173f782251422f1fea6acb ".to_string() ) ); diff --git a/src/handlers/check_commits/no_mentions.rs b/src/handlers/check_commits/no_mentions.rs index e3f9bc174..559be45d9 100644 --- a/src/handlers/check_commits/no_mentions.rs +++ b/src/handlers/check_commits/no_mentions.rs @@ -10,7 +10,7 @@ pub(super) fn mentions_in_commits( let mentions_commits = commits .into_iter() .filter(|c| !parser::get_mentions(&c.commit.message).is_empty()) - .map(|c| format!(" - {}\n", c.sha)) + .map(|c| format!("- {}\n", c.sha)) .collect::(); if mentions_commits.is_empty() { @@ -18,7 +18,7 @@ pub(super) fn mentions_in_commits( } else { Some(format!( r"There are username mentions (such as `@user`) in the commit messages of the following commits. - *Please remove the mentions to avoid spamming these users.* +*Please remove the mentions to avoid spamming these users.* {mentions_commits}", )) } @@ -53,8 +53,8 @@ Co-authored-by: Baz Qux ", mentions_in_commits(&NoMentionsConfig {}, &commits), Some( r"There are username mentions (such as `@user`) in the commit messages of the following commits. - *Please remove the mentions to avoid spamming these users.* - - d7daa17bc97df9377640b0d33cbd0bbeed703c3a +*Please remove the mentions to avoid spamming these users.* +- d7daa17bc97df9377640b0d33cbd0bbeed703c3a ".to_string() ) ); diff --git a/src/handlers/check_commits/no_merges.rs b/src/handlers/check_commits/no_merges.rs index b8d93e5fb..e5e71fbe2 100644 --- a/src/handlers/check_commits/no_merges.rs +++ b/src/handlers/check_commits/no_merges.rs @@ -61,18 +61,18 @@ so these commits will need to be removed for this pull request to be merged. ); for commit in commits { - writeln!(message, " - {commit}").unwrap(); + writeln!(message, "- {commit}").unwrap(); } writeln!( message, " - You can start a rebase with the following commands: - ```shell-session - $ # rebase - $ git pull --rebase https://github.com/{repository_name}.git {default_branch} - $ git push --force-with-lease - ```" +You can start a rebase with the following commands: +```shell-session +$ # rebase +$ git pull --rebase https://github.com/{repository_name}.git {default_branch} +$ git push --force-with-lease +```" ) .unwrap(); @@ -126,14 +126,14 @@ fn end_to_end() { unreachable!() }; assert_eq!(warning, "The following commits have merge commits (commits with multiple parents) in your changes. We have a [no merge policy](https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy) so these commits will need to be removed for this pull request to be merged. - - 9cc6dce67c917fe5937e984f58f5003ccbb5c37e - - You can start a rebase with the following commands: - ```shell-session - $ # rebase - $ git pull --rebase https://github.com/rust-lang/rust.git master - $ git push --force-with-lease - ``` +- 9cc6dce67c917fe5937e984f58f5003ccbb5c37e + +You can start a rebase with the following commands: +```shell-session +$ # rebase +$ git pull --rebase https://github.com/rust-lang/rust.git master +$ git push --force-with-lease +``` "); assert_eq!(labels, vec!["merge-commits"]); }