Sets repositories for a required workflow
One script reply has been approved by the moderators Verified

Sets the repositories for a required workflow that is required for selected repositories.

You must authenticate using an access token with the admin:org scope to use this endpoint.

For more information, see "Required Workflows."

Created by hugo697 815 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 255 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Sets repositories for a required workflow
6
 * Sets the repositories for a required workflow that is required for selected repositories.
7

8
You must authenticate using an access token with the `admin:org` scope to use this endpoint.
9

10
For more information, see "[Required Workflows](https://docs.github.com/actions/using-workflows/required-workflows)."
11
 */
12
export async function main(
13
  auth: Github,
14
  org: string,
15
  required_workflow_id: string,
16
  body: { selected_repository_ids: number[]; [k: string]: unknown }
17
) {
18
  const url = new URL(
19
    `https://api.github.com/orgs/${org}/actions/required_workflows/${required_workflow_id}/repositories`
20
  );
21

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