Skip to content

Commit 8f6a4a3

Browse files
authored
Merge pull request #2037 from Urgau/assign-custom-welcome-messages
Add possibility to have custom welcome messages when assigning
2 parents 0e966bd + 92fc5f7 commit 8f6a4a3

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ pub(crate) struct PingTeamConfig {
9696
#[serde(deny_unknown_fields)]
9797
pub(crate) struct AssignReviewPrefsConfig {}
9898

99+
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
100+
#[serde(rename_all = "kebab-case")]
101+
#[serde(deny_unknown_fields)]
102+
pub(crate) struct AssignCustomWelcomeMessages {
103+
/// Welcome message with reviewer automaticaly chosen (`{assignee}`)
104+
pub(crate) welcome_message: String,
105+
/// Welcome message without a reviewer automaticaly chosen
106+
pub(crate) welcome_message_no_reviewer: String,
107+
}
108+
99109
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
100110
#[serde(deny_unknown_fields)]
101111
pub(crate) struct AssignConfig {
@@ -118,6 +128,9 @@ pub(crate) struct AssignConfig {
118128
/// Should review preferences be taken into account when deciding who to assign to a PR?
119129
#[serde(default)]
120130
pub(crate) review_prefs: Option<AssignReviewPrefsConfig>,
131+
/// Custom welcome messages
132+
#[serde(default)]
133+
pub(crate) custom_welcome_messages: Option<AssignCustomWelcomeMessages>,
121134
}
122135

123136
impl AssignConfig {
@@ -677,6 +690,7 @@ mod tests {
677690
owners: HashMap::new(),
678691
users_on_vacation: HashSet::from(["jyn514".into()]),
679692
review_prefs: None,
693+
custom_welcome_messages: None,
680694
}),
681695
note: Some(NoteConfig { _empty: () }),
682696
ping: Some(PingConfig { teams: ping_teams }),
@@ -722,6 +736,10 @@ mod tests {
722736
[assign]
723737
warn_non_default_branch.enable = true
724738
739+
[assign.custom_welcome_messages]
740+
welcome-message = "Welcome message, assigning {assignee}!"
741+
welcome-message-no-reviewer = "Welcome message for when no reviewer could be found!"
742+
725743
[[assign.warn_non_default_branch.exceptions]]
726744
title = "[beta"
727745
branch = "beta"
@@ -755,6 +773,11 @@ mod tests {
755773
},
756774
],
757775
},
776+
custom_welcome_messages: Some(AssignCustomWelcomeMessages {
777+
welcome_message: "Welcome message, assigning {assignee}!".to_string(),
778+
welcome_message_no_reviewer:
779+
"Welcome message for when no reviewer could be found!".to_string()
780+
}),
758781
contributing_url: None,
759782
adhoc_groups: HashMap::new(),
760783
owners: HashMap::new(),

src/handlers/assign.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,38 @@ pub(super) async fn handle_input(
192192
// want any assignments or noise.
193193
return Ok(());
194194
}
195-
let welcome = if matches!(
195+
let welcome = if let Some(custom_welcome_messages) = &config.custom_welcome_messages {
196+
if !from_comment {
197+
let mut welcome = match &assignee {
198+
Some(assignee) => custom_welcome_messages
199+
.welcome_message
200+
.trim()
201+
.replace("{assignee}", &assignee.name),
202+
None => custom_welcome_messages
203+
.welcome_message_no_reviewer
204+
.trim()
205+
.to_string(),
206+
};
207+
208+
if let Some(contrib) = &config.contributing_url {
209+
if matches!(
210+
event.issue.author_association,
211+
AuthorAssociation::FirstTimer | AuthorAssociation::FirstTimeContributor
212+
) {
213+
welcome.push_str("\n\n");
214+
welcome.push_str(
215+
&CONTRIBUTION_MESSAGE
216+
.replace("{contributing_url}", contrib)
217+
.replace("{bot}", &ctx.username),
218+
);
219+
}
220+
}
221+
Some(welcome)
222+
} else {
223+
// No welcome is posted if they used `r?` in the opening body.
224+
None
225+
}
226+
} else if matches!(
196227
event.issue.author_association,
197228
AuthorAssociation::FirstTimer | AuthorAssociation::FirstTimeContributor
198229
) {

0 commit comments

Comments
 (0)