Edits history of script submission #1610 for ' Create a gist (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Create a gist
     * Allows you to add a new gist with one or more files.
    
    **Note:** Don't name your files "gistfile" with a numerical suffix. This is the format of the automatic naming scheme that Gist uses internally.
     */
    export async function main(
      auth: Github,
      body: {
        description?: string;
        files: { [k: string]: { content: string; [k: string]: unknown } };
        public?: boolean | ("true" | "false");
        [k: string]: unknown;
      }
    ) {
      const url = new URL(`https://api.github.com/gists`);
    
      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 399 days ago

  • nativets
    type Github = {
      token: string;
    };
    /**
     * Create a gist
     * Allows you to add a new gist with one or more files.
    
    **Note:** Don't name your files "gistfile" with a numerical suffix. This is the format of the automatic naming scheme that Gist uses internally.
     */
    export async function main(
      auth: Github,
      body: {
        description?: string;
        files: { [k: string]: { content: string; [k: string]: unknown } };
        public?: boolean | ("true" | "false");
        [k: string]: unknown;
      }
    ) {
      const url = new URL(`https://api.github.com/gists`);
    
      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 959 days ago