Skip to content

Commit 210178d

Browse files
committed
Reject assignment on a closed PR.
1 parent e2cde71 commit 210178d

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/github.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ pub struct Issue {
297297
/// The head commit for a PR (the branch from the source repo).
298298
#[serde(default)]
299299
pub head: Option<CommitBase>,
300+
/// Whether it is open or closed.
301+
pub state: IssueState,
302+
}
303+
304+
#[derive(Debug, serde::Deserialize, Eq, PartialEq)]
305+
#[serde(rename_all = "snake_case")]
306+
pub enum IssueState {
307+
Open,
308+
Closed,
300309
}
301310

302311
/// Contains only the parts of `Issue` that are needed for turning the issue title into a Zulip
@@ -467,6 +476,10 @@ impl Issue {
467476
self.pull_request.is_some()
468477
}
469478

479+
pub fn is_open(&self) -> bool {
480+
self.state == IssueState::Open
481+
}
482+
470483
pub async fn get_comment(&self, client: &GithubClient, id: usize) -> anyhow::Result<Comment> {
471484
let comment_url = format!("{}/issues/comments/{}", self.repository().url(), id);
472485
let comment = client.json(client.get(&comment_url)).await?;

src/handlers/assign.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ pub(super) async fn handle_command(
414414

415415
let issue = event.issue().unwrap();
416416
if issue.is_pr() {
417+
if !issue.is_open() {
418+
issue
419+
.post_comment(&ctx.github, "Assignment is not allowed on a closed PR.")
420+
.await?;
421+
return Ok(());
422+
}
417423
let username = match cmd {
418424
AssignCommand::Own => event.user().login.clone(),
419425
AssignCommand::User { username } => username,

src/handlers/assign/tests/tests_candidates.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ fn generic_issue(author: &str, repo: &str) -> serde_json::Value {
6565
"labels": [],
6666
"assignees": [],
6767
"comments_url": format!("https://api.github.com/repos/{repo}/pull/1234/comments"),
68+
"state": "open",
6869
})
6970
}
7071

0 commit comments

Comments
 (0)