Edits history of script submission #1780 for ' Create or update an environment (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Create or update an environment
     * Create or update an environment with protection rules, such as required reviewers.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      environment_name: string,
      body: {
        deployment_branch_policy?: {
          custom_branch_policies: boolean;
          protected_branches: boolean;
          [k: string]: unknown;
        };
        reviewers?: { id?: number; type?: "User" | "Team"; [k: string]: unknown }[];
        wait_timer?: number;
      }
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/environments/${environment_name}`
      );
    
      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.json();
    }
    

    Submitted by hugo697 367 days ago

  • nativets
    type Github = {
      token: string;
    };
    /**
     * Create or update an environment
     * Create or update an environment with protection rules, such as required reviewers.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      environment_name: string,
      body: {
        deployment_branch_policy?: {
          custom_branch_policies: boolean;
          protected_branches: boolean;
          [k: string]: unknown;
        };
        reviewers?: { id?: number; type?: "User" | "Team"; [k: string]: unknown }[];
        wait_timer?: number;
      }
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/environments/${environment_name}`
      );
    
      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.json();
    }
    

    Submitted by hugo697 927 days ago