Get all contributor commit activity

Returns the `total` number of commits authored by the contributor. In addition, the response includes a Weekly Hash (`weeks` array) with the following information: * `w` - Start of the week, given as a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time). * `a` - Number of additions * `d` - Number of deletions * `c` - Number of commits

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get all contributor commit activity
6
 * 
7
Returns the `total` number of commits authored by the contributor. In addition, the response includes a Weekly Hash (`weeks` array) with the following information:
8

9
*   `w` - Start of the week, given as a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time).
10
*   `a` - Number of additions
11
*   `d` - Number of deletions
12
*   `c` - Number of commits
13
 */
14
export async function main(auth: Github, owner: string, repo: string) {
15
  const url = new URL(
16
    `https://api.github.com/repos/${owner}/${repo}/stats/contributors`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: undefined,
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32