Edits history of script submission #2222 for ' Create a codespace for the authenticated user (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Create a codespace for the authenticated user
     * Creates a new codespace, owned by the authenticated user.
    
    This endpoint requires either a `repository_id` OR a `pull_request` but not both.
    
    You must authenticate using an access token with the `codespace` scope to use this endpoint.
    
    GitHub Apps must have write access to the `codespaces` repository permission to use this endpoint.
     */
    export async function main(
      auth: Github,
      body:
        | {
            client_ip?: string;
            devcontainer_path?: string;
            display_name?: string;
            idle_timeout_minutes?: number;
            location?: string;
            machine?: string;
            multi_repo_permissions_opt_out?: boolean;
            ref?: string;
            repository_id: number;
            retention_period_minutes?: number;
            working_directory?: string;
            [k: string]: unknown;
          }
        | {
            devcontainer_path?: string;
            idle_timeout_minutes?: number;
            location?: string;
            machine?: string;
            pull_request: {
              pull_request_number: number;
              repository_id: number;
              [k: string]: unknown;
            };
            working_directory?: string;
            [k: string]: unknown;
          }
    ) {
      const url = new URL(`https://api.github.com/user/codespaces`);
    
      const response = await fetch(url, {
        method: "POST",
        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 a codespace for the authenticated user
     * Creates a new codespace, owned by the authenticated user.
    
    This endpoint requires either a `repository_id` OR a `pull_request` but not both.
    
    You must authenticate using an access token with the `codespace` scope to use this endpoint.
    
    GitHub Apps must have write access to the `codespaces` repository permission to use this endpoint.
     */
    export async function main(
      auth: Github,
      body:
        | {
            client_ip?: string;
            devcontainer_path?: string;
            display_name?: string;
            idle_timeout_minutes?: number;
            location?: string;
            machine?: string;
            multi_repo_permissions_opt_out?: boolean;
            ref?: string;
            repository_id: number;
            retention_period_minutes?: number;
            working_directory?: string;
            [k: string]: unknown;
          }
        | {
            devcontainer_path?: string;
            idle_timeout_minutes?: number;
            location?: string;
            machine?: string;
            pull_request: {
              pull_request_number: number;
              repository_id: number;
              [k: string]: unknown;
            };
            working_directory?: string;
            [k: string]: unknown;
          }
    ) {
      const url = new URL(`https://api.github.com/user/codespaces`);
    
      const response = await fetch(url, {
        method: "POST",
        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