Edits history of script submission #1921 for ' Add project collaborator (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Add project collaborator
     * Adds a collaborator to an organization project and sets their permission level. You must be an organization owner or a project `admin` to add a collaborator.
     */
    export async function main(
      auth: Github,
      project_id: string,
      username: string,
      body: { permission?: "read" | "write" | "admin"; [k: string]: unknown }
    ) {
      const url = new URL(
        `https://api.github.com/projects/${project_id}/collaborators/${username}`
      );
    
      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;
    };
    /**
     * Add project collaborator
     * Adds a collaborator to an organization project and sets their permission level. You must be an organization owner or a project `admin` to add a collaborator.
     */
    export async function main(
      auth: Github,
      project_id: string,
      username: string,
      body: { permission?: "read" | "write" | "admin"; [k: string]: unknown }
    ) {
      const url = new URL(
        `https://api.github.com/projects/${project_id}/collaborators/${username}`
      );
    
      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