-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
37 lines (32 loc) · 927 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// @ts-check
/**
* Renames the default branch to main if it is currently set to master
*
* @param {import('@octoherd/cli').Octokit} octokit
* @param {import('@octoherd/cli').Repository} repository
*/
export async function script(octokit, repository) {
if (repository.default_branch !== "master") {
octokit.log.info(
`Default branch is not "master" but "${repository.default_branch}", ignoring`
);
return;
}
if (!repository.permissions.admin) {
octokit.log.warn(`You don't have admin permission, ignoring`);
return;
}
if (repository.archived) {
octokit.log.info(
`Repository is archived, ignoring`
);
return;
}
await octokit.request("POST /repos/{owner}/{repo}/branches/{branch}/rename", {
owner: repository.owner.login,
repo: repository.name,
branch: "master",
new_name: "main",
});
octokit.log.info(`Default branch renamed to "main"`);
}