Edits history of script submission #22395 for ' Dispatch Workflow Run (github)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    import { Octokit } from "@octokit/rest";
    
    /**
     * @param owner The account owner of the repository. The name is not case sensitive.
     *
     * @param repo The name of the repository. The name is not case sensitive.
     *
     * @param workflow_id The ID of the workflow. You can also pass the workflow file
     * name as a string.
     *
     * @param ref The git reference for the workflow. The reference can be a branch or
     * tag name.
     *
     * @param inputs Input keys and values configured in the workflow file. The maximum
     * number of properties is 10. Any default properties configured in the workflow
     * file will be used when inputs are omitted.
     */
    type Github = {
      token: string;
    };
    export async function main(
      gh_auth: Github,
      owner: string,
      repo: string,
      workflow_id: string,
      ref: string,
      inputs?: Record<string | number, any>
    ) {
      const octokit = new Octokit({ auth: gh_auth.token });
    
      return await octokit.request(
        "POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
        {
          owner,
          repo,
          workflow_id,
          ref,
          inputs: inputs || {},
          headers: {
            "X-GitHub-Api-Version": "2022-11-28",
            Accept: "application/vnd.github+json",
          },
        }
      );
    }
    

    Submitted by hugo989 7 days ago