Review pending deployments for a workflow run

Approve or reject pending deployments that are waiting on approval by a required reviewer. Required reviewers with read access to the repository contents and deployments can use this endpoint. Required reviewers must authenticate using an access token with the `repo` scope 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
 * Review pending deployments for a workflow run
6
 * Approve or reject pending deployments that are waiting on approval by a required reviewer.
7

8
Required reviewers with read access to the repository contents and deployments can use this endpoint. Required reviewers must authenticate using an access token with the `repo` scope to use this endpoint.
9
 */
10
export async function main(
11
  auth: Github,
12
  owner: string,
13
  repo: string,
14
  run_id: string,
15
  body: {
16
    comment: string;
17
    environment_ids: number[];
18
    state: "approved" | "rejected";
19
    [k: string]: unknown;
20
  }
21
) {
22
  const url = new URL(
23
    `https://api.github.com/repos/${owner}/${repo}/actions/runs/${run_id}/pending_deployments`
24
  );
25

26
  const response = await fetch(url, {
27
    method: "POST",
28
    headers: {
29
      "Content-Type": "application/json",
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40