0
List commits
One script reply has been approved by the moderators Verified

Signature verification object

The response will include a verification object that describes the result of verifying the commit's signature.

Created by hugo697 200 days ago Viewed 6181 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 200 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List commits
6
 * **Signature verification object**
7

8
The response will include a `verification` object that describes the result of verifying the commit's signature.
9
 */
10
export async function main(
11
  auth: Github,
12
  owner: string,
13
  repo: string,
14
  sha: string | undefined,
15
  path: string | undefined,
16
  author: string | undefined,
17
  since: string | undefined,
18
  until: string | undefined,
19
  per_page: string | undefined,
20
  page: string | undefined
21
) {
22
  const url = new URL(`https://api.github.com/repos/${owner}/${repo}/commits`);
23
  for (const [k, v] of [
24
    ["sha", sha],
25
    ["path", path],
26
    ["author", author],
27
    ["since", since],
28
    ["until", until],
29
    ["per_page", per_page],
30
    ["page", page],
31
  ]) {
32
    if (v !== undefined && v !== "") {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49