forked from microsoft/vscode-cpptools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAction.js
More file actions
129 lines (127 loc) · 5.75 KB
/
Action.js
File metadata and controls
129 lines (127 loc) · 5.75 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
"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Action = void 0;
const octokit_1 = require("../api/octokit");
const github_1 = require("@actions/github");
const utils_1 = require("./utils");
const core_1 = require("@actions/core");
class Action {
constructor() {
this.token = utils_1.getRequiredInput('token');
this.username = new github_1.GitHub(this.token).users.getAuthenticated().then((v) => v.data.name);
}
async run() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
console.log('running ', this.id, 'with context', {
...github_1.context,
payload: {
issue: (_b = (_a = github_1.context.payload) === null || _a === void 0 ? void 0 : _a.issue) === null || _b === void 0 ? void 0 : _b.number,
label: (_d = (_c = github_1.context.payload) === null || _c === void 0 ? void 0 : _c.label) === null || _d === void 0 ? void 0 : _d.name,
repository: (_f = (_e = github_1.context.payload) === null || _e === void 0 ? void 0 : _e.repository) === null || _f === void 0 ? void 0 : _f.html_url,
sender: (_j = (_h = (_g = github_1.context.payload) === null || _g === void 0 ? void 0 : _g.sender) === null || _h === void 0 ? void 0 : _h.login) !== null && _j !== void 0 ? _j : (_l = (_k = github_1.context.payload) === null || _k === void 0 ? void 0 : _k.sender) === null || _l === void 0 ? void 0 : _l.type,
},
});
if (utils_1.errorLoggingIssue) {
const { repo, issue, owner } = utils_1.errorLoggingIssue;
if (github_1.context.repo.repo === repo &&
github_1.context.repo.owner === owner &&
((_m = github_1.context.payload.issue) === null || _m === void 0 ? void 0 : _m.number) === issue) {
return console.log('refusing to run on error logging issue to prevent cascading errors');
}
}
try {
const token = utils_1.getRequiredInput('token');
const readonly = !!core_1.getInput('readonly');
const issue = (_o = github_1.context === null || github_1.context === void 0 ? void 0 : github_1.context.issue) === null || _o === void 0 ? void 0 : _o.number;
if (issue) {
const octokit = new octokit_1.OctoKitIssue(token, github_1.context.repo, { number: issue }, { readonly });
if (github_1.context.eventName === 'issue_comment') {
await this.onCommented(octokit, github_1.context.payload.comment.body, github_1.context.actor);
}
else if (github_1.context.eventName === 'issues') {
switch (github_1.context.payload.action) {
case 'opened':
await this.onOpened(octokit);
break;
case 'reopened':
await this.onReopened(octokit);
break;
case 'closed':
await this.onClosed(octokit);
break;
case 'labeled':
await this.onLabeled(octokit, github_1.context.payload.label.name);
break;
case 'unassigned':
await this.onUnassigned(octokit, github_1.context.payload.assignee.login);
break;
case 'edited':
await this.onEdited(octokit);
break;
case 'milestoned':
await this.onMilestoned(octokit);
break;
default:
throw Error('Unexpected action: ' + github_1.context.payload.action);
}
}
}
else {
await this.onTriggered(new octokit_1.OctoKit(token, github_1.context.repo, { readonly }));
}
}
catch (e) {
await this.error(e);
}
const usage = await utils_1.getRateLimit(this.token);
}
async error(error) {
const details = {
message: `${error.message}\n${error.stack}`,
id: this.id,
user: await this.username,
};
if (github_1.context.issue.number)
details.issue = github_1.context.issue.number;
const rendered = `
Message: ${details.message}
Actor: ${details.user}
ID: ${details.id}
`;
await utils_1.logErrorToIssue(rendered, true, this.token);
core_1.setFailed(error.message);
}
async onTriggered(_octokit) {
throw Error('not implemented');
}
async onEdited(_issue) {
throw Error('not implemented');
}
async onLabeled(_issue, _label) {
throw Error('not implemented');
}
async onUnassigned(_issue, _label) {
throw Error('not implemented');
}
async onOpened(_issue) {
throw Error('not implemented');
}
async onReopened(_issue) {
throw Error('not implemented');
}
async onClosed(_issue) {
throw Error('not implemented');
}
async onMilestoned(_issue) {
throw Error('not implemented');
}
async onCommented(_issue, _comment, _actor) {
throw Error('not implemented');
}
}
exports.Action = Action;
//# sourceMappingURL=Action.js.map