Edits history of script submission #2165 for ' Lock an issue (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * 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)."
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      issue_number: string,
      body: {
        lock_reason?: "off-topic" | "too heated" | "resolved" | "spam";
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/lock`
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 367 days ago

  • nativets
    type Github = {
      token: string;
    };
    /**
     * 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)."
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      issue_number: string,
      body: {
        lock_reason?: "off-topic" | "too heated" | "resolved" | "spam";
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/lock`
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 927 days ago