Skip to content

Commit ad8d3dc

Browse files
authored
Merge pull request #1943 from Kobzol/request-ghost
Allow review requesting ghost
2 parents a96e686 + 29cb0a0 commit ad8d3dc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/handlers/assign.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ const REVIEWER_ALREADY_ASSIGNED: &str =
8787
8888
Please choose another assignee.";
8989

90+
// Special account that we use to prevent assignment.
91+
const GHOST_ACCOUNT: &str = "ghost";
92+
9093
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
9194
struct AssignData {
9295
user: Option<String>,
@@ -132,7 +135,7 @@ pub(super) async fn handle_input(
132135
// Don't auto-assign or welcome if the user manually set the assignee when opening.
133136
if event.issue.assignees.is_empty() {
134137
let (assignee, from_comment) = determine_assignee(ctx, event, config, &diff).await?;
135-
if assignee.as_deref() == Some("ghost") {
138+
if assignee.as_deref() == Some(GHOST_ACCOUNT) {
136139
// "ghost" is GitHub's placeholder account for deleted accounts.
137140
// It is used here as a convenient way to prevent assignment. This
138141
// is typically used for rollups or experiments where you don't
@@ -473,6 +476,15 @@ pub(super) async fn handle_command(
473476
}
474477
};
475478

479+
// In the PR body, `r? ghost` means "do not assign anybody".
480+
// When you send `r? ghost` in a PR comment, it should mean "unassign the current assignee".
481+
// Only allow this for the PR author (usually when they forget to do `r? ghost` in the PR
482+
// body), otherwise anyone could remove assignees from any PR.
483+
if assignee == GHOST_ACCOUNT && issue.user.login == event.user().login {
484+
issue.remove_assignees(&ctx.github, Selection::All).await?;
485+
return Ok(());
486+
}
487+
476488
let db_client = ctx.db.get().await;
477489
let assignee = match find_reviewer_from_names(
478490
&db_client,
@@ -693,11 +705,6 @@ async fn find_reviewer_from_names(
693705
candidates
694706
);
695707

696-
// Special case user "ghost", we always skip filtering
697-
if candidates.contains("ghost") {
698-
return Ok("ghost".to_string());
699-
}
700-
701708
// Return unfiltered list of candidates
702709
Ok(candidates
703710
.into_iter()

0 commit comments

Comments
 (0)