Skip to content

Commit 2d73992

Browse files
authored
Merge pull request #2040 from Kobzol/welcome-message-no-fallback
Do not post welcome message when no reviewer is found without fallback
2 parents a801854 + 43a479a commit 2d73992

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ impl AssignConfig {
127127
.iter()
128128
.any(|vacationer| name_lower == vacationer.to_lowercase())
129129
}
130+
131+
/// Return a "fallback" adhoc group, which is used for assigning reviewers if no other
132+
/// reviewer was found.
133+
pub(crate) fn fallback_review_group(&self) -> Option<&[String]> {
134+
self.adhoc_groups.get("fallback").map(|v| v.as_slice())
135+
}
130136
}
131137

132138
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]

src/handlers/assign.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,25 @@ pub(super) async fn handle_input(
211211
}
212212
Some(welcome)
213213
} else if !from_comment {
214-
let welcome = match &assignee {
215-
Some(assignee) => RETURNING_USER_WELCOME_MESSAGE
216-
.replace("{assignee}", &assignee.name)
217-
.replace("{bot}", &ctx.username),
218-
None => RETURNING_USER_WELCOME_MESSAGE_NO_REVIEWER
219-
.replace("{author}", &event.issue.user.login),
220-
};
221-
Some(welcome)
214+
match &assignee {
215+
Some(assignee) => Some(
216+
RETURNING_USER_WELCOME_MESSAGE
217+
.replace("{assignee}", &assignee.name)
218+
.replace("{bot}", &ctx.username),
219+
),
220+
None => {
221+
// If the assign fallback group is empty, then we don't expect any automatic
222+
// assignment, and this message would just be spam.
223+
if config.fallback_review_group().is_some() {
224+
Some(
225+
RETURNING_USER_WELCOME_MESSAGE_NO_REVIEWER
226+
.replace("{author}", &event.issue.user.login),
227+
)
228+
} else {
229+
None
230+
}
231+
}
232+
}
222233
} else {
223234
// No welcome is posted if they are not new and they used `r?` in the opening body.
224235
None
@@ -412,7 +423,7 @@ async fn determine_assignee(
412423
}
413424
}
414425

415-
if let Some(fallback) = config.adhoc_groups.get("fallback") {
426+
if let Some(fallback) = config.fallback_review_group() {
416427
match find_reviewer_from_names(
417428
&mut db_client,
418429
ctx.workqueue.clone(),

0 commit comments

Comments
 (0)