1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | var __assign = (this && this.__assign) || function () {
|
16 | __assign = Object.assign || function(t) {
|
17 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
18 | s = arguments[i];
|
19 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
20 | t[p] = s[p];
|
21 | }
|
22 | return t;
|
23 | };
|
24 | return __assign.apply(this, arguments);
|
25 | };
|
26 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
27 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
28 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
29 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
30 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
31 | };
|
32 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
33 | return new (P || (P = Promise))(function (resolve, reject) {
|
34 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
35 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
36 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
37 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
38 | });
|
39 | };
|
40 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
41 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
42 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
43 | function verb(n) { return function (v) { return step([n, v]); }; }
|
44 | function step(op) {
|
45 | if (f) throw new TypeError("Generator is already executing.");
|
46 | while (_) try {
|
47 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
48 | if (y = 0, t) op = [op[0] & 2, t.value];
|
49 | switch (op[0]) {
|
50 | case 0: case 1: t = op; break;
|
51 | case 4: _.label++; return { value: op[1], done: false };
|
52 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
53 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
54 | default:
|
55 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
56 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
57 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
58 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
59 | if (t[2]) _.ops.pop();
|
60 | _.trys.pop(); continue;
|
61 | }
|
62 | op = body.call(thisArg, _);
|
63 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
64 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
65 | }
|
66 | };
|
67 | var __read = (this && this.__read) || function (o, n) {
|
68 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
69 | if (!m) return o;
|
70 | var i = m.call(o), r, ar = [], e;
|
71 | try {
|
72 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
73 | }
|
74 | catch (error) { e = { error: error }; }
|
75 | finally {
|
76 | try {
|
77 | if (r && !r.done && (m = i["return"])) m.call(i);
|
78 | }
|
79 | finally { if (e) throw e.error; }
|
80 | }
|
81 | return ar;
|
82 | };
|
83 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
84 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
85 | };
|
86 | Object.defineProperty(exports, "__esModule", { value: true });
|
87 | var graphql_1 = __importDefault(require("@octokit/graphql"));
|
88 | var plugin_enterprise_compatibility_1 = __importDefault(require("@octokit/plugin-enterprise-compatibility"));
|
89 | var plugin_retry_1 = __importDefault(require("@octokit/plugin-retry"));
|
90 | var plugin_throttling_1 = __importDefault(require("@octokit/plugin-throttling"));
|
91 | var rest_1 = __importDefault(require("@octokit/rest"));
|
92 | var gitlog_1 = __importDefault(require("gitlog"));
|
93 | var tinycolor2_1 = __importDefault(require("tinycolor2"));
|
94 | var util_1 = require("util");
|
95 | var typescript_memoize_1 = require("typescript-memoize");
|
96 | var exec_promise_1 = __importDefault(require("./utils/exec-promise"));
|
97 | var logger_1 = require("./utils/logger");
|
98 | var gitlog = util_1.promisify(gitlog_1.default);
|
99 | var GitAPIError = (function (_super) {
|
100 | __extends(GitAPIError, _super);
|
101 | function GitAPIError(api, args, origError) {
|
102 | return _super.call(this, "Error calling github: " + api + "\n\twith: " + JSON.stringify(args) + ".\n\t" + origError.message) || this;
|
103 | }
|
104 | return GitAPIError;
|
105 | }(Error));
|
106 | var makeIdentifier = function (type, context) {
|
107 | return "<!-- GITHUB_RELEASE " + type + ": " + context + " -->";
|
108 | };
|
109 | var makeCommentIdentifier = function (context) {
|
110 | return makeIdentifier('COMMENT', context);
|
111 | };
|
112 | var makePrBodyIdentifier = function (context) {
|
113 | return makeIdentifier('PR BODY', context);
|
114 | };
|
115 |
|
116 |
|
117 | var Git = (function () {
|
118 | function Git(options, logger) {
|
119 | if (logger === void 0) { logger = logger_1.dummyLog(); }
|
120 | var _this = this;
|
121 | this.logger = logger;
|
122 | this.options = options;
|
123 | this.baseUrl = this.options.baseUrl || 'https://api.github.com';
|
124 | this.graphqlBaseUrl = this.options.graphqlBaseUrl || this.baseUrl;
|
125 | this.logger.veryVerbose.info("Initializing GitHub with: " + this.baseUrl);
|
126 | var gitHub = rest_1.default.plugin(plugin_enterprise_compatibility_1.default)
|
127 | .plugin(plugin_retry_1.default)
|
128 | .plugin(plugin_throttling_1.default);
|
129 | this.github = new gitHub({
|
130 | baseUrl: this.baseUrl,
|
131 | auth: this.options.token,
|
132 | previews: ['symmetra-preview'],
|
133 | throttle: {
|
134 | onRateLimit: function (retryAfter, opts) {
|
135 | _this.logger.log.warn("Request quota exhausted for request " + opts.method + " " + opts.url);
|
136 | if (opts.request.retryCount < 5) {
|
137 | _this.logger.verbose.log("Retrying after " + retryAfter + " seconds!");
|
138 | return true;
|
139 | }
|
140 | },
|
141 | onAbuseLimit: function (retryAfter, opts) {
|
142 |
|
143 | _this.logger.log.error("Went over abuse rate limit " + opts.method + " " + opts.url);
|
144 | }
|
145 | }
|
146 | });
|
147 | this.github.hook.error('request', function (error) {
|
148 | if (error && error.headers && error.headers.authorization) {
|
149 | delete error.headers.authorization;
|
150 | }
|
151 | throw error;
|
152 | });
|
153 | }
|
154 | Git.prototype.getLatestReleaseInfo = function () {
|
155 | return __awaiter(this, void 0, void 0, function () {
|
156 | var latestRelease;
|
157 | return __generator(this, function (_a) {
|
158 | switch (_a.label) {
|
159 | case 0: return [4 , this.github.repos.getLatestRelease({
|
160 | owner: this.options.owner,
|
161 | repo: this.options.repo
|
162 | })];
|
163 | case 1:
|
164 | latestRelease = _a.sent();
|
165 | return [2 , latestRelease.data];
|
166 | }
|
167 | });
|
168 | });
|
169 | };
|
170 | Git.prototype.getLatestRelease = function () {
|
171 | return __awaiter(this, void 0, void 0, function () {
|
172 | var latestRelease, e_1;
|
173 | return __generator(this, function (_a) {
|
174 | switch (_a.label) {
|
175 | case 0:
|
176 | _a.trys.push([0, 2, , 3]);
|
177 | return [4 , this.getLatestReleaseInfo()];
|
178 | case 1:
|
179 | latestRelease = _a.sent();
|
180 | this.logger.veryVerbose.info('Got response for "getLatestRelease":\n', latestRelease);
|
181 | this.logger.verbose.info('Got latest release:\n', latestRelease);
|
182 | return [2 , latestRelease.tag_name];
|
183 | case 2:
|
184 | e_1 = _a.sent();
|
185 | if (e_1.status === 404) {
|
186 | this.logger.verbose.info("Couldn't find latest release on GitHub, using first commit.");
|
187 | return [2 , this.getFirstCommit()];
|
188 | }
|
189 | throw e_1;
|
190 | case 3: return [2 ];
|
191 | }
|
192 | });
|
193 | });
|
194 | };
|
195 | Git.prototype.getCommitDate = function (sha) {
|
196 | return __awaiter(this, void 0, void 0, function () {
|
197 | var date, _a, day, time, timezone;
|
198 | return __generator(this, function (_b) {
|
199 | switch (_b.label) {
|
200 | case 0: return [4 , exec_promise_1.default('git', ['show', '-s', '--format=%ci', sha])];
|
201 | case 1:
|
202 | date = _b.sent();
|
203 | _a = __read(date.split(' '), 3), day = _a[0], time = _a[1], timezone = _a[2];
|
204 | return [2 , day + "T" + time + timezone];
|
205 | }
|
206 | });
|
207 | });
|
208 | };
|
209 | Git.prototype.getFirstCommit = function () {
|
210 | return __awaiter(this, void 0, void 0, function () {
|
211 | var list;
|
212 | return __generator(this, function (_a) {
|
213 | switch (_a.label) {
|
214 | case 0: return [4 , exec_promise_1.default('git', ['rev-list', 'HEAD'])];
|
215 | case 1:
|
216 | list = _a.sent();
|
217 | return [2 , list.split('\n').pop()];
|
218 | }
|
219 | });
|
220 | });
|
221 | };
|
222 | |
223 |
|
224 |
|
225 | Git.prototype.getSha = function (short) {
|
226 | return __awaiter(this, void 0, void 0, function () {
|
227 | var result;
|
228 | return __generator(this, function (_a) {
|
229 | switch (_a.label) {
|
230 | case 0: return [4 , exec_promise_1.default('git', [
|
231 | 'rev-parse',
|
232 | short && '--short',
|
233 | 'HEAD'
|
234 | ])];
|
235 | case 1:
|
236 | result = _a.sent();
|
237 | this.logger.verbose.info("Got commit SHA from HEAD: " + result);
|
238 | return [2 , result];
|
239 | }
|
240 | });
|
241 | });
|
242 | };
|
243 | Git.prototype.getLabels = function (prNumber) {
|
244 | return __awaiter(this, void 0, void 0, function () {
|
245 | var args, labels, e_2;
|
246 | return __generator(this, function (_a) {
|
247 | switch (_a.label) {
|
248 | case 0:
|
249 | this.logger.verbose.info("Getting labels for PR: " + prNumber);
|
250 | args = {
|
251 | owner: this.options.owner,
|
252 | repo: this.options.repo,
|
253 | issue_number: prNumber
|
254 | };
|
255 | this.logger.verbose.info('Getting issue labels using:', args);
|
256 | _a.label = 1;
|
257 | case 1:
|
258 | _a.trys.push([1, 3, , 4]);
|
259 | return [4 , this.github.issues.listLabelsOnIssue(args)];
|
260 | case 2:
|
261 | labels = _a.sent();
|
262 | this.logger.veryVerbose.info('Got response for "listLabelsOnIssue":\n', labels);
|
263 | this.logger.verbose.info('Found labels on PR:\n', labels.data);
|
264 | return [2 , labels.data.map(function (l) { return l.name; })];
|
265 | case 3:
|
266 | e_2 = _a.sent();
|
267 | throw new GitAPIError('listLabelsOnIssue', args, e_2);
|
268 | case 4: return [2 ];
|
269 | }
|
270 | });
|
271 | });
|
272 | };
|
273 | Git.prototype.getPr = function (prNumber) {
|
274 | return __awaiter(this, void 0, void 0, function () {
|
275 | var args, info, e_3;
|
276 | return __generator(this, function (_a) {
|
277 | switch (_a.label) {
|
278 | case 0:
|
279 | this.logger.verbose.info("Getting info for PR: " + prNumber);
|
280 | args = {
|
281 | owner: this.options.owner,
|
282 | repo: this.options.repo,
|
283 | issue_number: prNumber
|
284 | };
|
285 | this.logger.verbose.info('Getting issue info using:', args);
|
286 | _a.label = 1;
|
287 | case 1:
|
288 | _a.trys.push([1, 3, , 4]);
|
289 | return [4 , this.github.issues.get(args)];
|
290 | case 2:
|
291 | info = _a.sent();
|
292 | this.logger.veryVerbose.info('Got response for "issues.get":\n', info);
|
293 | return [2 , info];
|
294 | case 3:
|
295 | e_3 = _a.sent();
|
296 | throw new GitAPIError('getPr', args, e_3);
|
297 | case 4: return [2 ];
|
298 | }
|
299 | });
|
300 | });
|
301 | };
|
302 | Git.prototype.getProjectLabels = function () {
|
303 | return __awaiter(this, void 0, void 0, function () {
|
304 | var args, labels, e_4;
|
305 | return __generator(this, function (_a) {
|
306 | switch (_a.label) {
|
307 | case 0:
|
308 | this.logger.verbose.info("Getting labels for project: " + this.options.repo);
|
309 | args = {
|
310 | owner: this.options.owner,
|
311 | repo: this.options.repo
|
312 | };
|
313 | _a.label = 1;
|
314 | case 1:
|
315 | _a.trys.push([1, 3, , 4]);
|
316 | return [4 , this.github.issues.listLabelsForRepo(args)];
|
317 | case 2:
|
318 | labels = _a.sent();
|
319 | this.logger.veryVerbose.info('Got response for "getProjectLabels":\n', labels);
|
320 | this.logger.verbose.info('Found labels on project:\n', labels.data);
|
321 | return [2 , labels.data.map(function (l) { return l.name; })];
|
322 | case 3:
|
323 | e_4 = _a.sent();
|
324 | throw new GitAPIError('getProjectLabels', args, e_4);
|
325 | case 4: return [2 ];
|
326 | }
|
327 | });
|
328 | });
|
329 | };
|
330 | Git.prototype.getGitLog = function (start, end) {
|
331 | if (end === void 0) { end = 'HEAD'; }
|
332 | return __awaiter(this, void 0, void 0, function () {
|
333 | var log;
|
334 | return __generator(this, function (_a) {
|
335 | switch (_a.label) {
|
336 | case 0: return [4 , gitlog({
|
337 | repo: process.cwd(),
|
338 | number: Number.MAX_SAFE_INTEGER,
|
339 | fields: ['hash', 'authorName', 'authorEmail', 'rawBody'],
|
340 | branch: start.trim() + ".." + end.trim(),
|
341 | execOptions: { maxBuffer: 1000 * 1024 }
|
342 | })];
|
343 | case 1:
|
344 | log = _a.sent();
|
345 | return [2 , log.map(function (commit) { return ({
|
346 | hash: commit.hash,
|
347 | authorName: commit.authorName,
|
348 | authorEmail: commit.authorEmail,
|
349 | subject: commit.rawBody
|
350 | }); })];
|
351 | }
|
352 | });
|
353 | });
|
354 | };
|
355 | Git.prototype.getUserByEmail = function (email) {
|
356 | return __awaiter(this, void 0, void 0, function () {
|
357 | var search, error_1;
|
358 | return __generator(this, function (_a) {
|
359 | switch (_a.label) {
|
360 | case 0:
|
361 | _a.trys.push([0, 2, , 3]);
|
362 | return [4 , this.github.search.users({
|
363 | q: "in:email " + email
|
364 | })];
|
365 | case 1:
|
366 | search = (_a.sent()).data;
|
367 | return [2 , search && search.items.length > 0 ? search.items[0] : {}];
|
368 | case 2:
|
369 | error_1 = _a.sent();
|
370 | this.logger.verbose.warn("Could not find user by email: " + email);
|
371 | return [3 , 3];
|
372 | case 3: return [2 ];
|
373 | }
|
374 | });
|
375 | });
|
376 | };
|
377 | Git.prototype.getUserByUsername = function (username) {
|
378 | return __awaiter(this, void 0, void 0, function () {
|
379 | var user, error_2;
|
380 | return __generator(this, function (_a) {
|
381 | switch (_a.label) {
|
382 | case 0:
|
383 | _a.trys.push([0, 2, , 3]);
|
384 | return [4 , this.github.users.getByUsername({
|
385 | username: username
|
386 | })];
|
387 | case 1:
|
388 | user = _a.sent();
|
389 | return [2 , user.data];
|
390 | case 2:
|
391 | error_2 = _a.sent();
|
392 | this.logger.verbose.warn("Could not find user by username: " + username);
|
393 | return [3 , 3];
|
394 | case 3: return [2 ];
|
395 | }
|
396 | });
|
397 | });
|
398 | };
|
399 | Git.prototype.getPullRequest = function (pr) {
|
400 | return __awaiter(this, void 0, void 0, function () {
|
401 | var args, result;
|
402 | return __generator(this, function (_a) {
|
403 | switch (_a.label) {
|
404 | case 0:
|
405 | this.logger.verbose.info("Getting Pull Request: " + pr);
|
406 | args = {
|
407 | owner: this.options.owner,
|
408 | repo: this.options.repo,
|
409 | pull_number: pr
|
410 | };
|
411 | this.logger.verbose.info('Getting pull request info using:', args);
|
412 | return [4 , this.github.pulls.get(args)];
|
413 | case 1:
|
414 | result = _a.sent();
|
415 | this.logger.veryVerbose.info('Got pull request data\n', result);
|
416 | this.logger.verbose.info('Got pull request info');
|
417 | return [2 , result];
|
418 | }
|
419 | });
|
420 | });
|
421 | };
|
422 | Git.prototype.searchRepo = function (options) {
|
423 | return __awaiter(this, void 0, void 0, function () {
|
424 | var repo, result;
|
425 | return __generator(this, function (_a) {
|
426 | switch (_a.label) {
|
427 | case 0:
|
428 | repo = "repo:" + this.options.owner + "/" + this.options.repo;
|
429 | options.q = repo + " " + options.q;
|
430 | this.logger.verbose.info('Searching repo using:\n', options);
|
431 | return [4 , this.github.search.issuesAndPullRequests(options)];
|
432 | case 1:
|
433 | result = _a.sent();
|
434 | this.logger.veryVerbose.info('Got response from search\n', result);
|
435 | this.logger.verbose.info('Searched repo on GitHub.');
|
436 | return [2 , result.data];
|
437 | }
|
438 | });
|
439 | });
|
440 | };
|
441 | Git.prototype.graphql = function (query) {
|
442 | return __awaiter(this, void 0, void 0, function () {
|
443 | var data;
|
444 | return __generator(this, function (_a) {
|
445 | switch (_a.label) {
|
446 | case 0:
|
447 | this.logger.verbose.info('Querying Github using GraphQL:\n', query);
|
448 | return [4 , graphql_1.default(query, {
|
449 | baseUrl: this.graphqlBaseUrl,
|
450 | headers: {
|
451 | authorization: "token " + this.options.token
|
452 | }
|
453 | })];
|
454 | case 1:
|
455 | data = _a.sent();
|
456 | this.logger.veryVerbose.info('Got response from query\n', data);
|
457 | return [2 , data];
|
458 | }
|
459 | });
|
460 | });
|
461 | };
|
462 | Git.prototype.createStatus = function (prInfo) {
|
463 | return __awaiter(this, void 0, void 0, function () {
|
464 | var args, result;
|
465 | return __generator(this, function (_a) {
|
466 | switch (_a.label) {
|
467 | case 0:
|
468 | args = __assign({}, prInfo, { owner: this.options.owner, repo: this.options.repo });
|
469 | this.logger.verbose.info('Creating status using:\n', args);
|
470 | return [4 , this.github.repos.createStatus(args)];
|
471 | case 1:
|
472 | result = _a.sent();
|
473 | this.logger.veryVerbose.info('Got response from createStatues\n', result);
|
474 | this.logger.verbose.info('Created status on GitHub.');
|
475 | return [2 , result];
|
476 | }
|
477 | });
|
478 | });
|
479 | };
|
480 | Git.prototype.createLabel = function (name, label) {
|
481 | return __awaiter(this, void 0, void 0, function () {
|
482 | var color, result;
|
483 | return __generator(this, function (_a) {
|
484 | switch (_a.label) {
|
485 | case 0:
|
486 | this.logger.verbose.info("Creating \"" + name + "\" label :\n" + label.name);
|
487 | color = label.color
|
488 | ? tinycolor2_1.default(label.color).toString('hex6')
|
489 | : tinycolor2_1.default.random().toString('hex6');
|
490 | return [4 , this.github.issues.createLabel({
|
491 | name: label.name,
|
492 | owner: this.options.owner,
|
493 | repo: this.options.repo,
|
494 | color: color.replace('#', ''),
|
495 | description: label.description
|
496 | })];
|
497 | case 1:
|
498 | result = _a.sent();
|
499 | this.logger.veryVerbose.info('Got response from createLabel\n', result);
|
500 | this.logger.verbose.info('Created label on GitHub.');
|
501 | return [2 , result];
|
502 | }
|
503 | });
|
504 | });
|
505 | };
|
506 | Git.prototype.updateLabel = function (name, label) {
|
507 | return __awaiter(this, void 0, void 0, function () {
|
508 | var color, result;
|
509 | return __generator(this, function (_a) {
|
510 | switch (_a.label) {
|
511 | case 0:
|
512 | this.logger.verbose.info("Updating \"" + name + "\" label :\n" + label.name);
|
513 | color = label.color
|
514 | ? tinycolor2_1.default(label.color).toString('hex6')
|
515 | : tinycolor2_1.default.random().toString('hex6');
|
516 | return [4 , this.github.issues.updateLabel({
|
517 | current_name: label.name,
|
518 | owner: this.options.owner,
|
519 | repo: this.options.repo,
|
520 | color: color.replace('#', ''),
|
521 | description: label.description
|
522 | })];
|
523 | case 1:
|
524 | result = _a.sent();
|
525 | this.logger.veryVerbose.info('Got response from updateLabel\n', result);
|
526 | this.logger.verbose.info('Updated label on GitHub.');
|
527 | return [2 , result];
|
528 | }
|
529 | });
|
530 | });
|
531 | };
|
532 | Git.prototype.addLabelToPr = function (pr, label) {
|
533 | return __awaiter(this, void 0, void 0, function () {
|
534 | var result;
|
535 | return __generator(this, function (_a) {
|
536 | switch (_a.label) {
|
537 | case 0:
|
538 | this.logger.verbose.info("Creating \"" + label + "\" label to PR " + pr);
|
539 | return [4 , this.github.issues.addLabels({
|
540 | issue_number: pr,
|
541 | owner: this.options.owner,
|
542 | repo: this.options.repo,
|
543 | labels: [label]
|
544 | })];
|
545 | case 1:
|
546 | result = _a.sent();
|
547 | this.logger.veryVerbose.info('Got response from addLabels\n', result);
|
548 | this.logger.verbose.info('Added labels on Pull Request.');
|
549 | return [2 , result];
|
550 | }
|
551 | });
|
552 | });
|
553 | };
|
554 | Git.prototype.lockIssue = function (issue) {
|
555 | return __awaiter(this, void 0, void 0, function () {
|
556 | var result;
|
557 | return __generator(this, function (_a) {
|
558 | switch (_a.label) {
|
559 | case 0:
|
560 | this.logger.verbose.info("Locking #" + issue + " issue...");
|
561 | return [4 , this.github.issues.lock({
|
562 | issue_number: issue,
|
563 | owner: this.options.owner,
|
564 | repo: this.options.repo
|
565 | })];
|
566 | case 1:
|
567 | result = _a.sent();
|
568 | this.logger.veryVerbose.info('Got response from lock\n', result);
|
569 | this.logger.verbose.info('Locked issue.');
|
570 | return [2 , result];
|
571 | }
|
572 | });
|
573 | });
|
574 | };
|
575 | Git.prototype.getProject = function () {
|
576 | return __awaiter(this, void 0, void 0, function () {
|
577 | var result;
|
578 | return __generator(this, function (_a) {
|
579 | switch (_a.label) {
|
580 | case 0:
|
581 | this.logger.verbose.info('Getting project from GitHub');
|
582 | return [4 , this.github.repos.get({
|
583 | owner: this.options.owner,
|
584 | repo: this.options.repo
|
585 | })];
|
586 | case 1:
|
587 | result = (_a.sent()).data;
|
588 | this.logger.veryVerbose.info('Got response from repos\n', result);
|
589 | this.logger.verbose.info('Got project information.');
|
590 | return [2 , result];
|
591 | }
|
592 | });
|
593 | });
|
594 | };
|
595 | Git.prototype.getPullRequests = function (options) {
|
596 | return __awaiter(this, void 0, void 0, function () {
|
597 | var result;
|
598 | return __generator(this, function (_a) {
|
599 | switch (_a.label) {
|
600 | case 0:
|
601 | this.logger.verbose.info('Getting pull requests...');
|
602 | return [4 , this.github.pulls.list(__assign({ owner: this.options.owner.toLowerCase(), repo: this.options.repo.toLowerCase() }, options))];
|
603 | case 1:
|
604 | result = (_a.sent()).data;
|
605 | this.logger.veryVerbose.info('Got response from pull requests', result);
|
606 | this.logger.verbose.info('Got pull request');
|
607 | return [2 , result];
|
608 | }
|
609 | });
|
610 | });
|
611 | };
|
612 | Git.prototype.getCommitsForPR = function (pr) {
|
613 | return __awaiter(this, void 0, void 0, function () {
|
614 | var result;
|
615 | return __generator(this, function (_a) {
|
616 | switch (_a.label) {
|
617 | case 0:
|
618 | this.logger.verbose.info("Getting commits for PR #" + pr);
|
619 | return [4 , this.github.paginate(this.github.pulls.listCommits.endpoint({
|
620 | owner: this.options.owner.toLowerCase(),
|
621 | repo: this.options.repo.toLowerCase(),
|
622 | pull_number: pr
|
623 | }))];
|
624 | case 1:
|
625 | result = _a.sent();
|
626 | this.logger.veryVerbose.info("Got response from PR #" + pr + "\n", result);
|
627 | this.logger.verbose.info("Got commits for PR #" + pr + ".");
|
628 | return [2 , result];
|
629 | }
|
630 | });
|
631 | });
|
632 | };
|
633 | Git.prototype.deleteComment = function (pr, context) {
|
634 | if (context === void 0) { context = 'default'; }
|
635 | return __awaiter(this, void 0, void 0, function () {
|
636 | var commentIdentifier, comments, oldMessage, commentId;
|
637 | return __generator(this, function (_a) {
|
638 | switch (_a.label) {
|
639 | case 0:
|
640 | commentIdentifier = makeCommentIdentifier(context);
|
641 | this.logger.verbose.info('Getting previous comments on:', pr);
|
642 | return [4 , this.github.issues.listComments({
|
643 | owner: this.options.owner,
|
644 | repo: this.options.repo,
|
645 | issue_number: pr
|
646 | })];
|
647 | case 1:
|
648 | comments = _a.sent();
|
649 | this.logger.veryVerbose.info('Got PR comments\n', comments);
|
650 | oldMessage = comments.data.find(function (comment) {
|
651 | return comment.body.includes(commentIdentifier);
|
652 | });
|
653 | if (!oldMessage) {
|
654 | return [2 ];
|
655 | }
|
656 | this.logger.verbose.info('Found previous message from same scope.');
|
657 | commentId = oldMessage.id;
|
658 | this.logger.verbose.info("Deleting comment: " + commentId);
|
659 | return [4 , this.github.issues.deleteComment({
|
660 | owner: this.options.owner,
|
661 | repo: this.options.repo,
|
662 | comment_id: commentId
|
663 | })];
|
664 | case 2:
|
665 | _a.sent();
|
666 | this.logger.verbose.info("Successfully deleted comment: " + commentId);
|
667 | return [2 ];
|
668 | }
|
669 | });
|
670 | });
|
671 | };
|
672 | Git.prototype.createComment = function (message, pr, context) {
|
673 | if (context === void 0) { context = 'default'; }
|
674 | return __awaiter(this, void 0, void 0, function () {
|
675 | var commentIdentifier, result;
|
676 | return __generator(this, function (_a) {
|
677 | switch (_a.label) {
|
678 | case 0:
|
679 | commentIdentifier = makeCommentIdentifier(context);
|
680 | this.logger.verbose.info('Using comment identifier:', commentIdentifier);
|
681 | return [4 , this.deleteComment(pr, context)];
|
682 | case 1:
|
683 | _a.sent();
|
684 | this.logger.verbose.info('Creating new comment');
|
685 | return [4 , this.github.issues.createComment({
|
686 | owner: this.options.owner,
|
687 | repo: this.options.repo,
|
688 | issue_number: pr,
|
689 | body: commentIdentifier + "\n" + message
|
690 | })];
|
691 | case 2:
|
692 | result = _a.sent();
|
693 | this.logger.veryVerbose.info('Got response from creating comment\n', result);
|
694 | this.logger.verbose.info('Successfully posted comment to PR');
|
695 | return [2 , result];
|
696 | }
|
697 | });
|
698 | });
|
699 | };
|
700 | Git.prototype.addToPrBody = function (message, pr, context) {
|
701 | if (context === void 0) { context = 'default'; }
|
702 | return __awaiter(this, void 0, void 0, function () {
|
703 | var id, issue, regex, body, result;
|
704 | return __generator(this, function (_a) {
|
705 | switch (_a.label) {
|
706 | case 0:
|
707 | id = makePrBodyIdentifier(context);
|
708 | this.logger.verbose.info('Using PR body identifier:', id);
|
709 | this.logger.verbose.info('Getting previous pr body on:', pr);
|
710 | return [4 , this.github.issues.get({
|
711 | owner: this.options.owner,
|
712 | repo: this.options.repo,
|
713 | issue_number: pr
|
714 | })];
|
715 | case 1:
|
716 | issue = _a.sent();
|
717 | this.logger.veryVerbose.info('Got PR description\n', issue.data.body);
|
718 | regex = new RegExp("(" + id + ")\\s*([\\S\\s]*)\\s*(" + id + ")");
|
719 | body = issue.data.body;
|
720 | if (body.match(regex)) {
|
721 | this.logger.verbose.info('Found previous message from same scope.');
|
722 | this.logger.verbose.info('Replacing pr body comment');
|
723 | body = body.replace(regex, message ? "$1\n" + message + "\n$3" : '');
|
724 | }
|
725 | else {
|
726 | body += message ? "\n" + id + "\n" + message + "\n" + id + "\n" : '';
|
727 | }
|
728 | this.logger.verbose.info('Creating new pr body');
|
729 | return [4 , this.github.issues.update({
|
730 | owner: this.options.owner,
|
731 | repo: this.options.repo,
|
732 | issue_number: pr,
|
733 | body: body
|
734 | })];
|
735 | case 2:
|
736 | result = _a.sent();
|
737 | this.logger.veryVerbose.info('Got response from updating body\n', result);
|
738 | this.logger.verbose.info("Successfully updated body of PR #" + pr);
|
739 | return [2 , result];
|
740 | }
|
741 | });
|
742 | });
|
743 | };
|
744 | Git.prototype.publish = function (releaseNotes, tag) {
|
745 | return __awaiter(this, void 0, void 0, function () {
|
746 | var result;
|
747 | return __generator(this, function (_a) {
|
748 | switch (_a.label) {
|
749 | case 0:
|
750 | this.logger.verbose.info('Creating release on GitHub for tag:', tag);
|
751 | return [4 , this.github.repos.createRelease({
|
752 | owner: this.options.owner,
|
753 | repo: this.options.repo,
|
754 | tag_name: tag,
|
755 | body: releaseNotes
|
756 | })];
|
757 | case 1:
|
758 | result = _a.sent();
|
759 | this.logger.veryVerbose.info('Got response from createRelease\n', result);
|
760 | this.logger.verbose.info('Created GitHub release.');
|
761 | return [2 , result];
|
762 | }
|
763 | });
|
764 | });
|
765 | };
|
766 | Git.prototype.getLatestTagInBranch = function () {
|
767 | return __awaiter(this, void 0, void 0, function () {
|
768 | return __generator(this, function (_a) {
|
769 | return [2 , exec_promise_1.default('git', ['describe', '--tags', '--abbrev=0'])];
|
770 | });
|
771 | });
|
772 | };
|
773 | __decorate([
|
774 | typescript_memoize_1.Memoize()
|
775 | ], Git.prototype, "getLatestReleaseInfo", null);
|
776 | __decorate([
|
777 | typescript_memoize_1.Memoize()
|
778 | ], Git.prototype, "getLatestRelease", null);
|
779 | __decorate([
|
780 | typescript_memoize_1.Memoize()
|
781 | ], Git.prototype, "getLabels", null);
|
782 | __decorate([
|
783 | typescript_memoize_1.Memoize()
|
784 | ], Git.prototype, "getPr", null);
|
785 | __decorate([
|
786 | typescript_memoize_1.Memoize()
|
787 | ], Git.prototype, "getGitLog", null);
|
788 | __decorate([
|
789 | typescript_memoize_1.Memoize()
|
790 | ], Git.prototype, "getUserByEmail", null);
|
791 | __decorate([
|
792 | typescript_memoize_1.Memoize()
|
793 | ], Git.prototype, "getUserByUsername", null);
|
794 | __decorate([
|
795 | typescript_memoize_1.Memoize()
|
796 | ], Git.prototype, "getPullRequest", null);
|
797 | __decorate([
|
798 | typescript_memoize_1.Memoize()
|
799 | ], Git.prototype, "getProject", null);
|
800 | __decorate([
|
801 | typescript_memoize_1.Memoize()
|
802 | ], Git.prototype, "getCommitsForPR", null);
|
803 | return Git;
|
804 | }());
|
805 | exports.default = Git;
|
806 |
|
\ | No newline at end of file |