screwdriver-api 8.0.98 → 8.0.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "8.0.98",
3
+ "version": "8.0.99",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -6,7 +6,7 @@ const merge = require('lodash.mergewith');
6
6
  const isEmpty = require('lodash.isempty');
7
7
  const { PR_JOB_NAME, PR_STAGE_NAME, STAGE_TEARDOWN_PATTERN } = require('screwdriver-data-schema').config.regex;
8
8
  const { getFullStageJobName } = require('../../helper');
9
- const { updateVirtualBuildSuccess, emitBuildStatusEvent } = require('../triggers/helpers');
9
+ const { updateVirtualBuildSuccess, emitBuildStatusEvent, isFixedBuild } = require('../triggers/helpers');
10
10
  const TERMINAL_STATUSES = ['FAILURE', 'ABORTED', 'UNSTABLE', 'COLLAPSED'];
11
11
  const FINISHED_STATUSES = ['SUCCESS', ...TERMINAL_STATUSES];
12
12
  const NON_TERMINATED_STATUSES = ['CREATED', 'RUNNING', 'QUEUED', 'BLOCKED', 'FROZEN'];
@@ -412,12 +412,14 @@ async function updateBuildAndTriggerDownstreamJobs(config, build, server, userna
412
412
  stopFrozen = stopFrozenBuild(build, currentStatus);
413
413
  }
414
414
 
415
- const [newBuild, newEvent] = await Promise.all([build.update(), event.update(), stopFrozen]);
416
- const job = await newBuild.job;
415
+ const job = await build.job;
417
416
  const pipeline = await job.pipeline;
417
+ const isFixed = await isFixedBuild({ build, job });
418
+
419
+ const [newBuild, newEvent] = await Promise.all([build.update(), event.update(), stopFrozen]);
418
420
 
419
421
  if (desiredStatus) {
420
- await emitBuildStatusEvent({ server, build: newBuild, pipeline, event: newEvent, job });
422
+ await emitBuildStatusEvent({ server, build: newBuild, pipeline, event: newEvent, job, isFixed });
421
423
  }
422
424
 
423
425
  const skipFurther = /\[(skip further)\]/.test(newEvent.causeMessage);
@@ -630,6 +630,27 @@ async function getParentBuildStatus({ joinListNames, joinBuilds }) {
630
630
  return { hasFailure, done };
631
631
  }
632
632
 
633
+ /**
634
+ * Identify whether this build resulted in a previously failed job to become successful.
635
+ *
636
+ * @method isFixedBuild
637
+ * @param {Build} build Build Object
638
+ * @param {Job} job Job Object
639
+ * @return {Promise<Boolean>}
640
+ */
641
+ async function isFixedBuild({ build, job }) {
642
+ if (build.status !== Status.SUCCESS) {
643
+ return false;
644
+ }
645
+
646
+ job = job || (await build.job); // eslint-disable-line no-param-reassign
647
+
648
+ const failureBuild = await job.getLatestBuild({ status: Status.FAILURE });
649
+ const successBuild = await job.getLatestBuild({ status: Status.SUCCESS });
650
+
651
+ return !!((failureBuild && !successBuild) || failureBuild.id > successBuild.id);
652
+ }
653
+
633
654
  /**
634
655
  * Emit 'build_status' event to notify
635
656
  * @param {Object} arg
@@ -640,23 +661,13 @@ async function getParentBuildStatus({ joinListNames, joinBuilds }) {
640
661
  * @param {Job} [arg.job] Job
641
662
  * @returns {Promise}
642
663
  */
643
- async function emitBuildStatusEvent({ server, build, pipeline, event, job }) {
664
+ async function emitBuildStatusEvent({ server, build, pipeline, event, job, isFixed = false }) {
644
665
  const { buildFactory } = server.app;
645
666
 
646
667
  event = event || (await build.event); // eslint-disable-line no-param-reassign
647
668
  job = job || (await build.job); // eslint-disable-line no-param-reassign
648
669
  pipeline = pipeline || (await job.pipeline); // eslint-disable-line no-param-reassign
649
670
 
650
- let isFixed = false;
651
-
652
- if (build.status === Status.SUCCESS) {
653
- const failureBuild = await job.getLatestBuild({ status: Status.FAILURE });
654
- const successBuild = await job.getLatestBuild({ status: Status.SUCCESS });
655
-
656
- // Identify whether this build resulted in a previously failed job to become successful.
657
- isFixed = !!((failureBuild && !successBuild) || failureBuild.id > successBuild.id);
658
- }
659
-
660
671
  return server.events.emit('build_status', {
661
672
  settings: job.permutations[0].settings,
662
673
  status: build.status,
@@ -1282,6 +1293,7 @@ module.exports = {
1282
1293
  getJoinBuilds,
1283
1294
  getParentBuildStatus,
1284
1295
  handleNewBuild,
1296
+ isFixedBuild,
1285
1297
  emitBuildStatusEvent,
1286
1298
  ensureStageTeardownBuildExists,
1287
1299
  getBuildsForGroupEvent,