Get commit authors

Each type of source control system represents authors in a different way.

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 commit authors
6
 * Each type of source control system represents authors in a different way.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  since: string | undefined
13
) {
14
  const url = new URL(
15
    `https://api.github.com/repos/${owner}/${repo}/import/authors`
16
  );
17
  for (const [k, v] of [["since", since]]) {
18
    if (v !== undefined && v !== "") {
19
      url.searchParams.append(k, v);
20
    }
21
  }
22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35