Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/handlers/check_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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"#
);
}
2 changes: 1 addition & 1 deletion src/handlers/check_commits/behind_upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}
Expand Down
14 changes: 7 additions & 7 deletions src/handlers/check_commits/issue_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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::<String>();

if issue_links_commits.is_empty() {
None
} 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}",
))
}
Expand Down Expand Up @@ -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()
)
);
Expand All @@ -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()
)
);
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/check_commits/no_mentions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ 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::<String>();

if mentions_commits.is_empty() {
None
} 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}",
))
}
Expand Down Expand Up @@ -53,8 +53,8 @@ Co-authored-by: Baz Qux <[email protected]>",
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()
)
);
Expand Down
30 changes: 15 additions & 15 deletions src/handlers/check_commits/no_merges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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"]);
}
Expand Down