1 | "use strict";
|
2 | var __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 | };
|
13 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
14 | return new (P || (P = Promise))(function (resolve, reject) {
|
15 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
16 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
17 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
18 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
19 | });
|
20 | };
|
21 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
22 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
23 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
24 | function verb(n) { return function (v) { return step([n, v]); }; }
|
25 | function step(op) {
|
26 | if (f) throw new TypeError("Generator is already executing.");
|
27 | while (_) try {
|
28 | 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;
|
29 | if (y = 0, t) op = [op[0] & 2, t.value];
|
30 | switch (op[0]) {
|
31 | case 0: case 1: t = op; break;
|
32 | case 4: _.label++; return { value: op[1], done: false };
|
33 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
34 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
35 | default:
|
36 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
37 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
38 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
39 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
40 | if (t[2]) _.ops.pop();
|
41 | _.trys.pop(); continue;
|
42 | }
|
43 | op = body.call(thisArg, _);
|
44 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
45 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
46 | }
|
47 | };
|
48 | var __rest = (this && this.__rest) || function (s, e) {
|
49 | var t = {};
|
50 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
51 | t[p] = s[p];
|
52 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
53 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
54 | t[p[i]] = s[p[i]];
|
55 | return t;
|
56 | };
|
57 | var __read = (this && this.__read) || function (o, n) {
|
58 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
59 | if (!m) return o;
|
60 | var i = m.call(o), r, ar = [], e;
|
61 | try {
|
62 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
63 | }
|
64 | catch (error) { e = { error: error }; }
|
65 | finally {
|
66 | try {
|
67 | if (r && !r.done && (m = i["return"])) m.call(i);
|
68 | }
|
69 | finally { if (e) throw e.error; }
|
70 | }
|
71 | return ar;
|
72 | };
|
73 | var __spread = (this && this.__spread) || function () {
|
74 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
75 | return ar;
|
76 | };
|
77 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
78 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
79 | };
|
80 | var __importStar = (this && this.__importStar) || function (mod) {
|
81 | if (mod && mod.__esModule) return mod;
|
82 | var result = {};
|
83 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
84 | result["default"] = mod;
|
85 | return result;
|
86 | };
|
87 | Object.defineProperty(exports, "__esModule", { value: true });
|
88 | var dotenv_1 = __importDefault(require("dotenv"));
|
89 | var is_ci_1 = __importDefault(require("is-ci"));
|
90 | var semver_1 = require("semver");
|
91 | var config_1 = __importDefault(require("./config"));
|
92 | var git_1 = __importDefault(require("./git"));
|
93 | var init_1 = __importDefault(require("./init"));
|
94 | var main_1 = require("./main");
|
95 | var release_1 = __importStar(require("./release"));
|
96 | var github_token_1 = __importDefault(require("./utils/github-token"));
|
97 | var load_plugins_1 = __importDefault(require("./utils/load-plugins"));
|
98 | var logger_1 = __importDefault(require("./utils/logger"));
|
99 | var make_hooks_1 = require("./utils/make-hooks");
|
100 | var Auto = (function () {
|
101 | function Auto(args) {
|
102 | var _this = this;
|
103 | this.prefixRelease = function (release) {
|
104 | if (!_this.release) {
|
105 | throw _this.createErrorMessage();
|
106 | }
|
107 | return _this.release.options.noVersionPrefix || release.startsWith('v')
|
108 | ? release
|
109 | : "v" + release;
|
110 | };
|
111 | this.args = args;
|
112 | this.logger = logger_1.default(args.veryVerbose ? 'veryVerbose' : args.verbose ? 'verbose' : undefined);
|
113 | this.hooks = make_hooks_1.makeHooks();
|
114 | this.hooks.onCreateRelease.tap('Link onCreateChangelog', function (release) {
|
115 | release.hooks.onCreateChangelog.tap('Link onCreateChangelog', function (changelog) {
|
116 | _this.hooks.onCreateChangelog.call(changelog);
|
117 | });
|
118 | });
|
119 | this.hooks.onCreateRelease.tap('Link onCreateLogParse', function (release) {
|
120 | release.hooks.onCreateLogParse.tap('Link onCreateLogParse', function (logParse) {
|
121 | _this.hooks.onCreateLogParse.call(logParse);
|
122 | });
|
123 | });
|
124 | dotenv_1.default.config();
|
125 | }
|
126 | |
127 |
|
128 |
|
129 |
|
130 | Auto.prototype.loadConfig = function () {
|
131 | return __awaiter(this, void 0, void 0, function () {
|
132 | var configLoader, config, _a, _b, repository, token, _c, githubOptions;
|
133 | return __generator(this, function (_d) {
|
134 | switch (_d.label) {
|
135 | case 0:
|
136 | configLoader = new config_1.default(this.logger);
|
137 | _b = (_a = this.hooks.modifyConfig).call;
|
138 | return [4 , configLoader.loadConfig(this.args)];
|
139 | case 1:
|
140 | config = _b.apply(_a, [_d.sent()]);
|
141 | this.logger.verbose.success('Loaded `auto` with config:', config);
|
142 | this.config = config;
|
143 | this.labels = config.labels;
|
144 | this.semVerLabels = release_1.getVersionMap(config.labels);
|
145 | this.loadPlugins(config);
|
146 | this.hooks.beforeRun.call(config);
|
147 | return [4 , this.getRepo(config)];
|
148 | case 2:
|
149 | repository = _d.sent();
|
150 | if (!(repository && repository.token)) return [3 , 3];
|
151 | _c = repository.token;
|
152 | return [3 , 5];
|
153 | case 3: return [4 , github_token_1.default(config.githubApi)];
|
154 | case 4:
|
155 | _c = _d.sent();
|
156 | _d.label = 5;
|
157 | case 5:
|
158 | token = _c;
|
159 | githubOptions = __assign({ owner: config.owner, repo: config.repo }, repository, { token: token, baseUrl: config.githubApi || 'https://api.github.com' });
|
160 | this.git = this.startGit(githubOptions);
|
161 | this.release = new release_1.default(this.git, config, this.logger);
|
162 | this.hooks.onCreateRelease.call(this.release);
|
163 | return [2 ];
|
164 | }
|
165 | });
|
166 | });
|
167 | };
|
168 | |
169 |
|
170 |
|
171 | Auto.prototype.init = function (options) {
|
172 | if (options === void 0) { options = {}; }
|
173 | return __awaiter(this, void 0, void 0, function () {
|
174 | return __generator(this, function (_a) {
|
175 | switch (_a.label) {
|
176 | case 0: return [4 , init_1.default(options, this.logger)];
|
177 | case 1:
|
178 | _a.sent();
|
179 | return [2 ];
|
180 | }
|
181 | });
|
182 | });
|
183 | };
|
184 | |
185 |
|
186 |
|
187 |
|
188 |
|
189 | Auto.prototype.createLabels = function (options) {
|
190 | if (options === void 0) { options = {}; }
|
191 | return __awaiter(this, void 0, void 0, function () {
|
192 | return __generator(this, function (_a) {
|
193 | switch (_a.label) {
|
194 | case 0:
|
195 | if (!this.release || !this.labels) {
|
196 | throw this.createErrorMessage();
|
197 | }
|
198 | return [4 , this.release.addLabelsToProject(this.labels, options)];
|
199 | case 1:
|
200 | _a.sent();
|
201 | return [2 ];
|
202 | }
|
203 | });
|
204 | });
|
205 | };
|
206 | |
207 |
|
208 |
|
209 |
|
210 |
|
211 | Auto.prototype.label = function (_a) {
|
212 | var pr = (_a === void 0 ? {} : _a).pr;
|
213 | return __awaiter(this, void 0, void 0, function () {
|
214 | var labels, pulls, lastMerged;
|
215 | return __generator(this, function (_b) {
|
216 | switch (_b.label) {
|
217 | case 0:
|
218 | if (!this.git) {
|
219 | throw this.createErrorMessage();
|
220 | }
|
221 | this.logger.verbose.info("Using command: 'label'");
|
222 | labels = [];
|
223 | if (!!pr) return [3 , 2];
|
224 | return [4 , this.git.getPullRequests({
|
225 | state: 'closed'
|
226 | })];
|
227 | case 1:
|
228 | pulls = _b.sent();
|
229 | lastMerged = pulls
|
230 | .sort(function (a, b) {
|
231 | return new Date(b.merged_at).getTime() - new Date(a.merged_at).getTime();
|
232 | })
|
233 | .find(function (pull) { return !!pull.merged_at; });
|
234 | if (lastMerged) {
|
235 | labels = lastMerged.labels.map(function (label) { return label.name; });
|
236 | }
|
237 | return [3 , 4];
|
238 | case 2: return [4 , this.git.getLabels(pr)];
|
239 | case 3:
|
240 | labels = _b.sent();
|
241 | _b.label = 4;
|
242 | case 4:
|
243 | if (labels.length) {
|
244 | console.log(labels.join('\n'));
|
245 | }
|
246 | return [2 ];
|
247 | }
|
248 | });
|
249 | });
|
250 | };
|
251 | |
252 |
|
253 |
|
254 |
|
255 |
|
256 | Auto.prototype.pr = function (_a) {
|
257 | var dryRun = _a.dryRun, pr = _a.pr, url = _a.url, options = __rest(_a, ["dryRun", "pr", "url"]);
|
258 | return __awaiter(this, void 0, void 0, function () {
|
259 | var sha, res, target_url, error_1;
|
260 | return __generator(this, function (_b) {
|
261 | switch (_b.label) {
|
262 | case 0:
|
263 | if (!this.git) {
|
264 | throw this.createErrorMessage();
|
265 | }
|
266 | sha = options.sha;
|
267 | this.logger.verbose.info("Using command: 'pr'");
|
268 | if (!(!sha && pr)) return [3 , 2];
|
269 | this.logger.verbose.info('Getting commit SHA from PR.');
|
270 | return [4 , this.git.getPullRequest(pr)];
|
271 | case 1:
|
272 | res = _b.sent();
|
273 | sha = res.data.head.sha;
|
274 | return [3 , 4];
|
275 | case 2:
|
276 | if (!!sha) return [3 , 4];
|
277 | this.logger.verbose.info('No PR found, getting commit SHA from HEAD.');
|
278 | return [4 , this.git.getSha()];
|
279 | case 3:
|
280 | sha = _b.sent();
|
281 | _b.label = 4;
|
282 | case 4:
|
283 | this.logger.verbose.info('Found PR SHA:', sha);
|
284 | target_url = url;
|
285 | if (!!dryRun) return [3 , 9];
|
286 | _b.label = 5;
|
287 | case 5:
|
288 | _b.trys.push([5, 7, , 8]);
|
289 | return [4 , this.git.createStatus(__assign({}, options, { sha: sha,
|
290 | target_url: target_url }))];
|
291 | case 6:
|
292 | _b.sent();
|
293 | return [3 , 8];
|
294 | case 7:
|
295 | error_1 = _b.sent();
|
296 | throw new Error("Failed to post status to Pull Request with error code " + error_1.status);
|
297 | case 8:
|
298 | this.logger.log.success('Posted status to Pull Request.');
|
299 | return [3 , 10];
|
300 | case 9:
|
301 | this.logger.verbose.info('`pr` dry run complete.');
|
302 | _b.label = 10;
|
303 | case 10:
|
304 | this.logger.verbose.success('Finished `pr` command');
|
305 | return [2 ];
|
306 | }
|
307 | });
|
308 | });
|
309 | };
|
310 | |
311 |
|
312 |
|
313 |
|
314 |
|
315 | Auto.prototype.prCheck = function (_a) {
|
316 | var dryRun = _a.dryRun, pr = _a.pr, url = _a.url, options = __rest(_a, ["dryRun", "pr", "url"]);
|
317 | return __awaiter(this, void 0, void 0, function () {
|
318 | var target_url, msg, sha, res, labels, labelTexts_1, releaseTag, skipReleaseTag, semverTag, description, error_2, error_3;
|
319 | var _this = this;
|
320 | return __generator(this, function (_b) {
|
321 | switch (_b.label) {
|
322 | case 0:
|
323 | if (!this.git || !this.release || !this.semVerLabels) {
|
324 | throw this.createErrorMessage();
|
325 | }
|
326 | this.logger.verbose.info("Using command: 'pr-check' for '" + url + "'");
|
327 | target_url = url;
|
328 | _b.label = 1;
|
329 | case 1:
|
330 | _b.trys.push([1, 4, , 5]);
|
331 | return [4 , this.git.getPullRequest(pr)];
|
332 | case 2:
|
333 | res = _b.sent();
|
334 | sha = res.data.head.sha;
|
335 | return [4 , this.git.getLabels(pr)];
|
336 | case 3:
|
337 | labels = _b.sent();
|
338 | labelTexts_1 = __spread(this.semVerLabels.values());
|
339 | releaseTag = labels.find(function (l) { return l === 'release'; });
|
340 | skipReleaseTag = labels.find(function (l) {
|
341 | return !!_this.release && _this.release.options.skipReleaseLabels.includes(l);
|
342 | });
|
343 | semverTag = labels.find(function (l) {
|
344 | return labelTexts_1.includes(l) &&
|
345 | !!_this.release &&
|
346 | !_this.release.options.skipReleaseLabels.includes(l) &&
|
347 | l !== 'release';
|
348 | });
|
349 | if (semverTag === undefined && !skipReleaseTag) {
|
350 | throw new Error('No semver label!');
|
351 | }
|
352 | this.logger.log.success("PR is using label: " + semverTag);
|
353 | description = void 0;
|
354 | if (skipReleaseTag) {
|
355 | description = 'PR will not create a release';
|
356 | }
|
357 | else if (releaseTag) {
|
358 | description = "PR will create release once merged - " + semverTag;
|
359 | }
|
360 | else {
|
361 | description = "CI - " + semverTag;
|
362 | }
|
363 | msg = {
|
364 | description: description,
|
365 | state: 'success'
|
366 | };
|
367 | return [3 , 5];
|
368 | case 4:
|
369 | error_2 = _b.sent();
|
370 | msg = {
|
371 | description: error_2.message,
|
372 | state: 'error'
|
373 | };
|
374 | return [3 , 5];
|
375 | case 5:
|
376 | this.logger.verbose.info('Posting comment to GitHub\n', msg);
|
377 | if (!!dryRun) return [3 , 10];
|
378 | _b.label = 6;
|
379 | case 6:
|
380 | _b.trys.push([6, 8, , 9]);
|
381 | return [4 , this.git.createStatus(__assign({}, options, msg, { target_url: target_url,
|
382 | sha: sha }))];
|
383 | case 7:
|
384 | _b.sent();
|
385 | this.logger.log.success('Posted status to Pull Request.');
|
386 | return [3 , 9];
|
387 | case 8:
|
388 | error_3 = _b.sent();
|
389 | throw new Error("Failed to post status to Pull Request with error code " + error_3.status);
|
390 | case 9: return [3 , 11];
|
391 | case 10:
|
392 | this.logger.verbose.info('`pr-check` dry run complete.');
|
393 | _b.label = 11;
|
394 | case 11:
|
395 | this.logger.verbose.success('Finished `pr-check` command');
|
396 | return [2 ];
|
397 | }
|
398 | });
|
399 | });
|
400 | };
|
401 | |
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 | Auto.prototype.comment = function (_a) {
|
408 | var message = _a.message, pr = _a.pr, _b = _a.context, context = _b === void 0 ? 'default' : _b, dryRun = _a.dryRun;
|
409 | return __awaiter(this, void 0, void 0, function () {
|
410 | return __generator(this, function (_c) {
|
411 | switch (_c.label) {
|
412 | case 0:
|
413 | if (!this.git) {
|
414 | throw this.createErrorMessage();
|
415 | }
|
416 | this.logger.verbose.info("Using command: 'comment'");
|
417 | if (!dryRun) return [3 , 1];
|
418 | this.logger.log.info("Would have commented on " + pr + " under \"" + context + "\" context:\n\n" + message);
|
419 | return [3 , 3];
|
420 | case 1: return [4 , this.git.createComment(message, pr, context)];
|
421 | case 2:
|
422 | _c.sent();
|
423 | this.logger.log.success("Commented on PR #" + pr);
|
424 | _c.label = 3;
|
425 | case 3: return [2 ];
|
426 | }
|
427 | });
|
428 | });
|
429 | };
|
430 | |
431 |
|
432 |
|
433 | Auto.prototype.version = function () {
|
434 | return __awaiter(this, void 0, void 0, function () {
|
435 | var bump;
|
436 | return __generator(this, function (_a) {
|
437 | switch (_a.label) {
|
438 | case 0:
|
439 | this.logger.verbose.info("Using command: 'version'");
|
440 | return [4 , this.getVersion()];
|
441 | case 1:
|
442 | bump = _a.sent();
|
443 | console.log(bump);
|
444 | return [2 ];
|
445 | }
|
446 | });
|
447 | });
|
448 | };
|
449 | |
450 |
|
451 |
|
452 | Auto.prototype.changelog = function (options) {
|
453 | return __awaiter(this, void 0, void 0, function () {
|
454 | return __generator(this, function (_a) {
|
455 | switch (_a.label) {
|
456 | case 0:
|
457 | this.logger.verbose.info("Using command: 'changelog'");
|
458 | return [4 , this.makeChangelog(options)];
|
459 | case 1:
|
460 | _a.sent();
|
461 | return [2 ];
|
462 | }
|
463 | });
|
464 | });
|
465 | };
|
466 | |
467 |
|
468 |
|
469 | Auto.prototype.runRelease = function (options) {
|
470 | return __awaiter(this, void 0, void 0, function () {
|
471 | return __generator(this, function (_a) {
|
472 | switch (_a.label) {
|
473 | case 0:
|
474 | this.logger.verbose.info("Using command: 'release'");
|
475 | return [4 , this.makeRelease(options)];
|
476 | case 1:
|
477 | _a.sent();
|
478 | return [2 ];
|
479 | }
|
480 | });
|
481 | });
|
482 | };
|
483 | |
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 | Auto.prototype.shipit = function (options) {
|
492 | return __awaiter(this, void 0, void 0, function () {
|
493 | var version, lastRelease, commitsInRelease, newVersion, current;
|
494 | return __generator(this, function (_a) {
|
495 | switch (_a.label) {
|
496 | case 0:
|
497 | if (!this.git || !this.release) {
|
498 | throw this.createErrorMessage();
|
499 | }
|
500 | this.logger.verbose.info("Using command: 'shipit'");
|
501 | this.hooks.beforeShipIt.call();
|
502 | return [4 , this.getVersion()];
|
503 | case 1:
|
504 | version = _a.sent();
|
505 | if (version === '') {
|
506 | return [2 ];
|
507 | }
|
508 | return [4 , this.git.getLatestRelease()];
|
509 | case 2:
|
510 | lastRelease = _a.sent();
|
511 | return [4 , this.release.getCommitsInRelease(lastRelease)];
|
512 | case 3:
|
513 | commitsInRelease = _a.sent();
|
514 | return [4 , this.makeChangelog(options)];
|
515 | case 4:
|
516 | _a.sent();
|
517 | if (!!options.dryRun) return [3 , 9];
|
518 | this.logger.verbose.info('Calling version hook');
|
519 | return [4 , this.hooks.version.promise(version)];
|
520 | case 5:
|
521 | _a.sent();
|
522 | this.logger.verbose.info('Calling after version hook');
|
523 | return [4 , this.hooks.afterVersion.promise()];
|
524 | case 6:
|
525 | _a.sent();
|
526 | this.logger.verbose.info('Calling publish hook');
|
527 | return [4 , this.hooks.publish.promise(version)];
|
528 | case 7:
|
529 | _a.sent();
|
530 | this.logger.verbose.info('Calling after publish hook');
|
531 | return [4 , this.hooks.afterPublish.promise()];
|
532 | case 8:
|
533 | _a.sent();
|
534 | _a.label = 9;
|
535 | case 9: return [4 , this.makeRelease(options)];
|
536 | case 10:
|
537 | newVersion = _a.sent();
|
538 | if (!options.dryRun) return [3 , 12];
|
539 | this.logger.log.warn("The version reported in the line above hasn't been incremented during `dry-run`");
|
540 | return [4 , this.getCurrentVersion(lastRelease)];
|
541 | case 11:
|
542 | current = _a.sent();
|
543 | this.logger.log.warn("Published version would be " + semver_1.inc(current, version));
|
544 | _a.label = 12;
|
545 | case 12: return [4 , this.hooks.afterShipIt.promise(newVersion, commitsInRelease)];
|
546 | case 13:
|
547 | _a.sent();
|
548 | return [2 ];
|
549 | }
|
550 | });
|
551 | });
|
552 | };
|
553 | Auto.prototype.startGit = function (gitOptions) {
|
554 | if (!gitOptions.owner || !gitOptions.repo || !gitOptions.token) {
|
555 | throw new Error('Must set owner, repo, and GitHub token.');
|
556 | }
|
557 | this.logger.verbose.info('Options contain repo information.');
|
558 |
|
559 | var tokenlessArgs = __assign({}, gitOptions, { token: "[Token starting with " + gitOptions.token.substring(0, 4) + "]" });
|
560 | this.logger.verbose.info('Initializing GitHub API with:\n', tokenlessArgs);
|
561 | return new git_1.default({
|
562 | owner: gitOptions.owner,
|
563 | repo: gitOptions.repo,
|
564 | token: gitOptions.token,
|
565 | baseUrl: gitOptions.baseUrl
|
566 | }, this.logger);
|
567 | };
|
568 | Auto.prototype.getVersion = function () {
|
569 | return __awaiter(this, void 0, void 0, function () {
|
570 | var lastRelease;
|
571 | return __generator(this, function (_a) {
|
572 | switch (_a.label) {
|
573 | case 0:
|
574 | if (!this.git || !this.release) {
|
575 | throw this.createErrorMessage();
|
576 | }
|
577 | return [4 , this.git.getLatestRelease()];
|
578 | case 1:
|
579 | lastRelease = _a.sent();
|
580 | return [2 , this.release.getSemverBump(lastRelease)];
|
581 | }
|
582 | });
|
583 | });
|
584 | };
|
585 | Auto.prototype.getCurrentVersion = function (lastRelease) {
|
586 | return __awaiter(this, void 0, void 0, function () {
|
587 | var lastVersion;
|
588 | var _this = this;
|
589 | return __generator(this, function (_a) {
|
590 | switch (_a.label) {
|
591 | case 0:
|
592 | this.hooks.getPreviousVersion.tap('None', function () {
|
593 | _this.logger.veryVerbose.info('No previous release found, using 0.0.0 as previous version.');
|
594 | return _this.prefixRelease('0.0.0');
|
595 | });
|
596 | return [4 , this.hooks.getPreviousVersion.promise(this.prefixRelease)];
|
597 | case 1:
|
598 | lastVersion = _a.sent();
|
599 | if (lastRelease.match(/\d+\.\d+\.\d+/) && semver_1.gt(lastRelease, lastVersion)) {
|
600 | this.logger.veryVerbose.info('Using latest release as previous version');
|
601 | return [2 , lastRelease];
|
602 | }
|
603 | return [2 , lastVersion];
|
604 | }
|
605 | });
|
606 | });
|
607 | };
|
608 | Auto.prototype.makeChangelog = function (_a) {
|
609 | var _b = _a === void 0 ? {} : _a, dryRun = _b.dryRun, from = _b.from, to = _b.to, message = _b.message;
|
610 | return __awaiter(this, void 0, void 0, function () {
|
611 | var lastRelease, _c, releaseNotes, currentVersion;
|
612 | return __generator(this, function (_d) {
|
613 | switch (_d.label) {
|
614 | case 0:
|
615 | if (!this.release || !this.git) {
|
616 | throw this.createErrorMessage();
|
617 | }
|
618 | return [4 , this.setGitUser()];
|
619 | case 1:
|
620 | _d.sent();
|
621 | _c = from;
|
622 | if (_c) return [3 , 3];
|
623 | return [4 , this.git.getLatestRelease()];
|
624 | case 2:
|
625 | _c = (_d.sent());
|
626 | _d.label = 3;
|
627 | case 3:
|
628 | lastRelease = _c;
|
629 | return [4 , this.release.generateReleaseNotes(lastRelease, to || undefined)];
|
630 | case 4:
|
631 | releaseNotes = _d.sent();
|
632 | this.logger.log.info('New Release Notes\n', releaseNotes);
|
633 | if (dryRun) {
|
634 | this.logger.verbose.info('`changelog` dry run complete.');
|
635 | return [2 ];
|
636 | }
|
637 | return [4 , this.getCurrentVersion(lastRelease)];
|
638 | case 5:
|
639 | currentVersion = _d.sent();
|
640 | return [4 , this.release.addToChangelog(releaseNotes, lastRelease, currentVersion, message)];
|
641 | case 6:
|
642 | _d.sent();
|
643 | return [2 ];
|
644 | }
|
645 | });
|
646 | });
|
647 | };
|
648 | Auto.prototype.makeRelease = function (_a) {
|
649 | var _b = _a === void 0 ? {} : _a, dryRun = _b.dryRun, useVersion = _b.useVersion, slack = _b.slack;
|
650 | return __awaiter(this, void 0, void 0, function () {
|
651 | var lastRelease, commitsInRelease, releaseNotes, version, _c, prefixed;
|
652 | return __generator(this, function (_d) {
|
653 | switch (_d.label) {
|
654 | case 0:
|
655 | if (!this.release || !this.git) {
|
656 | throw this.createErrorMessage();
|
657 | }
|
658 | return [4 , this.git.getLatestRelease()];
|
659 | case 1:
|
660 | lastRelease = _d.sent();
|
661 |
|
662 | this.logger.veryVerbose.info("Using " + lastRelease + " as previous release.");
|
663 | if (lastRelease.match(/\d+\.\d+\.\d+/)) {
|
664 | lastRelease = this.prefixRelease(lastRelease);
|
665 | }
|
666 | this.logger.log.info('Last used release:', lastRelease);
|
667 | return [4 , this.release.getCommitsInRelease(lastRelease)];
|
668 | case 2:
|
669 | commitsInRelease = _d.sent();
|
670 | return [4 , this.release.generateReleaseNotes(lastRelease)];
|
671 | case 3:
|
672 | releaseNotes = _d.sent();
|
673 | this.logger.log.info("Using release notes:\n" + releaseNotes);
|
674 | _c = useVersion;
|
675 | if (_c) return [3 , 5];
|
676 | return [4 , this.getCurrentVersion(lastRelease)];
|
677 | case 4:
|
678 | _c = (_d.sent());
|
679 | _d.label = 5;
|
680 | case 5:
|
681 | version = _c;
|
682 | if (!version) {
|
683 | this.logger.log.error('Could not calculate next version from last tag.');
|
684 | return [2 ];
|
685 | }
|
686 | prefixed = this.prefixRelease(version);
|
687 | this.logger.log.info("Publishing " + prefixed + " to GitHub.");
|
688 | if (!!dryRun) return [3 , 9];
|
689 | return [4 , this.git.publish(releaseNotes, prefixed)];
|
690 | case 6:
|
691 | _d.sent();
|
692 | if (!(slack || (this.config && this.config.slack))) return [3 , 8];
|
693 | this.logger.log.info('Posting release to slack');
|
694 | return [4 , this.release.postToSlack(releaseNotes, prefixed)];
|
695 | case 7:
|
696 | _d.sent();
|
697 | _d.label = 8;
|
698 | case 8: return [3 , 10];
|
699 | case 9:
|
700 | this.logger.verbose.info('Release dry run complete.');
|
701 | _d.label = 10;
|
702 | case 10: return [4 , this.hooks.afterRelease.promise(prefixed, commitsInRelease)];
|
703 | case 11:
|
704 | _d.sent();
|
705 | return [2 , prefixed];
|
706 | }
|
707 | });
|
708 | });
|
709 | };
|
710 | Auto.prototype.createErrorMessage = function () {
|
711 | return new Error("Auto is not initialized! Make sure the have run Auto.loadConfig");
|
712 | };
|
713 | |
714 |
|
715 |
|
716 | Auto.prototype.setGitUser = function () {
|
717 | return __awaiter(this, void 0, void 0, function () {
|
718 | var error_4, _a, email, name, packageAuthor;
|
719 | return __generator(this, function (_b) {
|
720 | switch (_b.label) {
|
721 | case 0:
|
722 | _b.trys.push([0, 3, , 9]);
|
723 |
|
724 | return [4 , main_1.execPromise('git', ['config', 'user.email'])];
|
725 | case 1:
|
726 |
|
727 | _b.sent();
|
728 | return [4 , main_1.execPromise('git', ['config', 'user.name'])];
|
729 | case 2:
|
730 | _b.sent();
|
731 | return [3 , 9];
|
732 | case 3:
|
733 | error_4 = _b.sent();
|
734 | if (!is_ci_1.default) {
|
735 | this.logger.log.note("Detected local environment, will not set git user. This happens automatically in a CI environment.\n\nIf a command fails manually run:\n\n - git config user.email your@email.com\n - git config user.name \"Your Name\"");
|
736 | return [2 ];
|
737 | }
|
738 | if (!this.release) {
|
739 | return [2 ];
|
740 | }
|
741 | _a = this.release.options, email = _a.email, name = _a.name;
|
742 | return [4 , this.hooks.getAuthor.promise()];
|
743 | case 4:
|
744 | packageAuthor = _b.sent();
|
745 | email = packageAuthor ? packageAuthor.email : email;
|
746 | name = packageAuthor ? packageAuthor.name : name;
|
747 | if (!email) return [3 , 6];
|
748 | return [4 , main_1.execPromise('git', ['config', 'user.email', "\"" + email + "\""])];
|
749 | case 5:
|
750 | _b.sent();
|
751 | _b.label = 6;
|
752 | case 6:
|
753 | if (!name) return [3 , 8];
|
754 | return [4 , main_1.execPromise('git', ['config', 'user.name', "\"" + name + "\""])];
|
755 | case 7:
|
756 | _b.sent();
|
757 | _b.label = 8;
|
758 | case 8: return [3 , 9];
|
759 | case 9: return [2 ];
|
760 | }
|
761 | });
|
762 | });
|
763 | };
|
764 | Auto.prototype.getRepo = function (config) {
|
765 | return __awaiter(this, void 0, void 0, function () {
|
766 | return __generator(this, function (_a) {
|
767 | if (config.owner && config.repo) {
|
768 | return [2 , config];
|
769 | }
|
770 | return [2 , this.hooks.getRepository.promise()];
|
771 | });
|
772 | });
|
773 | };
|
774 | |
775 |
|
776 |
|
777 | Auto.prototype.loadPlugins = function (config) {
|
778 | var _this = this;
|
779 | var pluginsPaths = config.plugins || ['npm'];
|
780 | pluginsPaths
|
781 | .map(function (plugin) {
|
782 | return typeof plugin === 'string' ? [plugin, {}] : plugin;
|
783 | })
|
784 | .map(function (plugin) { return load_plugins_1.default(plugin, _this.logger); })
|
785 | .filter(function (plugin) { return !!plugin; })
|
786 | .forEach(function (plugin) {
|
787 | _this.logger.verbose.info("Using " + plugin.name + " Plugin...");
|
788 | plugin.apply(_this);
|
789 | });
|
790 | };
|
791 | return Auto;
|
792 | }());
|
793 | exports.default = Auto;
|
794 |
|
\ | No newline at end of file |