Update a repository

**Note**: To edit a repository's topics, use the [Replace all repository topics](https://docs.github.com/rest/reference/repos#replace-all-repository-topics) 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 repository
6
 * **Note**: To edit a repository's topics, use the [Replace all repository topics](https://docs.github.com/rest/reference/repos#replace-all-repository-topics) endpoint.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  body: {
13
    allow_auto_merge?: boolean;
14
    allow_forking?: boolean;
15
    allow_merge_commit?: boolean;
16
    allow_rebase_merge?: boolean;
17
    allow_squash_merge?: boolean;
18
    allow_update_branch?: boolean;
19
    archived?: boolean;
20
    default_branch?: string;
21
    delete_branch_on_merge?: boolean;
22
    description?: string;
23
    has_issues?: boolean;
24
    has_projects?: boolean;
25
    has_wiki?: boolean;
26
    homepage?: string;
27
    is_template?: boolean;
28
    merge_commit_message?: "PR_BODY" | "PR_TITLE" | "BLANK";
29
    merge_commit_title?: "PR_TITLE" | "MERGE_MESSAGE";
30
    name?: string;
31
    private?: boolean;
32
    security_and_analysis?: {
33
      advanced_security?: { status?: string; [k: string]: unknown };
34
      secret_scanning?: { status?: string; [k: string]: unknown };
35
      secret_scanning_push_protection?: {
36
        status?: string;
37
        [k: string]: unknown;
38
      };
39
      [k: string]: unknown;
40
    };
41
    squash_merge_commit_message?: "PR_BODY" | "COMMIT_MESSAGES" | "BLANK";
42
    squash_merge_commit_title?: "PR_TITLE" | "COMMIT_OR_PR_TITLE";
43
    use_squash_pr_title_as_default?: boolean;
44
    visibility?: "public" | "private";
45
    web_commit_signoff_required?: boolean;
46
    [k: string]: unknown;
47
  }
48
) {
49
  const url = new URL(`https://api.github.com/repos/${owner}/${repo}`);
50

51
  const response = await fetch(url, {
52
    method: "PATCH",
53
    headers: {
54
      "Content-Type": "application/json",
55
      Authorization: "Bearer " + auth.token,
56
    },
57
    body: JSON.stringify(body),
58
  });
59
  if (!response.ok) {
60
    const text = await response.text();
61
    throw new Error(`${response.status} ${text}`);
62
  }
63
  return await response.json();
64
}
65