List Dependabot alerts for an organization

Lists Dependabot alerts for an organization. To use this endpoint, you must be an owner or security manager for the organization, and you must use an access token with the `repo` scope or `security_events` scope. For public repositories, you may instead use the `public_repo` scope. GitHub Apps must have **Dependabot alerts** read permission to use this endpoint.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List Dependabot alerts for an organization
6
 * Lists Dependabot alerts for an organization.
7

8
To use this endpoint, you must be an owner or security manager for the organization, and you must use an access token with the `repo` scope or `security_events` scope.
9

10
For public repositories, you may instead use the `public_repo` scope.
11

12
GitHub Apps must have **Dependabot alerts** read permission to use this endpoint.
13
 */
14
export async function main(
15
  auth: Github,
16
  org: string,
17
  state: string | undefined,
18
  severity: string | undefined,
19
  ecosystem: string | undefined,
20
  package: string | undefined,
21
  scope: "development" | "runtime" | undefined,
22
  sort: "created" | "updated" | undefined,
23
  direction: "asc" | "desc" | undefined,
24
  before: string | undefined,
25
  after: string | undefined,
26
  first: string | undefined,
27
  last: string | undefined,
28
  per_page: string | undefined
29
) {
30
  const url = new URL(`https://api.github.com/orgs/${org}/dependabot/alerts`);
31
  for (const [k, v] of [
32
    ["state", state],
33
    ["severity", severity],
34
    ["ecosystem", ecosystem],
35
    ["package", package],
36
    ["scope", scope],
37
    ["sort", sort],
38
    ["direction", direction],
39
    ["before", before],
40
    ["after", after],
41
    ["first", first],
42
    ["last", last],
43
    ["per_page", per_page],
44
  ]) {
45
    if (v !== undefined && v !== "") {
46
      url.searchParams.append(k, v);
47
    }
48
  }
49
  const response = await fetch(url, {
50
    method: "GET",
51
    headers: {
52
      Authorization: "Bearer " + auth.token,
53
    },
54
    body: undefined,
55
  });
56
  if (!response.ok) {
57
    const text = await response.text();
58
    throw new Error(`${response.status} ${text}`);
59
  }
60
  return await response.json();
61
}
62