@@ -43,61 +43,14 @@ use tokio::sync::RwLock;
43
43
use tokio_postgres:: Client as DbClient ;
44
44
use tracing as log;
45
45
46
+ mod messages;
47
+
46
48
#[ cfg( test) ]
47
49
mod tests {
48
50
mod tests_candidates;
49
51
mod tests_from_diff;
50
52
}
51
53
52
- const NEW_USER_WELCOME_MESSAGE : & str = "Thanks for the pull request, and welcome! \
53
- The Rust team is excited to review your changes, and you should hear from {who} \
54
- some time within the next two weeks.";
55
-
56
- const CONTRIBUTION_MESSAGE : & str = "Please see [the contribution \
57
- instructions]({contributing_url}) for more information. Namely, in order to ensure the \
58
- minimum review times lag, PR authors and assigned reviewers should ensure that the review \
59
- label (`S-waiting-on-review` and `S-waiting-on-author`) stays updated, invoking these commands \
60
- when appropriate:
61
-
62
- - `@{bot} author`: the review is finished, PR author should check the comments and take action accordingly
63
- - `@{bot} review`: the author is ready for a review, this PR will be queued again in the reviewer's queue" ;
64
-
65
- const WELCOME_WITH_REVIEWER : & str = "@{assignee} (or someone else)" ;
66
-
67
- const WELCOME_WITHOUT_REVIEWER : & str = "@Mark-Simulacrum (NB. this repo may be misconfigured)" ;
68
-
69
- const RETURNING_USER_WELCOME_MESSAGE : & str = "r? @{assignee}
70
-
71
- {bot} has assigned @{assignee}.
72
- They will have a look at your PR within the next two weeks and either review your PR or \
73
- reassign to another reviewer.
74
-
75
- Use `r?` to explicitly pick a reviewer" ;
76
-
77
- const RETURNING_USER_WELCOME_MESSAGE_NO_REVIEWER : & str =
78
- "@{author}: no appropriate reviewer found, use `r?` to override" ;
79
-
80
- fn reviewer_off_rotation_message ( username : & str ) -> String {
81
- format ! (
82
- r"`{username}` is not available for reviewing at the moment.
83
-
84
- Please choose another assignee."
85
- )
86
- }
87
-
88
- const REVIEWER_IS_PR_AUTHOR : & str = "Pull request author cannot be assigned as reviewer.
89
-
90
- Please choose another assignee." ;
91
-
92
- const REVIEWER_ALREADY_ASSIGNED : & str =
93
- "Requested reviewer is already assigned to this pull request.
94
-
95
- Please choose another assignee." ;
96
-
97
- const REVIEWER_ASSIGNED_BEFORE : & str = "Requested reviewer @{username} was already assigned before.
98
-
99
- Please choose another assignee by using `r? @reviewer`." ;
100
-
101
54
// Special account that we use to prevent assignment.
102
55
const GHOST_ACCOUNT : & str = "ghost" ;
103
56
@@ -211,11 +164,7 @@ pub(super) async fn handle_input(
211
164
AuthorAssociation :: FirstTimer | AuthorAssociation :: FirstTimeContributor
212
165
) {
213
166
welcome. push_str ( "\n \n " ) ;
214
- welcome. push_str (
215
- & CONTRIBUTION_MESSAGE
216
- . replace ( "{contributing_url}" , contrib)
217
- . replace ( "{bot}" , & ctx. username ) ,
218
- ) ;
167
+ welcome. push_str ( & messages:: contribution_message ( contrib, & ctx. username ) ) ;
219
168
}
220
169
}
221
170
Some ( welcome)
@@ -227,35 +176,29 @@ pub(super) async fn handle_input(
227
176
event. issue. author_association,
228
177
AuthorAssociation :: FirstTimer | AuthorAssociation :: FirstTimeContributor
229
178
) {
230
- let who_text = match & assignee {
231
- Some ( assignee) => WELCOME_WITH_REVIEWER . replace ( "{assignee}" , & assignee. name ) ,
232
- None => WELCOME_WITHOUT_REVIEWER . to_string ( ) ,
179
+ let assignee_text = match & assignee {
180
+ Some ( assignee) => messages :: welcome_with_reviewer ( & assignee. name ) ,
181
+ None => messages :: WELCOME_WITHOUT_REVIEWER . to_string ( ) ,
233
182
} ;
234
- let mut welcome = NEW_USER_WELCOME_MESSAGE . replace ( "{who}" , & who_text ) ;
183
+ let mut welcome = messages :: new_user_welcome_message ( & assignee_text ) ;
235
184
if let Some ( contrib) = & config. contributing_url {
236
185
welcome. push_str ( "\n \n " ) ;
237
- welcome. push_str (
238
- & CONTRIBUTION_MESSAGE
239
- . replace ( "{contributing_url}" , contrib)
240
- . replace ( "{bot}" , & ctx. username ) ,
241
- ) ;
186
+ welcome. push_str ( & messages:: contribution_message ( contrib, & ctx. username ) ) ;
242
187
}
243
188
Some ( welcome)
244
189
} else if !from_comment {
245
190
match & assignee {
246
- Some ( assignee) => Some (
247
- RETURNING_USER_WELCOME_MESSAGE
248
- . replace ( "{assignee}" , & assignee. name )
249
- . replace ( "{bot}" , & ctx. username ) ,
250
- ) ,
191
+ Some ( assignee) => Some ( messages:: returning_user_welcome_message (
192
+ & assignee. name ,
193
+ & ctx. username ,
194
+ ) ) ,
251
195
None => {
252
196
// If the assign fallback group is empty, then we don't expect any automatic
253
197
// assignment, and this message would just be spam.
254
198
if config. fallback_review_group ( ) . is_some ( ) {
255
- Some (
256
- RETURNING_USER_WELCOME_MESSAGE_NO_REVIEWER
257
- . replace ( "{author}" , & event. issue . user . login ) ,
258
- )
199
+ Some ( messages:: returning_user_welcome_message_no_reviewer (
200
+ & event. issue . user . login ,
201
+ ) )
259
202
} else {
260
203
None
261
204
}
@@ -807,28 +750,16 @@ impl fmt::Display for FindReviewerError {
807
750
)
808
751
}
809
752
FindReviewerError :: ReviewerOffRotation { username } => {
810
- write ! ( f, "{}" , reviewer_off_rotation_message( username) )
753
+ write ! ( f, "{}" , messages :: reviewer_off_rotation_message( username) )
811
754
}
812
- FindReviewerError :: ReviewerIsPrAuthor { username } => {
813
- write ! (
814
- f,
815
- "{}" ,
816
- REVIEWER_IS_PR_AUTHOR . replace( "{username}" , username)
817
- )
755
+ FindReviewerError :: ReviewerIsPrAuthor { .. } => {
756
+ write ! ( f, "{}" , messages:: REVIEWER_IS_PR_AUTHOR )
818
757
}
819
- FindReviewerError :: ReviewerAlreadyAssigned { username } => {
820
- write ! (
821
- f,
822
- "{}" ,
823
- REVIEWER_ALREADY_ASSIGNED . replace( "{username}" , username)
824
- )
758
+ FindReviewerError :: ReviewerAlreadyAssigned { .. } => {
759
+ write ! ( f, "{}" , messages:: REVIEWER_ALREADY_ASSIGNED )
825
760
}
826
761
FindReviewerError :: ReviewerPreviouslyAssigned { username } => {
827
- write ! (
828
- f,
829
- "{}" ,
830
- REVIEWER_ASSIGNED_BEFORE . replace( "{username}" , username)
831
- )
762
+ write ! ( f, "{}" , messages:: reviewer_assigned_before( username) )
832
763
}
833
764
FindReviewerError :: DatabaseError ( error) => {
834
765
write ! ( f, "Database error: {error}" )
0 commit comments