diff --git a/index.js b/index.js index d55c727..d16a97c 100644 --- a/index.js +++ b/index.js @@ -76,7 +76,8 @@ module.exports = function configParser( jobs: Hoek.reach(doc, 'jobs'), childPipelines: Hoek.reach(doc, 'childPipelines', { default: {} }), workflowGraph: Hoek.reach(doc, 'workflowGraph'), - parameters: Hoek.reach(doc, 'parameters') + parameters: Hoek.reach(doc, 'parameters'), + subscribe: Hoek.reach(doc, 'subscribe', { default: {} }) }; if (warnAnnotations.length > 0) { diff --git a/lib/phase/functional.js b/lib/phase/functional.js index 167a882..1c409c7 100644 --- a/lib/phase/functional.js +++ b/lib/phase/functional.js @@ -223,6 +223,15 @@ module.exports = async (flattenedDoc, buildClusterFactory, triggerFactory, pipel // Workflow graph doc.workflowGraph = await generateWorkflowGraph(doc, triggerFactory, pipelineId); + + doc.workflowGraph.nodes.forEach((node) => { + if (node.name === 'subscribe') node.name = '~subscribe'; + }); + + doc.workflowGraph.edges.forEach((edge) => { + if (edge.src === 'subscribe') edge.src = '~subscribe'; + }); + errors = errors.concat(validateWorkflowGraph(doc)); // Check if build cluster annotation is valid diff --git a/test/data/basic-job-with-images.json b/test/data/basic-job-with-images.json index 5b0e61d..75b5e0f 100644 --- a/test/data/basic-job-with-images.json +++ b/test/data/basic-job-with-images.json @@ -64,5 +64,6 @@ "name": "main" } ] - } + }, + "subscribe": {} } diff --git a/test/data/basic-job-with-template-override-steps-teardown.json b/test/data/basic-job-with-template-override-steps-teardown.json index 14f3b41..5c02ecf 100644 --- a/test/data/basic-job-with-template-override-steps-teardown.json +++ b/test/data/basic-job-with-template-override-steps-teardown.json @@ -59,5 +59,6 @@ { "src": "~pr", "dest": "main" }, { "src": "~commit", "dest": "main" } ] - } + }, + "subscribe": {} } diff --git a/test/data/basic-job-with-template-override-steps-template-teardown.json b/test/data/basic-job-with-template-override-steps-template-teardown.json index 9fc82fb..747262b 100644 --- a/test/data/basic-job-with-template-override-steps-template-teardown.json +++ b/test/data/basic-job-with-template-override-steps-template-teardown.json @@ -59,5 +59,6 @@ { "src": "~pr", "dest": "main" }, { "src": "~commit", "dest": "main" } ] - } + }, + "subscribe": {} } diff --git a/test/data/basic-job-with-template-override-steps.json b/test/data/basic-job-with-template-override-steps.json index 7b5997b..42cbd43 100644 --- a/test/data/basic-job-with-template-override-steps.json +++ b/test/data/basic-job-with-template-override-steps.json @@ -55,5 +55,6 @@ { "src": "~pr", "dest": "main" }, { "src": "~commit", "dest": "main" } ] - } + }, + "subscribe": {} } diff --git a/test/data/basic-job-with-template-with-namespace.json b/test/data/basic-job-with-template-with-namespace.json index da7052d..b127ee7 100644 --- a/test/data/basic-job-with-template-with-namespace.json +++ b/test/data/basic-job-with-template-with-namespace.json @@ -68,5 +68,6 @@ { "src": "~commit", "dest": "main" }, { "src": "main", "dest": "publish" } ] - } + }, + "subscribe": {} } diff --git a/test/data/basic-job-with-template-wrapped-steps.json b/test/data/basic-job-with-template-wrapped-steps.json index 7ebad76..d9414d6 100644 --- a/test/data/basic-job-with-template-wrapped-steps.json +++ b/test/data/basic-job-with-template-wrapped-steps.json @@ -54,5 +54,6 @@ { "src": "~pr", "dest": "main" }, { "src": "~commit", "dest": "main" } ] - } + }, + "subscribe": {} } diff --git a/test/data/basic-job-with-template.json b/test/data/basic-job-with-template.json index 2ba3860..6a21be9 100644 --- a/test/data/basic-job-with-template.json +++ b/test/data/basic-job-with-template.json @@ -70,5 +70,6 @@ { "src": "~commit", "dest": "main" }, { "src": "main", "dest": "publish" } ] - } + }, + "subscribe": {} } diff --git a/test/data/basic-shared-project.json b/test/data/basic-shared-project.json index 1e7393c..34714f5 100644 --- a/test/data/basic-shared-project.json +++ b/test/data/basic-shared-project.json @@ -191,5 +191,6 @@ { "src": "~commit", "dest": "main" }, { "src": "main", "dest": "foobar" } ] - } + }, + "subscribe": {} } diff --git a/test/data/build-cluster.json b/test/data/build-cluster.json index 53cee40..fd22c5c 100644 --- a/test/data/build-cluster.json +++ b/test/data/build-cluster.json @@ -77,5 +77,6 @@ { "src": "main", "dest": "test" }, { "src": "test", "dest": "publish" } ] - } + }, + "subscribe": {} } diff --git a/test/data/complex-environment.json b/test/data/complex-environment.json index 3befce9..7e59ba0 100644 --- a/test/data/complex-environment.json +++ b/test/data/complex-environment.json @@ -39,6 +39,8 @@ { "src": "~pr", "dest": "main" }, { "src": "~commit", "dest": "main" } ] - } + }, + "subscribe": {} + } diff --git a/test/data/node-module.json b/test/data/node-module.json index 36193bb..1153401 100644 --- a/test/data/node-module.json +++ b/test/data/node-module.json @@ -120,5 +120,6 @@ { "src": "~commit", "dest": "main" }, { "src": "main", "dest": "publish" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-and-job-annotations.json b/test/data/pipeline-and-job-annotations.json index ec150bb..a1b95d5 100644 --- a/test/data/pipeline-and-job-annotations.json +++ b/test/data/pipeline-and-job-annotations.json @@ -39,5 +39,6 @@ { "src": "~pr", "dest": "main" }, { "src": "~commit", "dest": "main" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-annotations.json b/test/data/pipeline-annotations.json index c413746..31f4213 100644 --- a/test/data/pipeline-annotations.json +++ b/test/data/pipeline-annotations.json @@ -36,5 +36,6 @@ { "src": "~pr", "dest": "main" }, { "src": "~commit", "dest": "main" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-cache-false-job.json b/test/data/pipeline-cache-false-job.json index 4504d92..63e6d32 100644 --- a/test/data/pipeline-cache-false-job.json +++ b/test/data/pipeline-cache-false-job.json @@ -99,5 +99,6 @@ { "src": "main", "dest": "test" }, { "src": "test", "dest": "publish" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-cache.json b/test/data/pipeline-cache.json index ce6ca26..5ec0db1 100644 --- a/test/data/pipeline-cache.json +++ b/test/data/pipeline-cache.json @@ -112,5 +112,6 @@ { "src": "main", "dest": "test" }, { "src": "test", "dest": "publish" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-with-blocked-by.json b/test/data/pipeline-with-blocked-by.json index 488b77a..fc2f71a 100644 --- a/test/data/pipeline-with-blocked-by.json +++ b/test/data/pipeline-with-blocked-by.json @@ -47,5 +47,6 @@ { "src": "~commit", "dest": "test" }, { "src": "~commit", "dest": "echo" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-with-childPipelines.json b/test/data/pipeline-with-childPipelines.json index d92ffdc..f001421 100644 --- a/test/data/pipeline-with-childPipelines.json +++ b/test/data/pipeline-with-childPipelines.json @@ -77,5 +77,6 @@ { "src": "~commit", "dest": "main" }, { "src": "main", "dest": "foobar" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-with-freeze-windows.json b/test/data/pipeline-with-freeze-windows.json index d5b955d..14fbbc6 100644 --- a/test/data/pipeline-with-freeze-windows.json +++ b/test/data/pipeline-with-freeze-windows.json @@ -47,5 +47,6 @@ { "src": "~commit", "dest": "test" }, { "src": "~commit", "dest": "echo" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-with-requires-external.json b/test/data/pipeline-with-requires-external.json index 6f675f0..ecf1c02 100644 --- a/test/data/pipeline-with-requires-external.json +++ b/test/data/pipeline-with-requires-external.json @@ -72,5 +72,6 @@ { "src": "sd@123:B", "dest": "E", "join": true }, { "src": "sd@456:C", "dest": "E", "join": true } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-with-requires.json b/test/data/pipeline-with-requires.json index 1e0bc87..945aba8 100644 --- a/test/data/pipeline-with-requires.json +++ b/test/data/pipeline-with-requires.json @@ -118,5 +118,6 @@ { "src": "foobar", "dest": "test-and", "join": true }, { "src": "main", "dest": "test-and", "join": true } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-with-sourcePaths-string.json b/test/data/pipeline-with-sourcePaths-string.json index bb0119c..1b061aa 100644 --- a/test/data/pipeline-with-sourcePaths-string.json +++ b/test/data/pipeline-with-sourcePaths-string.json @@ -33,5 +33,6 @@ { "src": "~commit", "dest": "component" }, { "src": "~pr", "dest": "component" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-with-sourcePaths.json b/test/data/pipeline-with-sourcePaths.json index 5a9c483..ef5e007 100644 --- a/test/data/pipeline-with-sourcePaths.json +++ b/test/data/pipeline-with-sourcePaths.json @@ -34,5 +34,6 @@ { "src": "~commit", "dest": "component" }, { "src": "~pr", "dest": "component" } ] - } + }, + "subscribe": {} } diff --git a/test/data/pipeline-with-subscribed-scms.json b/test/data/pipeline-with-subscribed-scms.json new file mode 100644 index 0000000..9bc298e --- /dev/null +++ b/test/data/pipeline-with-subscribed-scms.json @@ -0,0 +1,38 @@ +{ + "annotations": {}, + "parameters": {}, + "jobs": { + "main": [ + { + "annotations": {}, + "secrets": [], + "settings": {}, + "environment": {}, + "image": "node:6", + "requires": ["~commit", "~pr", "~subscribe"], + "commands": [ + { + "name": "install", + "command": "npm install" + } + ] + } + ] + }, + "workflowGraph": { + "nodes": [ + { "name": "~pr" }, + { "name": "~commit" }, + { "name": "main" }, + { "name": "~subscribe" } + ], + "edges": [ + { "src": "~commit", "dest": "main" }, + { "src": "~pr", "dest": "main" }, + { "src": "~subscribe", "dest": "main" } + ] + }, + "subscribe": { + "scmUrls": [{"git@github.com:supra08/quickstart-generic.git#master": ["~commit", "~tags", "~release"]}] + } +} \ No newline at end of file diff --git a/test/data/pipeline-with-subscribed-scms.yaml b/test/data/pipeline-with-subscribed-scms.yaml new file mode 100644 index 0000000..1ad76a4 --- /dev/null +++ b/test/data/pipeline-with-subscribed-scms.yaml @@ -0,0 +1,15 @@ +shared: + image: node:6 + +subscribe: + scmUrls: + - git@github.com:supra08/quickstart-generic.git#master: [~commit, ~tags, ~release] + +jobs: + main: + steps: + - install: npm install + requires: + - ~commit + - ~pr + - ~subscribe \ No newline at end of file diff --git a/test/data/shared-annotations.json b/test/data/shared-annotations.json index dcf6648..8e47eeb 100644 --- a/test/data/shared-annotations.json +++ b/test/data/shared-annotations.json @@ -209,5 +209,6 @@ { "src": "~commit", "dest": "main" }, { "src": "main", "dest": "foobar" } ] - } + }, + "subscribe": {} } diff --git a/test/data/shared-job-annotations.json b/test/data/shared-job-annotations.json index 96cd1b9..d78d896 100644 --- a/test/data/shared-job-annotations.json +++ b/test/data/shared-job-annotations.json @@ -36,5 +36,6 @@ { "src": "~pr", "dest": "main" }, { "src": "~commit", "dest": "main" } ] - } + }, + "subscribe": {} } diff --git a/test/index.test.js b/test/index.test.js index f3655d5..265e8ac 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -160,6 +160,15 @@ describe('config parser', () => { /"fakeScmUrl" fails to match the required pattern:/); })); }); + + describe('subscribe', () => { + it('fetches subscribe from the config and adds to parsed doc', + () => parser(loadData('pipeline-with-subscribed-scms.yaml')) + .then((data) => { + assert.deepEqual(data, + JSON.parse(loadData('pipeline-with-subscribed-scms.json'))); + })); + }); }); describe('flatten', () => {