Edits history of script submission #2148 for ' List workflow runs for a workflow (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * List workflow runs for a workflow
     * List all workflow runs for a workflow. You can replace `workflow_id` with the workflow file name. For example, you could use `main.yaml`. You can use parameters to narrow the list of results. For more information about using parameters, see [Parameters](https://docs.github.com/rest/overview/resources-in-the-rest-api#parameters).
    
    Anyone with read access to the repository can use this endpoint. If the repository is private you must use an access token with the `repo` scope.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      workflow_id: string,
      actor: string | undefined,
      branch: string | undefined,
      event: string | undefined,
      status:
        | "completed"
        | "action_required"
        | "cancelled"
        | "failure"
        | "neutral"
        | "skipped"
        | "stale"
        | "success"
        | "timed_out"
        | "in_progress"
        | "queued"
        | "requested"
        | "waiting"
        | "pending"
        | undefined,
      per_page: string | undefined,
      page: string | undefined,
      created: string | undefined,
      exclude_pull_requests: string | undefined,
      check_suite_id: string | undefined,
      head_sha: string | undefined
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`
      );
      for (const [k, v] of [
        ["actor", actor],
        ["branch", branch],
        ["event", event],
        ["status", status],
        ["per_page", per_page],
        ["page", page],
        ["created", created],
        ["exclude_pull_requests", exclude_pull_requests],
        ["check_suite_id", check_suite_id],
        ["head_sha", head_sha],
      ]) {
        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 workflow runs for a workflow
     * List all workflow runs for a workflow. You can replace `workflow_id` with the workflow file name. For example, you could use `main.yaml`. You can use parameters to narrow the list of results. For more information about using parameters, see [Parameters](https://docs.github.com/rest/overview/resources-in-the-rest-api#parameters).
    
    Anyone with read access to the repository can use this endpoint. If the repository is private you must use an access token with the `repo` scope.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      workflow_id: string,
      actor: string | undefined,
      branch: string | undefined,
      event: string | undefined,
      status:
        | "completed"
        | "action_required"
        | "cancelled"
        | "failure"
        | "neutral"
        | "skipped"
        | "stale"
        | "success"
        | "timed_out"
        | "in_progress"
        | "queued"
        | "requested"
        | "waiting"
        | "pending"
        | undefined,
      per_page: string | undefined,
      page: string | undefined,
      created: string | undefined,
      exclude_pull_requests: string | undefined,
      check_suite_id: string | undefined,
      head_sha: string | undefined
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`
      );
      for (const [k, v] of [
        ["actor", actor],
        ["branch", branch],
        ["event", event],
        ["status", status],
        ["per_page", per_page],
        ["page", page],
        ["created", created],
        ["exclude_pull_requests", exclude_pull_requests],
        ["check_suite_id", check_suite_id],
        ["head_sha", head_sha],
      ]) {
        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