Edits history of script submission #2166 for ' Check if a user can be assigned to a issue (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Check if a user can be assigned to a issue
     * Checks if a user has permission to be assigned to a specific issue.
    
    If the `assignee` can be assigned to this issue, a `204` status code with no content is returned.
    
    Otherwise a `404` status code is returned.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      issue_number: string,
      assignee: string
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/assignees/${assignee}`
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      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;
    };
    /**
     * Check if a user can be assigned to a issue
     * Checks if a user has permission to be assigned to a specific issue.
    
    If the `assignee` can be assigned to this issue, a `204` status code with no content is returned.
    
    Otherwise a `404` status code is returned.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      issue_number: string,
      assignee: string
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/assignees/${assignee}`
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 927 days ago