Edits history of script submission #1688 for ' Get contextual information for a user (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Get contextual information for a user
     * Provides hovercard information when authenticated through basic auth or OAuth with the `repo` scope.
     */
    export async function main(
      auth: Github,
      username: string,
      subject_type:
        | "organization"
        | "repository"
        | "issue"
        | "pull_request"
        | undefined,
      subject_id: string | undefined
    ) {
      const url = new URL(`https://api.github.com/users/${username}/hovercard`);
      for (const [k, v] of [
        ["subject_type", subject_type],
        ["subject_id", subject_id],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      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;
    };
    /**
     * Get contextual information for a user
     * Provides hovercard information when authenticated through basic auth or OAuth with the `repo` scope.
     */
    export async function main(
      auth: Github,
      username: string,
      subject_type:
        | "organization"
        | "repository"
        | "issue"
        | "pull_request"
        | undefined,
      subject_id: string | undefined
    ) {
      const url = new URL(`https://api.github.com/users/${username}/hovercard`);
      for (const [k, v] of [
        ["subject_type", subject_type],
        ["subject_id", subject_id],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 927 days ago