screwdriver-api 7.0.8 → 7.0.10

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": "7.0.8",
3
+ "version": "7.0.10",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -454,7 +454,7 @@ async function updateParentBuilds({ joinParentBuilds, nextBuild, build }) {
454
454
  );
455
455
 
456
456
  nextBuild.parentBuilds = newParentBuilds;
457
- nextBuild.parentBuildId = [build.id].concat(nextBuild.parentBuildId || []);
457
+ nextBuild.parentBuildId = Array.from(new Set([build.id, ...(nextBuild.parentBuildId || [])]));
458
458
 
459
459
  // FIXME: Is this needed ? Why not update once in handleNewBuild()
460
460
  return nextBuild.update();
@@ -683,6 +683,31 @@ async function createJoinObject(nextJobs, current, eventFactory) {
683
683
  return joinObj;
684
684
  }
685
685
 
686
+ /**
687
+ * Get parentBuildId from parentBuilds object
688
+ * @param {Object} parentBuilds Builds that triggered this build
689
+ * @param {Array} joinListNames Array of join job name
690
+ * @param {Number} pipelineId Pipeline ID
691
+ * @return {Array} Array of parentBuildId
692
+ */
693
+ function getParentBuildIds({ currentBuildId, parentBuilds, joinListNames, pipelineId }) {
694
+ const parentBuildIds = [];
695
+
696
+ for (let i = 0; i < joinListNames.length; i += 1) {
697
+ const name = joinListNames[i];
698
+ const joinInfo = getPipelineAndJob(name, pipelineId);
699
+
700
+ if (
701
+ parentBuilds[joinInfo.externalPipelineId] &&
702
+ parentBuilds[joinInfo.externalPipelineId].jobs[joinInfo.externalJobName]
703
+ ) {
704
+ parentBuildIds.push(parentBuilds[joinInfo.externalPipelineId].jobs[joinInfo.externalJobName]);
705
+ }
706
+ }
707
+
708
+ return Array.from(new Set([currentBuildId, ...parentBuildIds]));
709
+ }
710
+
686
711
  /**
687
712
  * Build API Plugin
688
713
  * @method register
@@ -946,7 +971,8 @@ const buildsPlugin = {
946
971
 
947
972
  return existingBuild &&
948
973
  existingBuild.status !== 'CREATED' &&
949
- !existingBuild.parentBuildId.includes(current.build.id)
974
+ !existingBuild.parentBuildId.includes(current.build.id) &&
975
+ existingBuild.eventId !== current.event.parentEventId
950
976
  ? existingBuild
951
977
  : null;
952
978
  })
@@ -1004,6 +1030,9 @@ const buildsPlugin = {
1004
1030
 
1005
1031
  fillParentBuilds(parentBuilds, current, externalGroupBuilds, externalEvent);
1006
1032
 
1033
+ const joinList = nextJobs[nextJobName].join;
1034
+ const joinListNames = joinList.map(j => j.name);
1035
+
1007
1036
  if (nextBuild) {
1008
1037
  // update current build info in parentBuilds
1009
1038
  // nextBuild is not build model, so fetch proper build
@@ -1015,6 +1044,13 @@ const buildsPlugin = {
1015
1044
  } else {
1016
1045
  // no existing build, so first time processing this job
1017
1046
  // in the external pipeline's event
1047
+ const parentBuildId = getParentBuildIds({
1048
+ currentBuildId: current.build.id,
1049
+ parentBuilds,
1050
+ joinListNames,
1051
+ pipelineId: externalPipelineId
1052
+ });
1053
+
1018
1054
  newBuild = await createInternalBuild({
1019
1055
  jobFactory,
1020
1056
  buildFactory,
@@ -1026,15 +1062,14 @@ const buildsPlugin = {
1026
1062
  event: externalEvent, // this is the parentBuild for the next build
1027
1063
  baseBranch: externalEvent.baseBranch || null,
1028
1064
  parentBuilds,
1029
- parentBuildId: current.build.id,
1065
+ parentBuildId,
1030
1066
  start: false
1031
1067
  });
1032
1068
  }
1033
1069
 
1034
- const joinList = nextJobs[nextJobName].join;
1035
1070
  const { hasFailure, done } = await getParentBuildStatus({
1036
1071
  newBuild,
1037
- joinListNames: joinList.map(j => j.name),
1072
+ joinListNames,
1038
1073
  pipelineId: externalPipelineId,
1039
1074
  buildFactory
1040
1075
  });