Edits history of script submission #2393 for ' Set interaction restrictions for a repository (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Set interaction restrictions for a repository
     * Temporarily restricts interactions to a certain type of GitHub user within the given repository. You must have owner or admin access to set these restrictions. If an interaction limit is set for the user or organization that owns this repository, you will receive a `409 Conflict` response and will not be able to use this endpoint to change the interaction limit for a single repository.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      body: {
        expiry?: "one_day" | "three_days" | "one_week" | "one_month" | "six_months";
        limit: "existing_users" | "contributors_only" | "collaborators_only";
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/interaction-limits`
      );
    
      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;
    };
    /**
     * Set interaction restrictions for a repository
     * Temporarily restricts interactions to a certain type of GitHub user within the given repository. You must have owner or admin access to set these restrictions. If an interaction limit is set for the user or organization that owns this repository, you will receive a `409 Conflict` response and will not be able to use this endpoint to change the interaction limit for a single repository.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      body: {
        expiry?: "one_day" | "three_days" | "one_week" | "one_month" | "six_months";
        limit: "existing_users" | "contributors_only" | "collaborators_only";
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/interaction-limits`
      );
    
      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