Update a secret scanning alert

Updates the status of a secret scanning alert in an eligible repository. To use this endpoint, you must be an administrator for the repository or for the organization that owns the repository, and you must use a personal 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 the `secret_scanning_alerts` write 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
 * Update a secret scanning alert
6
 * Updates the status of a secret scanning alert in an eligible repository.
7
To use this endpoint, you must be an administrator for the repository or for the organization that owns the repository, and you must use a personal access token with the `repo` scope or `security_events` scope.
8
For public repositories, you may instead use the `public_repo` scope.
9

10
GitHub Apps must have the `secret_scanning_alerts` write permission to use this endpoint.
11
 */
12
export async function main(
13
  auth: Github,
14
  owner: string,
15
  repo: string,
16
  alert_number: string,
17
  body: {
18
    resolution?:
19
      | null
20
      | "false_positive"
21
      | "wont_fix"
22
      | "revoked"
23
      | "used_in_tests";
24
    resolution_comment?: string;
25
    state: "open" | "resolved";
26
    [k: string]: unknown;
27
  }
28
) {
29
  const url = new URL(
30
    `https://api.github.com/repos/${owner}/${repo}/secret-scanning/alerts/${alert_number}`
31
  );
32

33
  const response = await fetch(url, {
34
    method: "PATCH",
35
    headers: {
36
      "Content-Type": "application/json",
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: JSON.stringify(body),
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47