-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
113 lines (96 loc) · 4.01 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require('dotenv').config();
const Octokit = require("@octokit/rest");
const fs = require('fs');
const initData = JSON.parse(fs.readFileSync('init-data.json'));
const octokit = Octokit({
auth: process.env.GITHUB_PERSONAL_TOKEN
});
var orgRepos = null;
var studentRepos = null;
console.log('Starting repo initialization.');
(async () => {
orgRepos = await octokit.repos.listForOrg({
org: process.env.ORG
});
studentRepos = orgRepos.data
.filter(r => { return r.name.includes(process.env.REPO_PATTERN) })
.map(function(repo) {
return repo.name;
}
);
console.log("These repos are going to be initialized: ", studentRepos);
const start = async () => {
await asyncForEach(studentRepos, async (repoName) => {
console.log("Initializing: ", repoName);
initData.project.response = await octokit.projects.createForRepo({
owner: process.env.ORG,
repo: repoName,
name: initData.project.name,
body: initData.project.body
});
initData.project.columns.toDo.response = await octokit.projects.createColumn({
project_id: initData.project.response.data.id,
name: "To do"
});
initData.project.columns.inProgress.response = await octokit.projects.createColumn({
project_id: initData.project.response.data.id,
name: "In progress"
});
initData.project.columns.done.response = await octokit.projects.createColumn({
project_id: initData.project.response.data.id,
name: "Done"
});
var promisesMilestones = await initData.milestones.map( async (milestone) => {
milestone.response = await octokit.issues.createMilestone({
owner: process.env.ORG,
repo: repoName,
title: milestone.title,
state: 'open',
due_on: milestone.due_on
});
return milestone;
});
initData.milestones = await Promise.all(promisesMilestones);
var promisesLabels = await initData.labels.map( async (label) => {
label.response = await octokit.issues.createLabel({
owner: process.env.ORG,
repo: repoName,
name: label.name,
color: label.color,
description: label.description
});
return label;
});
initData.labels = await Promise.all(promisesLabels);
var promisesIssues = await initData.issues.map( async (issue) => {
var currentMilestone = initData.milestones.filter( milestone => milestone.title == issue.milestone);
issue.response = await octokit.issues.create({
owner: process.env.ORG,
repo: repoName,
title: issue.title,
body: issue.body,
milestone: currentMilestone[0].response.data.number,
labels: issue.labels
});
return issue;
});
initData.issues = await Promise.all(promisesIssues);
var promisesCard = await initData.issues.map( async (issue) => {
issue.card.response = await octokit.projects.createCard({
column_id: initData.project.columns.toDo.response.data.id,
content_id: issue.response.data.id,
content_type: "Issue"
});
return issue;
});
initData.issues = await Promise.all(promisesCard);
});
console.log('Done!');
}
start();
})();
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}