-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
60 lines (48 loc) · 1.51 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// @ts-check
/**
* This script copies labels from one repo to the next
*
* @param {import('@octoherd/cli').Octokit} octokit
* @param {import('@octoherd/cli').Repository} repository
* @param {object} options
* @param {string} options.template this is the repo you want the labels to be copied from
*/
export async function script(octokit, repository, { template }) {
if (!template) {
throw new Error(`--template is required`);
}
octokit.log.debug(
"Load branch protection settings from template repository %s",
template
);
const [templateOwner, templateRepo] = template.split("/");
const [repoOwner, repoName] = repository.full_name.split("/");
const labels = await octokit.request('GET /repos/{owner}/{repo}/labels', {
owner: templateOwner,
repo: templateRepo
})
try {
for (let i = 0; i < labels.data.length; i++) {
const {name, description, color} = labels.data[i];
const exists = await octokit.request('GET /repos/{owner}/{repo}/labels/{name}', {
owner: repoOwner,
repo: repoName,
name,
}).then(() => true, () => false)
octokit.log.info(`${name} label exists: ${exists}`)
if (!exists) {
const label = await octokit.request('POST /repos/{owner}/{repo}/labels', {
owner: repoOwner,
repo: repoName,
name,
description,
color
})
octokit.log.info(`${name} updated`)
}
}
} catch(e) {
octokit.log.error(e)
}
// console.log(response)
}