Skip to content

Commit bfeafd5

Browse files
authored
Merge pull request #1858 from Urgau/lock-mcp
Lock Major Change Proposal issue
2 parents 4e83f7a + d5649f4 commit bfeafd5

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/github.rs

+42
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,18 @@ pub enum ReportedContentClassifiers {
443443
Spam,
444444
}
445445

446+
#[derive(Debug, serde::Deserialize, serde::Serialize, Eq, PartialEq)]
447+
pub enum LockReason {
448+
#[serde(rename = "off-topic")]
449+
OffTopic,
450+
#[serde(rename = "too heated")]
451+
TooHeated,
452+
#[serde(rename = "resolved")]
453+
Resolved,
454+
#[serde(rename = "spam")]
455+
Spam,
456+
}
457+
446458
#[derive(Debug, serde::Deserialize, Eq, PartialEq)]
447459
#[serde(rename_all = "snake_case")]
448460
pub enum PullRequestReviewState {
@@ -882,6 +894,36 @@ impl Issue {
882894
Ok(())
883895
}
884896

897+
/// Lock an issue with an optional reason.
898+
pub async fn lock(
899+
&self,
900+
client: &GithubClient,
901+
reason: Option<LockReason>,
902+
) -> anyhow::Result<()> {
903+
let lock_url = format!(
904+
"{}/issues/{}/lock",
905+
self.repository().url(client),
906+
self.number
907+
);
908+
#[derive(serde::Serialize)]
909+
struct LockReasonIssue {
910+
lock_reason: LockReason,
911+
}
912+
client
913+
.send_req({
914+
let req = client.put(&lock_url);
915+
916+
if let Some(lock_reason) = reason {
917+
req.json(&LockReasonIssue { lock_reason })
918+
} else {
919+
req
920+
}
921+
})
922+
.await
923+
.context("failed to lock issue")?;
924+
Ok(())
925+
}
926+
885927
pub async fn close(&self, client: &GithubClient) -> anyhow::Result<()> {
886928
let edit_url = format!("{}/issues/{}", self.repository().url(client), self.number);
887929
#[derive(serde::Serialize)]

src/handlers/major_change.rs

+4
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ async fn handle(
294294
.post_comment(&ctx.github, &comment)
295295
.await
296296
.context("post major change comment")?;
297+
issue
298+
.lock(&ctx.github, None)
299+
.await
300+
.context("lock major change issue")?;
297301
}
298302

299303
let zulip_req = zulip_req.send(&ctx.github.raw());

0 commit comments

Comments
 (0)