Lock an issue

Users with push access can lock an issue or pull request's conversation. Note that, if you choose not to pass any parameters, you'll need to set `Content-Length` to zero when calling out to this endpoint. For more information, see "[HTTP verbs](https://docs.github.com/rest/overview/resources-in-the-rest-api#http-verbs)."

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Lock an issue
6
 * Users with push access can lock an issue or pull request's conversation.
7

8
Note that, if you choose not to pass any parameters, you'll need to set `Content-Length` to zero when calling out to this endpoint. For more information, see "[HTTP verbs](https://docs.github.com/rest/overview/resources-in-the-rest-api#http-verbs)."
9
 */
10
export async function main(
11
  auth: Github,
12
  owner: string,
13
  repo: string,
14
  issue_number: string,
15
  body: {
16
    lock_reason?: "off-topic" | "too heated" | "resolved" | "spam";
17
    [k: string]: unknown;
18
  }
19
) {
20
  const url = new URL(
21
    `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/lock`
22
  );
23

24
  const response = await fetch(url, {
25
    method: "PUT",
26
    headers: {
27
      "Content-Type": "application/json",
28
      Authorization: "Bearer " + auth.token,
29
    },
30
    body: JSON.stringify(body),
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.text();
37
}
38