UNPKG

33.8 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || function () {
3 __assign = Object.assign || function(t) {
4 for (var s, i = 1, n = arguments.length; i < n; i++) {
5 s = arguments[i];
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 t[p] = s[p];
8 }
9 return t;
10 };
11 return __assign.apply(this, arguments);
12};
13var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16 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;
17 return c > 3 && r && Object.defineProperty(target, key, r), r;
18};
19var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
20 return new (P || (P = Promise))(function (resolve, reject) {
21 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
24 step((generator = generator.apply(thisArg, _arguments || [])).next());
25 });
26};
27var __generator = (this && this.__generator) || function (thisArg, body) {
28 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
29 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
30 function verb(n) { return function (v) { return step([n, v]); }; }
31 function step(op) {
32 if (f) throw new TypeError("Generator is already executing.");
33 while (_) try {
34 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;
35 if (y = 0, t) op = [op[0] & 2, t.value];
36 switch (op[0]) {
37 case 0: case 1: t = op; break;
38 case 4: _.label++; return { value: op[1], done: false };
39 case 5: _.label++; y = op[1]; op = [0]; continue;
40 case 7: op = _.ops.pop(); _.trys.pop(); continue;
41 default:
42 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
43 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
44 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
45 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
46 if (t[2]) _.ops.pop();
47 _.trys.pop(); continue;
48 }
49 op = body.call(thisArg, _);
50 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
51 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
52 }
53};
54var __read = (this && this.__read) || function (o, n) {
55 var m = typeof Symbol === "function" && o[Symbol.iterator];
56 if (!m) return o;
57 var i = m.call(o), r, ar = [], e;
58 try {
59 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
60 }
61 catch (error) { e = { error: error }; }
62 finally {
63 try {
64 if (r && !r.done && (m = i["return"])) m.call(i);
65 }
66 finally { if (e) throw e.error; }
67 }
68 return ar;
69};
70var __spread = (this && this.__spread) || function () {
71 for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
72 return ar;
73};
74var __importStar = (this && this.__importStar) || function (mod) {
75 if (mod && mod.__esModule) return mod;
76 var result = {};
77 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
78 result["default"] = mod;
79 return result;
80};
81var __importDefault = (this && this.__importDefault) || function (mod) {
82 return (mod && mod.__esModule) ? mod : { "default": mod };
83};
84Object.defineProperty(exports, "__esModule", { value: true });
85var _a;
86var fs = __importStar(require("fs"));
87var semver_1 = require("semver");
88var util_1 = require("util");
89var typescript_memoize_1 = require("typescript-memoize");
90var changelog_1 = __importDefault(require("./changelog"));
91var log_parse_1 = __importDefault(require("./log-parse"));
92var semver_2 = __importStar(require("./semver"));
93var exec_promise_1 = __importDefault(require("./utils/exec-promise"));
94var logger_1 = require("./utils/logger");
95var make_hooks_1 = require("./utils/make-hooks");
96var slack_1 = __importDefault(require("./utils/slack"));
97exports.defaultLabels = [
98 semver_2.default.major,
99 semver_2.default.minor,
100 semver_2.default.patch,
101 'skip-release',
102 'release',
103 'prerelease'
104];
105exports.isVersionLabel = function (label) {
106 return exports.defaultLabels.includes(label);
107};
108exports.defaultLabelDefinition = (_a = {},
109 _a[semver_2.default.major] = {
110 name: 'major',
111 title: '💥 Breaking Change',
112 description: 'Increment the major version when merged'
113 },
114 _a[semver_2.default.minor] = {
115 name: 'minor',
116 title: '🚀 Enhancement',
117 description: 'Increment the minor version when merged'
118 },
119 _a[semver_2.default.patch] = {
120 name: 'patch',
121 title: '🐛 Bug Fix',
122 description: 'Increment the patch version when merged'
123 },
124 _a['skip-release'] = {
125 name: 'skip-release',
126 description: 'Preserve the current version when merged'
127 },
128 _a.release = {
129 name: 'release',
130 description: 'Create a release when this pr is merged'
131 },
132 _a.prerelease = {
133 name: 'prerelease',
134 title: '🚧 Prerelease',
135 description: 'Create a pre-release version when merged'
136 },
137 _a.internal = {
138 name: 'internal',
139 title: '🏠 Internal',
140 description: 'Changes only affect the internal API'
141 },
142 _a.documentation = {
143 name: 'documentation',
144 title: '📝 Documentation',
145 description: 'Changes only affect the documentation'
146 },
147 _a);
148exports.getVersionMap = function (labels) {
149 if (labels === void 0) { labels = exports.defaultLabelDefinition; }
150 return Object.entries(labels).reduce(function (semVer, _a) {
151 var _b = __read(_a, 2), label = _b[0], labelDef = _b[1];
152 if (exports.isVersionLabel(label)) {
153 semVer.set(label, labelDef.name);
154 }
155 return semVer;
156 // tslint:disable-next-line align
157 }, new Map());
158};
159var readFile = util_1.promisify(fs.readFile);
160var writeFile = util_1.promisify(fs.writeFile);
161/**
162 * A class for interacting with the git remote
163 */
164var Release = /** @class */ (function () {
165 function Release(git, options, logger) {
166 if (options === void 0) { options = {
167 skipReleaseLabels: [],
168 labels: exports.defaultLabelDefinition
169 }; }
170 if (logger === void 0) { logger = logger_1.dummyLog(); }
171 this.options = options;
172 this.logger = logger;
173 this.hooks = make_hooks_1.makeReleaseHooks();
174 this.versionLabels = exports.getVersionMap(options.labels);
175 this.git = git;
176 }
177 /**
178 * Generate a changelog from a range of commits.
179 *
180 * @param from sha or tag to start changelog from
181 * @param to sha or tag to end changelog at (defaults to HEAD)
182 */
183 Release.prototype.generateReleaseNotes = function (from, to) {
184 if (to === void 0) { to = 'HEAD'; }
185 return __awaiter(this, void 0, void 0, function () {
186 var commits, project, changelog;
187 return __generator(this, function (_a) {
188 switch (_a.label) {
189 case 0: return [4 /*yield*/, this.getCommitsInRelease(from, to)];
190 case 1:
191 commits = _a.sent();
192 return [4 /*yield*/, this.git.getProject()];
193 case 2:
194 project = _a.sent();
195 changelog = new changelog_1.default(this.logger, {
196 owner: this.git.options.owner,
197 repo: this.git.options.repo,
198 baseUrl: project.html_url,
199 jira: this.options.jira,
200 labels: this.options.labels
201 });
202 this.hooks.onCreateChangelog.call(changelog);
203 changelog.loadDefaultHooks();
204 return [2 /*return*/, changelog.generateReleaseNotes(commits)];
205 }
206 });
207 });
208 };
209 Release.prototype.getCommitsInRelease = function (from, to) {
210 if (to === void 0) { to = 'HEAD'; }
211 return __awaiter(this, void 0, void 0, function () {
212 var allCommits, allPrCommits, allPrCommitHashes, labelled;
213 var _this = this;
214 return __generator(this, function (_a) {
215 switch (_a.label) {
216 case 0: return [4 /*yield*/, this.getCommits(from, to)];
217 case 1:
218 allCommits = _a.sent();
219 return [4 /*yield*/, Promise.all(allCommits
220 .filter(function (commit) { return commit.pullRequest; })
221 .map(function (commit) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
222 return [2 /*return*/, this.git.getCommitsForPR(Number(commit.pullRequest.number))];
223 }); }); }))];
224 case 2:
225 allPrCommits = _a.sent();
226 allPrCommitHashes = allPrCommits
227 .filter(Boolean)
228 .reduce(function (all, pr) { return __spread(all, pr.map(function (subCommit) { return subCommit.sha; })); }, []);
229 labelled = allCommits.filter(function (commit) {
230 return !allPrCommitHashes.includes(commit.hash) &&
231 !commit.subject.includes('[skip ci]');
232 });
233 return [4 /*yield*/, Promise.all(labelled.map(function (commit) { return __awaiter(_this, void 0, void 0, function () {
234 var prs, labels;
235 return __generator(this, function (_a) {
236 switch (_a.label) {
237 case 0:
238 if (commit.pullRequest) {
239 return [2 /*return*/, commit];
240 }
241 return [4 /*yield*/, this.git.searchRepo({ q: commit.hash })];
242 case 1:
243 prs = _a.sent();
244 if (prs && prs.items && prs.total_count > 0) {
245 labels = prs.items[0].labels || [];
246 commit.labels = __spread(labels.map(function (label) { return label.name; }), commit.labels);
247 }
248 else {
249 commit.labels = __spread(['pushToMaster'], commit.labels);
250 }
251 commit.subject = commit.subject.split('\n')[0];
252 return [2 /*return*/];
253 }
254 });
255 }); }))];
256 case 3:
257 _a.sent();
258 return [2 /*return*/, labelled];
259 }
260 });
261 });
262 };
263 /**
264 * Prepend a set of release notes to the changelog.md
265 *
266 * @param releaseNotes Release notes to prepend to the changelog
267 * @param lastRelease Last release version of the code. Could be the first commit SHA
268 * @param currentVersion Current version of the code
269 * @param message Message to commit the changelog with
270 */
271 Release.prototype.addToChangelog = function (releaseNotes, lastRelease, currentVersion, message) {
272 if (message === void 0) { message = 'Update CHANGELOG.md [skip ci]'; }
273 return __awaiter(this, void 0, void 0, function () {
274 var version, bump, date, prefixed, newChangelog, oldChangelog;
275 return __generator(this, function (_a) {
276 switch (_a.label) {
277 case 0:
278 this.logger.verbose.info('Adding new changes to changelog.');
279 if (!lastRelease.match(/\d+\.\d+\.\d+/)) return [3 /*break*/, 2];
280 return [4 /*yield*/, this.calcNextVersion(lastRelease)];
281 case 1:
282 version = _a.sent();
283 return [3 /*break*/, 4];
284 case 2: return [4 /*yield*/, this.getSemverBump(lastRelease)];
285 case 3:
286 bump = _a.sent();
287 version = semver_1.inc(currentVersion, bump);
288 _a.label = 4;
289 case 4:
290 this.logger.verbose.info('Calculated next version to be:', version);
291 date = new Date().toDateString();
292 prefixed = this.options.noVersionPrefix || (version && version.startsWith('v'))
293 ? version
294 : "v" + version;
295 newChangelog = "# " + prefixed + " (" + date + ")\n\n" + releaseNotes;
296 if (!fs.existsSync('CHANGELOG.md')) return [3 /*break*/, 6];
297 this.logger.verbose.info('Old changelog exists, prepending changes.');
298 return [4 /*yield*/, readFile('CHANGELOG.md', 'utf8')];
299 case 5:
300 oldChangelog = _a.sent();
301 newChangelog = newChangelog + "\n\n---\n\n" + oldChangelog;
302 _a.label = 6;
303 case 6: return [4 /*yield*/, writeFile('CHANGELOG.md', newChangelog)];
304 case 7:
305 _a.sent();
306 this.logger.verbose.info('Wrote new changelog to filesystem.');
307 return [4 /*yield*/, exec_promise_1.default('git', ['add', 'CHANGELOG.md'])];
308 case 8:
309 _a.sent();
310 return [4 /*yield*/, exec_promise_1.default('git', ['commit', '-m', "\"" + message + "\"", '--no-verify'])];
311 case 9:
312 _a.sent();
313 this.logger.verbose.info('Commited new changelog.');
314 return [2 /*return*/];
315 }
316 });
317 });
318 };
319 /**
320 * Get a range of commits. The commits will have PR numbers and labels attached
321 *
322 * @param from Tag or SHA to start at
323 * @param to Tage or SHA to end at (defaults to HEAD)
324 */
325 Release.prototype.getCommits = function (from, to) {
326 if (to === void 0) { to = 'HEAD'; }
327 return __awaiter(this, void 0, void 0, function () {
328 var gitlog, logParse, commits;
329 var _this = this;
330 return __generator(this, function (_a) {
331 switch (_a.label) {
332 case 0:
333 this.logger.verbose.info("Getting commits from " + from + " to " + to);
334 return [4 /*yield*/, this.git.getGitLog(from, to)];
335 case 1:
336 gitlog = _a.sent();
337 this.logger.veryVerbose.info('Got gitlog:\n', gitlog);
338 return [4 /*yield*/, this.createLogParse()];
339 case 2:
340 logParse = _a.sent();
341 return [4 /*yield*/, logParse.normalizeCommits(gitlog)];
342 case 3:
343 commits = _a.sent();
344 this.logger.veryVerbose.info('Added labels to commits:\n', commits);
345 return [4 /*yield*/, Promise.all(commits.map(function (commit) { return __awaiter(_this, void 0, void 0, function () {
346 var resolvedAuthors, prCommits, author;
347 var _this = this;
348 return __generator(this, function (_a) {
349 switch (_a.label) {
350 case 0:
351 resolvedAuthors = [];
352 if (!commit.pullRequest) return [3 /*break*/, 3];
353 return [4 /*yield*/, this.git.getCommitsForPR(Number(commit.pullRequest.number))];
354 case 1:
355 prCommits = _a.sent();
356 if (!prCommits) {
357 return [2 /*return*/];
358 }
359 return [4 /*yield*/, Promise.all(prCommits.map(function (prCommit) { return __awaiter(_this, void 0, void 0, function () {
360 return __generator(this, function (_a) {
361 if (prCommit && prCommit.author) {
362 return [2 /*return*/, this.git.getUserByUsername(prCommit.author.login)];
363 }
364 return [2 /*return*/];
365 });
366 }); }))];
367 case 2:
368 resolvedAuthors = _a.sent();
369 return [3 /*break*/, 5];
370 case 3:
371 if (!commit.authorEmail) return [3 /*break*/, 5];
372 return [4 /*yield*/, this.git.getUserByEmail(commit.authorEmail)];
373 case 4:
374 author = _a.sent();
375 resolvedAuthors.push(author);
376 _a.label = 5;
377 case 5:
378 commit.authors = resolvedAuthors.map(function (author) { return (__assign({}, author, { username: author ? author.login : undefined })); });
379 commit.authors.map(function (author) {
380 _this.logger.veryVerbose.info("Found author: " + author.username);
381 });
382 return [2 /*return*/];
383 }
384 });
385 }); }))];
386 case 4:
387 _a.sent();
388 return [2 /*return*/, commits];
389 }
390 });
391 });
392 };
393 Release.prototype.addLabelsToProject = function (labels, options) {
394 if (options === void 0) { options = {}; }
395 return __awaiter(this, void 0, void 0, function () {
396 var oldLabels, labelsToCreate, repoMetadata, justLabelNames, state, state;
397 var _this = this;
398 return __generator(this, function (_a) {
399 switch (_a.label) {
400 case 0: return [4 /*yield*/, this.git.getProjectLabels()];
401 case 1:
402 oldLabels = _a.sent();
403 labelsToCreate = Object.entries(labels).filter(function (_a) {
404 var _b = __read(_a, 2), versionLabel = _b[0], labelDef = _b[1];
405 if (!labelDef) {
406 return;
407 }
408 if (versionLabel === 'release' &&
409 !_this.options.onlyPublishWithReleaseLabel) {
410 return;
411 }
412 if (versionLabel === 'skip-release' &&
413 _this.options.onlyPublishWithReleaseLabel) {
414 return;
415 }
416 return true;
417 });
418 if (!!options.dryRun) return [3 /*break*/, 3];
419 return [4 /*yield*/, Promise.all(labelsToCreate.map(function (_a) {
420 var _b = __read(_a, 2), label = _b[0], labelDef = _b[1];
421 return __awaiter(_this, void 0, void 0, function () {
422 return __generator(this, function (_c) {
423 switch (_c.label) {
424 case 0:
425 if (!labelDef) {
426 return [2 /*return*/];
427 }
428 if (!(oldLabels && oldLabels.includes(labelDef.name))) return [3 /*break*/, 2];
429 return [4 /*yield*/, this.git.updateLabel(label, labelDef)];
430 case 1:
431 _c.sent();
432 return [3 /*break*/, 4];
433 case 2: return [4 /*yield*/, this.git.createLabel(label, labelDef)];
434 case 3:
435 _c.sent();
436 _c.label = 4;
437 case 4: return [2 /*return*/];
438 }
439 });
440 });
441 }))];
442 case 2:
443 _a.sent();
444 _a.label = 3;
445 case 3: return [4 /*yield*/, this.git.getProject()];
446 case 4:
447 repoMetadata = _a.sent();
448 justLabelNames = labelsToCreate.map(function (_a) {
449 var _b = __read(_a, 1), name = _b[0];
450 return name;
451 });
452 if (justLabelNames.length > 0) {
453 state = options.dryRun ? 'Would have created' : 'Created';
454 this.logger.log.log(state + " labels: " + justLabelNames.join(', '));
455 }
456 else {
457 state = options.dryRun ? 'would have been' : 'were';
458 this.logger.log.log("No labels " + state + " created, they must have already been present on your project.");
459 }
460 if (options.dryRun) {
461 return [2 /*return*/];
462 }
463 this.logger.log.log("\nYou can see these, and more at " + repoMetadata.html_url + "/labels");
464 return [2 /*return*/];
465 }
466 });
467 });
468 };
469 /**
470 * Calculate the SEMVER bump over a range of commits using the PR labels
471 *
472 * @param from Tag or SHA to start at
473 * @param to Tage or SHA to end at (defaults to HEAD)
474 */
475 Release.prototype.getSemverBump = function (from, to) {
476 if (to === void 0) { to = 'HEAD'; }
477 return __awaiter(this, void 0, void 0, function () {
478 var commits, labels, _a, onlyPublishWithReleaseLabel, skipReleaseLabels, options, result;
479 return __generator(this, function (_b) {
480 switch (_b.label) {
481 case 0: return [4 /*yield*/, this.getCommits(from, to)];
482 case 1:
483 commits = _b.sent();
484 labels = commits.map(function (commit) { return commit.labels; });
485 _a = this.options, onlyPublishWithReleaseLabel = _a.onlyPublishWithReleaseLabel, skipReleaseLabels = _a.skipReleaseLabels;
486 options = { onlyPublishWithReleaseLabel: onlyPublishWithReleaseLabel, skipReleaseLabels: skipReleaseLabels };
487 this.logger.verbose.info('Calculating SEMVER bump using:\n', {
488 labels: labels,
489 versionLabels: this.versionLabels,
490 options: options
491 });
492 result = semver_2.calculateSemVerBump(labels, this.versionLabels, options);
493 this.logger.verbose.success('Calculated SEMVER bump:', result);
494 return [2 /*return*/, result];
495 }
496 });
497 });
498 };
499 /**
500 * Post the release notes to slack.
501 *
502 * @param releaseNotes Release notes to post to slack
503 * @param tag Version to include in the title of the slack message
504 */
505 Release.prototype.postToSlack = function (releaseNotes, tag) {
506 return __awaiter(this, void 0, void 0, function () {
507 var project;
508 return __generator(this, function (_a) {
509 switch (_a.label) {
510 case 0:
511 if (!this.options.slack) {
512 throw new Error('Slack url must be set to post a message to slack.');
513 }
514 return [4 /*yield*/, this.git.getProject()];
515 case 1:
516 project = _a.sent();
517 this.logger.verbose.info('Posting release notes to slack.');
518 return [4 /*yield*/, slack_1.default(releaseNotes, {
519 tag: tag,
520 owner: this.git.options.owner,
521 repo: this.git.options.repo,
522 baseUrl: project.html_url,
523 slackUrl: this.options.slack
524 })];
525 case 2:
526 _a.sent();
527 this.logger.verbose.info('Posted release notes to slack.');
528 return [2 /*return*/];
529 }
530 });
531 });
532 };
533 Release.prototype.calcNextVersion = function (lastTag) {
534 return __awaiter(this, void 0, void 0, function () {
535 var bump;
536 return __generator(this, function (_a) {
537 switch (_a.label) {
538 case 0: return [4 /*yield*/, this.getSemverBump(lastTag)];
539 case 1:
540 bump = _a.sent();
541 return [2 /*return*/, semver_1.inc(lastTag, bump)];
542 }
543 });
544 });
545 };
546 Release.prototype.createLogParse = function () {
547 return __awaiter(this, void 0, void 0, function () {
548 var logParse;
549 var _this = this;
550 return __generator(this, function (_a) {
551 logParse = new log_parse_1.default();
552 logParse.hooks.parseCommit.tapPromise('Labels', function (commit) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
553 return [2 /*return*/, this.addLabelsToCommit(commit)];
554 }); }); });
555 logParse.hooks.parseCommit.tapPromise('PR Commits', function (commit) { return __awaiter(_this, void 0, void 0, function () {
556 var prsSinceLastRelease;
557 return __generator(this, function (_a) {
558 switch (_a.label) {
559 case 0: return [4 /*yield*/, this.getPRsSinceLastRelease()];
560 case 1:
561 prsSinceLastRelease = _a.sent();
562 return [2 /*return*/, this.getPRForRebasedCommits(commit, prsSinceLastRelease)];
563 }
564 });
565 }); });
566 this.hooks.onCreateLogParse.call(logParse);
567 return [2 /*return*/, logParse];
568 });
569 });
570 };
571 Release.prototype.getPRsSinceLastRelease = function () {
572 return __awaiter(this, void 0, void 0, function () {
573 var lastRelease, error_1, firstCommit, _a, prsSinceLastRelease, data;
574 var _this = this;
575 return __generator(this, function (_b) {
576 switch (_b.label) {
577 case 0:
578 _b.trys.push([0, 2, , 5]);
579 return [4 /*yield*/, this.git.getLatestReleaseInfo()];
580 case 1:
581 lastRelease = _b.sent();
582 return [3 /*break*/, 5];
583 case 2:
584 error_1 = _b.sent();
585 return [4 /*yield*/, this.git.getFirstCommit()];
586 case 3:
587 firstCommit = _b.sent();
588 _a = {};
589 return [4 /*yield*/, this.git.getCommitDate(firstCommit)];
590 case 4:
591 lastRelease = (_a.published_at = _b.sent(),
592 _a);
593 return [3 /*break*/, 5];
594 case 5:
595 if (!lastRelease) {
596 return [2 /*return*/, []];
597 }
598 return [4 /*yield*/, this.git.searchRepo({
599 q: "is:pr is:merged merged:>=" + lastRelease.published_at
600 })];
601 case 6:
602 prsSinceLastRelease = _b.sent();
603 if (!prsSinceLastRelease || !prsSinceLastRelease.items) {
604 return [2 /*return*/, []];
605 }
606 return [4 /*yield*/, Promise.all(prsSinceLastRelease.items.map(function (pr) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
607 return [2 /*return*/, this.git.getPullRequest(Number(pr.number))];
608 }); }); }))];
609 case 7:
610 data = _b.sent();
611 return [2 /*return*/, data.map(function (item) { return item.data; })];
612 }
613 });
614 });
615 };
616 /**
617 * Add the PR labels to the commit
618 *
619 * @param commits Commits to modify
620 */
621 Release.prototype.addLabelsToCommit = function (commit) {
622 return __awaiter(this, void 0, void 0, function () {
623 var labels;
624 return __generator(this, function (_a) {
625 switch (_a.label) {
626 case 0:
627 if (!commit.labels) {
628 commit.labels = [];
629 }
630 if (!commit.pullRequest) return [3 /*break*/, 2];
631 return [4 /*yield*/, this.git.getLabels(commit.pullRequest.number)];
632 case 1:
633 labels = (_a.sent()) || [];
634 commit.labels = __spread(labels, commit.labels);
635 _a.label = 2;
636 case 2: return [2 /*return*/, commit];
637 }
638 });
639 });
640 };
641 /**
642 * Commits from rebased PRs do not have messages that tie them to a PR
643 * Instead we have to find all PRs since the last release and try to match
644 * their merge commit SHAs.
645 *
646 * @param commits Commits to modify
647 */
648 Release.prototype.getPRForRebasedCommits = function (commit, pullRequests) {
649 var matchPr = pullRequests.find(function (pr) { return pr.merge_commit_sha === commit.hash; });
650 if (!commit.pullRequest && matchPr) {
651 var labels = matchPr.labels.map(function (label) { return label.name; }) || [];
652 commit.labels = __spread(labels, commit.labels);
653 commit.pullRequest = {
654 number: matchPr.number
655 };
656 }
657 return commit;
658 };
659 __decorate([
660 typescript_memoize_1.Memoize()
661 ], Release.prototype, "createLogParse", null);
662 __decorate([
663 typescript_memoize_1.Memoize()
664 ], Release.prototype, "getPRsSinceLastRelease", null);
665 return Release;
666}());
667exports.default = Release;
668//# sourceMappingURL=release.js.map
\No newline at end of file