Edits history of script submission #2361 for ' Set selected repositories for a user secret (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Set selected repositories for a user secret
     * Select the repositories that will use a user's codespace secret.
    
    You must authenticate using an access token with the `codespace` or `codespace:secrets` scope to use this endpoint. User must have Codespaces access to use this endpoint.
    
    GitHub Apps must have write access to the `codespaces_user_secrets` user permission and write access to the `codespaces_secrets` repository permission on all referenced repositories to use this endpoint.
     */
    export async function main(
      auth: Github,
      secret_name: string,
      body: { selected_repository_ids: number[]; [k: string]: unknown }
    ) {
      const url = new URL(
        `https://api.github.com/user/codespaces/secrets/${secret_name}/repositories`
      );
    
      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 selected repositories for a user secret
     * Select the repositories that will use a user's codespace secret.
    
    You must authenticate using an access token with the `codespace` or `codespace:secrets` scope to use this endpoint. User must have Codespaces access to use this endpoint.
    
    GitHub Apps must have write access to the `codespaces_user_secrets` user permission and write access to the `codespaces_secrets` repository permission on all referenced repositories to use this endpoint.
     */
    export async function main(
      auth: Github,
      secret_name: string,
      body: { selected_repository_ids: number[]; [k: string]: unknown }
    ) {
      const url = new URL(
        `https://api.github.com/user/codespaces/secrets/${secret_name}/repositories`
      );
    
      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