This repository was archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathImporter.js
More file actions
135 lines (135 loc) · 5.79 KB
/
Importer.js
File metadata and controls
135 lines (135 loc) · 5.79 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Importer = void 0;
const Core = require("@actions/core");
const rest_1 = require("@octokit/rest");
const GitHub = require("@actions/github");
const googleapis_1 = require("googleapis");
class Importer {
async start() {
var _a, _b, _c, _d;
try {
Core.startGroup("🚦 Checking Inputs and Initializing...");
const serviceAccountCredentials = Core.getInput(Importer.INPUT_SERVICE_ACCOUNT_JSON);
const documentId = Core.getInput(Importer.INPUT_DOCUMENT_ID);
const sheetName = Core.getInput(Importer.INPUT_SHEET_NAME);
if (!serviceAccountCredentials || !documentId || !sheetName) {
throw new Error("🚨 Some Inputs missed. Please check project README.");
}
Core.info("Auth with GitHub Token...");
const octokit = new rest_1.Octokit();
Core.info("Done.");
Core.endGroup();
Core.startGroup("📑 Getting all Issues in repository...");
var page = 1;
var issuesData = [];
var issuesPage;
do {
Core.info(`Getting data from Issues page ${page}...`);
issuesPage = await octokit.issues.listForRepo({
owner: GitHub.context.repo.owner,
repo: GitHub.context.repo.repo,
state: "all",
page
});
Core.info(`There are ${issuesPage.data.length} Issues...`);
issuesData = issuesData.concat(issuesPage.data);
if (issuesPage.data.length) {
Core.info("Next page...");
}
page++;
} while (issuesPage.data.length);
Core.info("All pages processed:");
issuesData.forEach(value => {
Core.info(`${Importer.LOG_BULLET_ITEM} ${value.title}`);
});
Core.endGroup();
Core.startGroup("🔓 Authenticating via Google API Service Account...");
const auth = new googleapis_1.google.auth.GoogleAuth({
// Scopes can be specified either as an array or as a single, space-delimited string.
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
credentials: JSON.parse(serviceAccountCredentials)
});
const sheets = googleapis_1.google.sheets({
version: "v4",
auth: auth
});
Core.info("Done.");
Core.endGroup();
Core.startGroup(`🧼 Cleaning old Sheet (${sheetName})...`);
await sheets.spreadsheets.values.clear({
spreadsheetId: documentId,
range: sheetName,
});
Core.info("Done.");
Core.endGroup();
Core.startGroup(`🔨 Form Issues data for Sheets format...`);
var issueSheetsData = [];
for (const value of issuesData) {
var labels = [];
for (const label of value.labels) {
labels.push(label.name);
}
var assignees = [];
for (const assignee of value.assignees) {
assignees.push(assignee.login);
}
issueSheetsData.push([
value.number,
value.state,
value.pull_request ? "Pull Request" : "Issue",
value.title,
value.html_url,
Object.keys(labels).map(k => labels[k]).join(", "),
Object.keys(assignees).map(k => assignees[k]).join(", "),
(_a = value.milestone) === null || _a === void 0 ? void 0 : _a.title,
(_b = value.milestone) === null || _b === void 0 ? void 0 : _b.state,
(_c = value.milestone) === null || _c === void 0 ? void 0 : _c.due_on,
(_d = value.milestone) === null || _d === void 0 ? void 0 : _d.html_url,
]);
}
issueSheetsData.forEach(value => {
Core.info(`${Importer.LOG_BULLET_ITEM} ${JSON.stringify(value)}`);
});
Core.endGroup();
Core.startGroup(`📝 Adding Issues data to Sheet (${sheetName})...`);
Core.info("Adding header...");
await sheets.spreadsheets.values.append({
spreadsheetId: documentId,
range: sheetName + "!A1:1",
valueInputOption: "USER_ENTERED",
requestBody: {
majorDimension: "ROWS",
range: sheetName + "!A1:1",
values: [
["#", "Status", "Type", "Title", "URI", "Labels", "Assignees", "Milestone", "Status", "Deadline", "URI"]
]
}
});
Core.info("Appending data...");
await sheets.spreadsheets.values.append({
spreadsheetId: documentId,
range: sheetName + "!A1:1",
valueInputOption: "USER_ENTERED",
requestBody: {
majorDimension: "ROWS",
range: sheetName + "!A1:1",
values: issueSheetsData
}
});
Core.info("Done.");
Core.endGroup();
Core.info("☑️ Done!");
}
catch (error) {
Core.setFailed(error);
}
}
}
exports.Importer = Importer;
Importer.LOG_SPACING_SIZE = 2;
Importer.LOG_BULLET_ITEM = "·️";
Importer.INPUT_SERVICE_ACCOUNT_JSON = "google-api-service-account-credentials";
Importer.INPUT_DOCUMENT_ID = "document-id";
Importer.INPUT_SHEET_NAME = "sheet-name";
//# sourceMappingURL=Importer.js.map