Get default workflow permissions for an organization

Gets the default workflow permissions granted to the `GITHUB_TOKEN` when running workflows in an organization, as well as whether GitHub Actions can submit approving pull request reviews.

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
 * Get default workflow permissions for an organization
6
 * Gets the default workflow permissions granted to the `GITHUB_TOKEN` when running workflows in an organization,
7
as well as whether GitHub Actions can submit approving pull request reviews.
8
 */
9
export async function main(auth: Github, org: string) {
10
  const url = new URL(
11
    `https://api.github.com/orgs/${org}/actions/permissions/workflow`
12
  );
13

14
  const response = await fetch(url, {
15
    method: "GET",
16
    headers: {
17
      Authorization: "Bearer " + auth.token,
18
    },
19
    body: undefined,
20
  });
21
  if (!response.ok) {
22
    const text = await response.text();
23
    throw new Error(`${response.status} ${text}`);
24
  }
25
  return await response.json();
26
}
27