Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ pub enum ReportedContentClassifiers {
Spam,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, Eq, PartialEq)]
pub enum LockReason {
Copy link
Contributor

@apiraino apiraino Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which of these reasons would apply to the use case "tracking issues are just not for discussions"?

Copy link
Member Author

@Urgau Urgau Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these apply/transmit the idea we want, so I wouldn't use any of them. The reason is optional anyway, I didn't use any of them for this PR.

#[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 {
Expand Down Expand Up @@ -855,6 +867,36 @@ impl Issue {
Ok(())
}

/// Lock an issue with an optional reason.
pub async fn lock(
&self,
client: &GithubClient,
reason: Option<LockReason>,
) -> 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)]
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/major_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading