Skip to content

Commit a1a20a5

Browse files
committed
fixes
1 parent ee91f28 commit a1a20a5

File tree

1 file changed

+60
-25
lines changed

1 file changed

+60
-25
lines changed

src/handlers/no_merges.rs

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ pub(super) async fn parse_input(
7878
})
7979
}
8080

81+
const DEFAULT_MESSAGE: &str = "
82+
There are merge commits (commits with multiple parents) in your changes. We have a \
83+
[no merge policy](https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy) \
84+
so these commits will need to be removed for this pull request to be merged.
85+
86+
You can start a rebase with the following commands:
87+
```shell-session
88+
$ # rebase
89+
$ git rebase -i master
90+
$ # delete any merge commits in the editor that appears
91+
$ git push --force-with-lease
92+
```
93+
94+
";
95+
8196
pub(super) async fn handle_input(
8297
ctx: &Context,
8398
config: &NoMergesConfig,
@@ -88,37 +103,20 @@ pub(super) async fn handle_input(
88103
let mut state: IssueData<'_, NoMergesState> =
89104
IssueData::load(&mut client, &event.issue, NO_MERGES_KEY).await?;
90105

91-
let mut message = if let Some(ref message) = config.message {
92-
message.clone()
93-
} else {
94-
"
95-
There are merge commits (commits with multiple parents) in your changes. We have a
96-
[no merge policy](https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy) so
97-
these commits will need to be removed for this pull request to be merged.
98-
99-
You can start a rebase with the following commands:
100-
101-
```shell-session
102-
$ # rebase
103-
$ git rebase -i master
104-
$ # delete any merge commits in the editor that appears
105-
$ git push --force-with-lease
106-
```
107-
"
108-
.to_string()
109-
};
106+
let mut message = config
107+
.message
108+
.as_deref()
109+
.unwrap_or(DEFAULT_MESSAGE)
110+
.to_string();
110111

111112
let since_last_posted = if state.data.mentioned_merge_commits.is_empty() {
112113
""
113114
} else {
114115
" (since this message was last posted)"
115116
};
116-
write!(
117+
writeln!(
117118
message,
118-
"
119-
120-
The following commits are merge commits{since_last_posted}:
121-
"
119+
"The following commits are merge commits{since_last_posted}:"
122120
)
123121
.unwrap();
124122

@@ -130,7 +128,7 @@ pub(super) async fn handle_input(
130128

131129
should_send = true;
132130
state.data.mentioned_merge_commits.insert((*commit).clone());
133-
write!(message, "- {commit}").unwrap();
131+
writeln!(message, "- {commit}").unwrap();
134132
}
135133

136134
if should_send {
@@ -157,3 +155,40 @@ pub(super) async fn handle_input(
157155
}
158156
Ok(())
159157
}
158+
159+
#[cfg(test)]
160+
mod test {
161+
use super::*;
162+
163+
#[test]
164+
fn message() {
165+
let mut message = DEFAULT_MESSAGE.to_string();
166+
167+
writeln!(message, "The following commits are merge commits:").unwrap();
168+
169+
for n in 1..5 {
170+
writeln!(message, "- commit{n}").unwrap();
171+
}
172+
173+
assert_eq!(
174+
message,
175+
"
176+
There are 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.
177+
178+
You can start a rebase with the following commands:
179+
```shell-session
180+
$ # rebase
181+
$ git rebase -i master
182+
$ # delete any merge commits in the editor that appears
183+
$ git push --force-with-lease
184+
```
185+
186+
The following commits are merge commits:
187+
- commit1
188+
- commit2
189+
- commit3
190+
- commit4
191+
"
192+
);
193+
}
194+
}

0 commit comments

Comments
 (0)