Skip to content

Commit 3233df1

Browse files
committed
Allow configuring bot name
1 parent ebad750 commit 3233df1

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

.env.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ GITHUB_WEBHOOK_SECRET=MUST_BE_CONFIGURED
55
# for logging, refer to this document: https://rust-lang-nursery.github.io/rust-cookbook/development_tools/debugging/config_log.html
66
# `RUSTC_LOG` is not required to run the application, but it makes local development easier
77
# RUST_LOG=MUST_BE_CONFIGURED
8+
9+
# If you are running a bot on non-rustbot account,
10+
# this allows to configure that username which the bot will respond to.
11+
# For example write blahblahblah here, if you want for this bot to
12+
# respond to @blahblahblah claim.
13+
# TRIAGEBOT_USERNAME=CAN_BE_CONFIGURED

src/handlers/assign.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ minimum review times lag, PR authors and assigned reviewers should ensure that t
4747
label (`S-waiting-on-review` and `S-waiting-on-author`) stays updated, invoking these commands \
4848
when appropriate:
4949
50-
- `@rustbot author`: the review is finished, PR author should check the comments and take action accordingly
51-
- `@rustbot review`: the author is ready for a review, this PR will be queued again in the reviewer's queue";
50+
- `@{bot} author`: the review is finished, PR author should check the comments and take action accordingly
51+
- `@{bot} review`: the author is ready for a review, this PR will be queued again in the reviewer's queue";
5252

5353
const WELCOME_WITH_REVIEWER: &str = "@{assignee} (or someone else)";
5454

5555
const WELCOME_WITHOUT_REVIEWER: &str = "@Mark-Simulacrum (NB. this repo may be misconfigured)";
5656

5757
const RETURNING_USER_WELCOME_MESSAGE: &str = "r? @{assignee}
5858
59-
(rustbot has picked a reviewer for you, use r? to override)";
59+
({bot} has picked a reviewer for you, use r? to override)";
6060

6161
const RETURNING_USER_WELCOME_MESSAGE_NO_REVIEWER: &str =
6262
"@{author}: no appropriate reviewer found, use r? to override";
@@ -141,12 +141,18 @@ pub(super) async fn handle_input(
141141
let mut welcome = NEW_USER_WELCOME_MESSAGE.replace("{who}", &who_text);
142142
if let Some(contrib) = &config.contributing_url {
143143
welcome.push_str("\n\n");
144-
welcome.push_str(&CONTRIBUTION_MESSAGE.replace("{contributing_url}", contrib));
144+
welcome.push_str(
145+
&CONTRIBUTION_MESSAGE
146+
.replace("{contributing_url}", contrib)
147+
.replace("{bot}", &ctx.username),
148+
);
145149
}
146150
Some(welcome)
147151
} else if !from_comment {
148152
let welcome = match &assignee {
149-
Some(assignee) => RETURNING_USER_WELCOME_MESSAGE.replace("{assignee}", assignee),
153+
Some(assignee) => RETURNING_USER_WELCOME_MESSAGE
154+
.replace("{assignee}", assignee)
155+
.replace("{bot}", &ctx.username),
150156
None => RETURNING_USER_WELCOME_MESSAGE_NO_REVIEWER
151157
.replace("{author}", &event.issue.user.login),
152158
};

src/handlers/glacier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(super) async fn handle_command(
3333

3434
let octocrab = &ctx.octocrab;
3535

36-
let fork = octocrab.repos("rustbot", "glacier");
36+
let fork = octocrab.repos(&ctx.username, "glacier");
3737
let base = octocrab.repos("rust-lang", "glacier");
3838

3939
let master = base
@@ -65,7 +65,7 @@ pub(super) async fn handle_command(
6565
.pulls("rust-lang", "glacier")
6666
.create(
6767
format!("ICE - rust-lang/rust#{}", number),
68-
format!("rustbot:triagebot-ice-{}", number),
68+
format!("{}:triagebot-ice-{}", ctx.username, number),
6969
"master",
7070
)
7171
.body(format!(

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
246246
.build()
247247
.expect("Failed to build octograb.");
248248
let ctx = Arc::new(Context {
249-
username: String::from("rustbot"),
249+
username: std::env::var("TRIAGEBOT_USERNAME").or_else(|err| match err {
250+
std::env::VarError::NotPresent => Ok("rustbot".to_owned()),
251+
err => Err(err),
252+
})?,
250253
db: pool,
251254
github: gh,
252255
octocrab: oc,

0 commit comments

Comments
 (0)