screwdriver-api 8.0.45 → 8.0.47

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.45",
3
+ "version": "8.0.47",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -344,14 +344,6 @@ async function updateBuildAndTriggerDownstreamJobs(config, build, server, userna
344
344
  }
345
345
 
346
346
  stageBuildHasFailure = TERMINAL_STATUSES.includes(stageBuild.status);
347
-
348
- // Create a stage teardown build
349
- if (!isStageTeardown) {
350
- await createOrUpdateStageTeardownBuild(
351
- { pipeline, job, build, username, scmContext, event, stage },
352
- server.app
353
- );
354
- }
355
347
  }
356
348
 
357
349
  // Guard against triggering non-successful or unstable builds
@@ -371,19 +363,25 @@ async function updateBuildAndTriggerDownstreamJobs(config, build, server, userna
371
363
  // Determine if stage teardown build should start
372
364
  // (if stage teardown build exists, and stageBuild.status is negative,
373
365
  // and there are no active stage builds, and teardown build is not started)
374
- if (stage && FINISHED_STATUSES.includes(newBuild.status)) {
366
+ if (stage && FINISHED_STATUSES.includes(newBuild.status) && !isStageTeardown) {
375
367
  const stageTeardownName = getFullStageJobName({ stageName: stage.name, jobName: 'teardown' });
376
368
  const stageTeardownJob = await jobFactory.get({ pipelineId: pipeline.id, name: stageTeardownName });
377
- const stageTeardownBuild = await buildFactory.get({ eventId: newEvent.id, jobId: stageTeardownJob.id });
369
+ let stageTeardownBuild = await buildFactory.get({ eventId: newEvent.id, jobId: stageTeardownJob.id });
378
370
 
379
371
  // Start stage teardown build if stage is done
380
- if (stageTeardownBuild && stageTeardownBuild.status === 'CREATED') {
372
+ if (!stageTeardownBuild || stageTeardownBuild.status === 'CREATED') {
381
373
  const stageJobBuilds = await getStageJobBuilds({ stage, event: newEvent, jobFactory });
382
374
  const stageIsDone = isStageDone(stageJobBuilds);
383
375
 
384
376
  if (stageIsDone) {
385
377
  const teardownNode = newEvent.workflowGraph.nodes.find(n => n.id === stageTeardownJob.id);
386
378
 
379
+ // Update teardown build
380
+ stageTeardownBuild = await createOrUpdateStageTeardownBuild(
381
+ { pipeline, job, build, username, scmContext, event, stage },
382
+ server.app
383
+ );
384
+
387
385
  stageTeardownBuild.parentBuildId = stageJobBuilds.map(b => b.id);
388
386
 
389
387
  if (teardownNode && teardownNode.virtual) {
@@ -1003,7 +1003,7 @@ async function ensureStageTeardownBuildExists({
1003
1003
 
1004
1004
  // Doesn't exist, create stage teardown job
1005
1005
  if (!existingStageTeardownBuild) {
1006
- await createInternalBuild({
1006
+ return createInternalBuild({
1007
1007
  jobFactory,
1008
1008
  buildFactory,
1009
1009
  pipelineId: current.pipeline.id,
@@ -1016,13 +1016,13 @@ async function ensureStageTeardownBuildExists({
1016
1016
  baseBranch: current.event.baseBranch || null,
1017
1017
  start: false
1018
1018
  });
1019
- } else {
1020
- await updateParentBuilds({
1021
- joinParentBuilds: parentBuilds,
1022
- nextBuild: existingStageTeardownBuild,
1023
- build: current.build
1024
- });
1025
1019
  }
1020
+
1021
+ return updateParentBuilds({
1022
+ joinParentBuilds: parentBuilds,
1023
+ nextBuild: existingStageTeardownBuild,
1024
+ build: current.build
1025
+ });
1026
1026
  }
1027
1027
 
1028
1028
  /**
@@ -47,7 +47,11 @@ function determineStartFrom(action, type, targetBranch, pipelineBranch, releaseN
47
47
  let startFrom;
48
48
 
49
49
  if (type && type === 'pr') {
50
- startFrom = '~pr';
50
+ if (action && action === 'closed') {
51
+ startFrom = '~pr-closed';
52
+ } else {
53
+ startFrom = '~pr';
54
+ }
51
55
  } else {
52
56
  switch (action) {
53
57
  case 'release':
@@ -890,7 +894,9 @@ async function pullRequestClosed(options, request, h) {
890
894
  j.permutations.length > 0 &&
891
895
  j.permutations[0] &&
892
896
  j.permutations[0].requires &&
893
- j.permutations[0].requires.includes('~pr-closed')
897
+ j.permutations[0].requires.some(
898
+ require => require === '~pr-closed' || require.startsWith('~pr-closed:')
899
+ )
894
900
  );
895
901
 
896
902
  prClosedJobs.push(...filteredJobs);