screwdriver-api 7.0.122 → 7.0.124

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.122",
3
+ "version": "7.0.124",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -93,6 +93,7 @@
93
93
  "js-yaml": "^3.14.1",
94
94
  "jsonwebtoken": "^9.0.0",
95
95
  "license-checker": "^25.0.1",
96
+ "lodash": "^4.17.21",
96
97
  "lodash.mergewith": "^4.6.2",
97
98
  "ndjson": "^2.0.0",
98
99
  "node-env-file": "^0.1.8",
@@ -327,7 +327,6 @@ async function triggeredPipelines(
327
327
  };
328
328
 
329
329
  const pipelines = await pipelineFactory.list(listConfig);
330
-
331
330
  const pipelinesWithSubscribedRepos = await pipelineFactory.list(externalRepoSearchConfig);
332
331
 
333
332
  let pipelinesOnCommitBranch = [];
@@ -365,7 +364,43 @@ async function triggeredPipelines(
365
364
 
366
365
  const currentRepoPipelines = pipelinesOnCommitBranch.concat(pipelinesOnOtherBranch);
367
366
 
368
- return currentRepoPipelines.concat(pipelinesWithSubscribedRepos);
367
+ if (pipelinesOnCommitBranch.length === 0) {
368
+ return currentRepoPipelines;
369
+ }
370
+
371
+ // process the pipelinesWithSubscribedRepos only when the pipelinesOnCommitBranch is not empty
372
+ // pipelinesOnCommitBranch has the information to determine the triggering event of downstream subscribing repo
373
+ pipelinesWithSubscribedRepos.forEach(p => {
374
+ if (!Array.isArray(p.subscribedScmUrlsWithActions)) {
375
+ return;
376
+ }
377
+ p.subscribedScmUrlsWithActions.forEach(subscribedScmUriWithAction => {
378
+ const { scmUri: subscribedScmUri, actions: subscribedActions } = subscribedScmUriWithAction;
379
+
380
+ if (pipelinesOnCommitBranch[0].scmUri === subscribedScmUri) {
381
+ const pipeline = pipelinesOnCommitBranch[0];
382
+ const isReleaseOrTagFiltering = isReleaseOrTagFilteringEnabled(action, pipeline.workflowGraph);
383
+ const startFrom = determineStartFrom(
384
+ action,
385
+ type,
386
+ branch,
387
+ null,
388
+ releaseName,
389
+ tagName,
390
+ isReleaseOrTagFiltering
391
+ );
392
+
393
+ for (const subscribedAction of subscribedActions) {
394
+ if (new RegExp(subscribedAction).test(startFrom)) {
395
+ currentRepoPipelines.push(p);
396
+ break;
397
+ }
398
+ }
399
+ }
400
+ });
401
+ });
402
+
403
+ return currentRepoPipelines;
369
404
  }
370
405
 
371
406
  /**
@@ -445,11 +480,12 @@ async function createPREvents(options, request) {
445
480
  ref,
446
481
  releaseName
447
482
  } = options;
483
+
448
484
  const { scm } = request.server.app.pipelineFactory;
449
485
  const { eventFactory, pipelineFactory, userFactory } = request.server.app;
450
486
  const scmDisplayName = scm.getDisplayName({ scmContext: scmConfig.scmContext });
451
487
  const userDisplayName = `${scmDisplayName}:${username}`;
452
- let { sha } = options;
488
+ const { sha } = options;
453
489
 
454
490
  scmConfig.prNum = prNum;
455
491
 
@@ -462,13 +498,11 @@ async function createPREvents(options, request) {
462
498
  let subscribedConfigSha = '';
463
499
  let eventConfig = {};
464
500
 
465
- // Check if the webhook event is from a subscribed repo and
466
- // and fetch the source repo commit sha and save the subscribed sha
467
501
  if (uriTrimmer(scmConfig.scmUri) !== uriTrimmer(p.scmUri)) {
468
502
  subscribedConfigSha = sha;
469
503
 
470
504
  try {
471
- sha = await pipelineFactory.scm.getCommitSha({
505
+ configPipelineSha = await pipelineFactory.scm.getCommitSha({
472
506
  scmUri: p.scmUri,
473
507
  scmContext: scmConfig.scmContext,
474
508
  token: scmConfig.token
@@ -480,8 +514,6 @@ async function createPREvents(options, request) {
480
514
  logger.info(`skip create event for branch: ${b}`);
481
515
  }
482
516
  }
483
-
484
- configPipelineSha = sha;
485
517
  } else {
486
518
  try {
487
519
  configPipelineSha = await pipelineFactory.scm.getCommitSha(scmConfig);
@@ -540,7 +572,7 @@ async function createPREvents(options, request) {
540
572
  username,
541
573
  scmContext: scmConfig.scmContext,
542
574
  startFrom: '~subscribe',
543
- sha,
575
+ sha: configPipelineSha,
544
576
  configPipelineSha,
545
577
  changedFiles,
546
578
  baseBranch: branch,
@@ -1060,6 +1092,7 @@ async function createEvents(
1060
1092
  async function pushEvent(request, h, parsed, skipMessage, token) {
1061
1093
  const { eventFactory, pipelineFactory, userFactory } = request.server.app;
1062
1094
  const { hookId, checkoutUrl, branch, scmContext, type, action, changedFiles, releaseName, ref } = parsed;
1095
+
1063
1096
  const fullCheckoutUrl = `${checkoutUrl}#${branch}`;
1064
1097
  const scmConfig = {
1065
1098
  scmUri: '',
@@ -1087,6 +1120,7 @@ async function pushEvent(request, h, parsed, skipMessage, token) {
1087
1120
  releaseName,
1088
1121
  ref
1089
1122
  );
1123
+
1090
1124
  let events = [];
1091
1125
 
1092
1126
  if (!pipelines || pipelines.length === 0) {