0
Create commit signature protection
One script reply has been approved by the moderators Verified

Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.

Created by hugo697 319 days ago Viewed 8992 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 319 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Create commit signature protection
6
 * Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  branch: string
13
) {
14
  const url = new URL(
15
    `https://api.github.com/repos/${owner}/${repo}/branches/${branch}/protection/required_signatures`
16
  );
17

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