Edits history of script submission #2362 for ' Set GitHub Actions permissions for a repository (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Set GitHub Actions permissions for a repository
     * Sets the GitHub Actions permissions policy for enabling GitHub Actions and allowed actions and reusable workflows in the repository.
    
    You must authenticate using an access token with the `repo` scope to use this endpoint. GitHub Apps must have the `administration` repository permission to use this API.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      body: {
        allowed_actions?: "all" | "local_only" | "selected";
        enabled: boolean;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/actions/permissions`
      );
    
      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;
    };
    /**
     * Set GitHub Actions permissions for a repository
     * Sets the GitHub Actions permissions policy for enabling GitHub Actions and allowed actions and reusable workflows in the repository.
    
    You must authenticate using an access token with the `repo` scope to use this endpoint. GitHub Apps must have the `administration` repository permission to use this API.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      body: {
        allowed_actions?: "all" | "local_only" | "selected";
        enabled: boolean;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/actions/permissions`
      );
    
      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