UNPKG

morning-builds-core

Version:

Core functionality for Morning Builds

183 lines 10.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [0, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var BluebirdPromise = require("bluebird"); var fail_categories_1 = require("../fail-categories"); var formatMessages = require("./format-messages"); var Report = /** @class */ (function () { function Report(store, clients, managers) { this.statisticsStore = store.statistics; this.executionStore = store.execution; this.bambooClient = clients.bamboo; this.commentsManager = managers.comments; this.failingTestsManager = managers.failingTests; this.flakyIssuesManager = managers.flakyIssues; this.labelManager = managers.labels; this.unknownCauseManager = managers.unknownCause; } Report.prototype.report = function (_a) { var _this = this; var _b = _a.dryRun, dryRun = _b === void 0 ? true : _b; console.log(formatMessages.initMessage(dryRun)); return this.bambooClient .fetchFailingBuilds() .then(function (builds) { return __awaiter(_this, void 0, void 0, function () { var buildsWithFailDetails, _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, now; return __generator(this, function (_s) { switch (_s.label) { case 0: console.log(formatMessages.failedBuildsCountMessage(builds)); buildsWithFailDetails = []; _b = // Errors (_a = buildsWithFailDetails.push).apply; _c = [ // Errors buildsWithFailDetails]; return [4 /*yield*/, this.labelManager.assembleBuildsWithErrorInLabels(builds)]; case 1: // Errors _b.apply(_a, _c.concat([_s.sent()])); _e = (_d = buildsWithFailDetails.push).apply; _f = [buildsWithFailDetails]; return [4 /*yield*/, this.commentsManager.assembleBuildsWithErrorInComments(builds .filter(function (build) { return !buildsWithFailDetails.some(function (b) { return b.build.planKey === build.planKey; }); }))]; case 2: _e.apply(_d, _f.concat([_s.sent()])); _h = // Failing tests (_g = buildsWithFailDetails.push).apply; _j = [ // Failing tests buildsWithFailDetails]; return [4 /*yield*/, this.failingTestsManager.assembleBuildsWithFailingTests(builds .filter(function (build) { return build.failedTestCount; }) .filter(function (build) { return !buildsWithFailDetails.some(function (b) { return b.build.planKey === build.planKey; }); }))]; case 3: // Failing tests _h.apply(_g, _j.concat([_s.sent()])); _l = // Unknown causes (_k = buildsWithFailDetails.push).apply; _m = [ // Unknown causes buildsWithFailDetails]; return [4 /*yield*/, this.unknownCauseManager.assembleBuildsWithUnknownFailCause(builds .filter(function (build) { return !buildsWithFailDetails.some(function (b) { return b.build.planKey === build.planKey; }); }))]; case 4: // Unknown causes _l.apply(_k, _m.concat([_s.sent()])); _p = (_o = console).log; return [4 /*yield*/, formatMessages.failCategoriesCountMessage(buildsWithFailDetails)]; case 5: _p.apply(_o, [_s.sent()]); _r = (_q = console).log; return [4 /*yield*/, formatMessages.formatDetailsTable(buildsWithFailDetails)]; case 6: _r.apply(_q, [_s.sent()]); now = new Date(); (!dryRun && this.updateIssues(buildsWithFailDetails, now)); (!dryRun && this.saveExecution(buildsWithFailDetails, now)); (!dryRun && this.saveStatistics(buildsWithFailDetails)); return [2 /*return*/, buildsWithFailDetails]; } }); }); }); }; Report.prototype.summary = function (failReasons) { return { total: failReasons.length, reasonsCount: Object.entries(failReasons .reduce(function (acc, reason) { return Object.assign(acc, (_a = {}, _a[reason] = (acc[reason] || 0) + 1, _a)); var _a; }, {})).map(function (entry) { return ({ reason: entry[0], count: entry[1] }); }) }; }; Report.prototype.updateIssues = function (buildsWithFailDetails, date) { return __awaiter(this, void 0, void 0, function () { var _this = this; var buildsdWithIssuesToUpdate; return __generator(this, function (_a) { buildsdWithIssuesToUpdate = buildsWithFailDetails .filter(function (b) { return b.failReason === fail_categories_1.categories.failingTest && b.failingTests[0] && b.failingTests[0].issue; }) .filter(function (_a) { var build = _a.build; return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, this.executionStore.fetchFailingBuild(date, build.planKey, build.resultNumber)]; case 1: return [2 /*return*/, !(_b.sent()).issue]; } }); }); }); return [2 /*return*/, BluebirdPromise .map(buildsdWithIssuesToUpdate, function (b) { return _this.flakyIssuesManager.updateFlakyIssue({ failingBuild: b.build, failingTest: b.failingTests[0].test, issue: b.failingTests[0].issue }); }) .tap(function (flakyIssues) { return console.log("Updated " + flakyIssues.length + " Flaky test Jira tickets."); }) .then(function (flakyIssues) { return flakyIssues.length; })]; }); }); }; Report.prototype.saveExecution = function (buildsWithFailDetails, date) { var _this = this; return BluebirdPromise .map(buildsWithFailDetails, function (b) { _this.executionStore.addExecution({ build: b.build, issue: b.failingTests && b.failingTests[0].issue ? b.failingTests[0].issue.key : null, failReason: b.failReason, failDetails: b.failDetails || null, }, date); }) .then(function () { return console.log('Execution state saved'); }); }; Report.prototype.saveStatistics = function (buildsWithFailDetails) { var _this = this; return BluebirdPromise .map(buildsWithFailDetails, function (b) { _this.statisticsStore.addToTimeSeries(b); _this.statisticsStore.addToBuildFailCount(b); }) .then(function () { return console.log('Statistics saved for failing builds'); }); }; return Report; }()); exports.Report = Report; //# sourceMappingURL=report.js.map