From e4f1366e12bced48ffc19d2d2c526a6ae3961d7a Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 18 Nov 2024 22:58:18 +0100 Subject: [PATCH 1/2] Add GitHub issue locking helper --- src/github.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/github.rs b/src/github.rs index d6a92688..e878a1d7 100644 --- a/src/github.rs +++ b/src/github.rs @@ -416,6 +416,18 @@ pub enum ReportedContentClassifiers { Spam, } +#[derive(Debug, serde::Deserialize, serde::Serialize, Eq, PartialEq)] +pub enum LockReason { + #[serde(rename = "off-topic")] + OffTopic, + #[serde(rename = "too heated")] + TooHeated, + #[serde(rename = "resolved")] + Resolved, + #[serde(rename = "spam")] + Spam, +} + #[derive(Debug, serde::Deserialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum PullRequestReviewState { @@ -855,6 +867,36 @@ impl Issue { Ok(()) } + /// Lock an issue with an optional reason. + pub async fn lock( + &self, + client: &GithubClient, + reason: Option, + ) -> anyhow::Result<()> { + let lock_url = format!( + "{}/issues/{}/lock", + self.repository().url(client), + self.number + ); + #[derive(serde::Serialize)] + struct LockReasonIssue { + lock_reason: LockReason, + } + client + .send_req({ + let req = client.put(&lock_url); + + if let Some(lock_reason) = reason { + req.json(&LockReasonIssue { lock_reason }) + } else { + req + } + }) + .await + .context("failed to lock issue")?; + Ok(()) + } + pub async fn close(&self, client: &GithubClient) -> anyhow::Result<()> { let edit_url = format!("{}/issues/{}", self.repository().url(client), self.number); #[derive(serde::Serialize)] From d5649f42835bad5e9438a584dddda0a570f6e75f Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 18 Nov 2024 23:00:45 +0100 Subject: [PATCH 2/2] Lock major change issue --- src/handlers/major_change.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/handlers/major_change.rs b/src/handlers/major_change.rs index 0678ea42..834bda4c 100644 --- a/src/handlers/major_change.rs +++ b/src/handlers/major_change.rs @@ -294,6 +294,10 @@ async fn handle( .post_comment(&ctx.github, &comment) .await .context("post major change comment")?; + issue + .lock(&ctx.github, None) + .await + .context("lock major change issue")?; } let zulip_req = zulip_req.send(&ctx.github.raw());