Edits history of script submission #2021 for ' Get a tree (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Get a tree
     * Returns a single tree using the SHA1 value for that tree.
    
    If `truncated` is `true` in the response then the number of items in the `tree` array exceeded our maximum limit. If you need to fetch more items, use the non-recursive method of fetching trees, and fetch one sub-tree at a time.
    
    
    **Note**: The limit for the `tree` array is 100,000 entries with a maximum size of 7 MB when using the `recursive` parameter.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      tree_sha: string,
      recursive: string | undefined
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/git/trees/${tree_sha}`
      );
      for (const [k, v] of [["recursive", recursive]]) {
        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 399 days ago

  • nativets
    type Github = {
      token: string;
    };
    /**
     * Get a tree
     * Returns a single tree using the SHA1 value for that tree.
    
    If `truncated` is `true` in the response then the number of items in the `tree` array exceeded our maximum limit. If you need to fetch more items, use the non-recursive method of fetching trees, and fetch one sub-tree at a time.
    
    
    **Note**: The limit for the `tree` array is 100,000 entries with a maximum size of 7 MB when using the `recursive` parameter.
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      tree_sha: string,
      recursive: string | undefined
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/git/trees/${tree_sha}`
      );
      for (const [k, v] of [["recursive", recursive]]) {
        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 959 days ago