Edits history of script submission #2223 for ' List commit statuses for a reference (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * List commit statuses for a reference
     * Users with pull access in a repository can view commit statuses for a given ref. The ref can be a SHA, a branch name, or a tag name. Statuses are returned in reverse chronological order. The first status in the list will be the latest one.
    
    This resource is also available via a legacy route: `GET /repos/:owner/:repo/statuses/:ref`.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      ref: string,
      per_page: string | undefined,
      page: string | undefined
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/commits/${ref}/statuses`
      );
      for (const [k, v] of [
        ["per_page", per_page],
        ["page", page],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      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.json();
    }
    

    Submitted by hugo697 367 days ago

  • nativets
    type Github = {
      token: string;
    };
    /**
     * List commit statuses for a reference
     * Users with pull access in a repository can view commit statuses for a given ref. The ref can be a SHA, a branch name, or a tag name. Statuses are returned in reverse chronological order. The first status in the list will be the latest one.
    
    This resource is also available via a legacy route: `GET /repos/:owner/:repo/statuses/:ref`.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      ref: string,
      per_page: string | undefined,
      page: string | undefined
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/commits/${ref}/statuses`
      );
      for (const [k, v] of [
        ["per_page", per_page],
        ["page", page],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      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.json();
    }
    

    Submitted by hugo697 927 days ago