Skip to content

Commit

Permalink
Allow configuring bot name
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Oct 15, 2023
1 parent ebad750 commit 960cf29
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ GITHUB_WEBHOOK_SECRET=MUST_BE_CONFIGURED
# for logging, refer to this document: https://rust-lang-nursery.github.io/rust-cookbook/development_tools/debugging/config_log.html
# `RUSTC_LOG` is not required to run the application, but it makes local development easier
# RUST_LOG=MUST_BE_CONFIGURED

# If you are running a bot on non-rustbot account,
# this allows to configure that username which the bot will respond to.
# For example write blahblahblah here, if you want for this bot to
# respond to @blahblahblah claim.
# TRIAGEBOT_USERNAME=CAN_BE_CONFIGURED
16 changes: 11 additions & 5 deletions src/handlers/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ minimum review times lag, PR authors and assigned reviewers should ensure that t
label (`S-waiting-on-review` and `S-waiting-on-author`) stays updated, invoking these commands \
when appropriate:
- `@rustbot author`: the review is finished, PR author should check the comments and take action accordingly
- `@rustbot review`: the author is ready for a review, this PR will be queued again in the reviewer's queue";
- `@{bot} author`: the review is finished, PR author should check the comments and take action accordingly
- `@{bot} review`: the author is ready for a review, this PR will be queued again in the reviewer's queue";

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

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

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

const RETURNING_USER_WELCOME_MESSAGE_NO_REVIEWER: &str =
"@{author}: no appropriate reviewer found, use r? to override";
Expand Down Expand Up @@ -141,12 +141,18 @@ pub(super) async fn handle_input(
let mut welcome = NEW_USER_WELCOME_MESSAGE.replace("{who}", &who_text);
if let Some(contrib) = &config.contributing_url {
welcome.push_str("\n\n");
welcome.push_str(&CONTRIBUTION_MESSAGE.replace("{contributing_url}", contrib));
welcome.push_str(
&CONTRIBUTION_MESSAGE
.replace("{contributing_url}", contrib)
.replace("{bot}", &ctx.username),
);
}
Some(welcome)
} else if !from_comment {
let welcome = match &assignee {
Some(assignee) => RETURNING_USER_WELCOME_MESSAGE.replace("{assignee}", assignee),
Some(assignee) => RETURNING_USER_WELCOME_MESSAGE
.replace("{assignee}", assignee)
.replace("{bot}", self.username),
None => RETURNING_USER_WELCOME_MESSAGE_NO_REVIEWER
.replace("{author}", &event.issue.user.login),
};
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/glacier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(super) async fn handle_command(

let octocrab = &ctx.octocrab;

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

let master = base
Expand Down Expand Up @@ -65,7 +65,7 @@ pub(super) async fn handle_command(
.pulls("rust-lang", "glacier")
.create(
format!("ICE - rust-lang/rust#{}", number),
format!("rustbot:triagebot-ice-{}", number),
format!("{}:triagebot-ice-{}", ctx.username, number),
"master",
)
.body(format!(
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
.build()
.expect("Failed to build octograb.");
let ctx = Arc::new(Context {
username: String::from("rustbot"),
username: std::env::var("TRIAGEBOT_USERNAME").or_else(|err| match err {
std::env::VarError::NotPresent => Ok("rustbot".to_owned()),
err => Err(err),
})?,
db: pool,
github: gh,
octocrab: oc,
Expand Down

0 comments on commit 960cf29

Please sign in to comment.