diff --git a/core/scm.js b/core/scm.js index 980475b6..b8e93b55 100644 --- a/core/scm.js +++ b/core/scm.js @@ -251,7 +251,22 @@ const SCHEMA_HOOK = Joi.object() releaseAuthor: Joi.string() .allow('') .optional() - .label('Author of the event') + .label('Author of the event'), + + addedFiles: Joi.array() + .items(Joi.string().allow('')) + .optional() + .label('Added files of head commit'), + + modifiedFiles: Joi.array() + .items(Joi.string().allow('')) + .optional() + .label('Modified files of head commit'), + + removedFiles: Joi.array() + .items(Joi.string().allow('')) + .optional() + .label('Removed files of head commit') }) .label('SCM Hook'); diff --git a/plugins/scm.js b/plugins/scm.js index d2784c1d..5b03f743 100644 --- a/plugins/scm.js +++ b/plugins/scm.js @@ -154,7 +154,7 @@ const GET_FILE = Joi.object() const GET_CHANGED_FILES_INPUT = Joi.object() .keys({ type, - payload: Joi.object() + webhookConfig: Joi.object() .allow(null) .required(), token, diff --git a/test/core/scm.test.js b/test/core/scm.test.js index 88f8c83c..cf1b2bb8 100644 --- a/test/core/scm.test.js +++ b/test/core/scm.test.js @@ -72,6 +72,18 @@ describe('scm core', () => { assert.isNotNull(validate('scm.hook.push.invalid-array.yaml', core.scm.hook).error); }); + it('fails the push hook because added files is not an array of string', () => { + assert.isNotNull(validate('scm.hook.push.invalid-added-files.yaml', core.scm.hook).error); + }); + + it('fails the push hook because modified files is not an array of string', () => { + assert.isNotNull(validate('scm.hook.push.invalid-modified-files.yaml', core.scm.hook).error); + }); + + it('fails the push hook because removed files is not an array of string', () => { + assert.isNotNull(validate('scm.hook.push.invalid-removed-files.yaml', core.scm.hook).error); + }); + it('validates the ping hook', () => { assert.isNull(validate('scm.hook.ping.yaml', core.scm.hook).error); }); diff --git a/test/data/scm.getChangedFilesInput.yaml b/test/data/scm.getChangedFilesInput.yaml index 006a96b2..0e679108 100644 --- a/test/data/scm.getChangedFilesInput.yaml +++ b/test/data/scm.getChangedFilesInput.yaml @@ -1,4 +1,4 @@ -payload: +webhookConfig: ref: 'refs/heads/master' before: '9049f1265b7d61be4a8904a9a27120d2064dab3b' after: '0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c' diff --git a/test/data/scm.hook.push.invalid-added-files.yaml b/test/data/scm.hook.push.invalid-added-files.yaml new file mode 100644 index 00000000..153cb898 --- /dev/null +++ b/test/data/scm.hook.push.invalid-added-files.yaml @@ -0,0 +1,14 @@ +# # Invalid SCM Hook addedFiles +action: push +branch: master +checkoutUrl: git@github.com:screwdriver-cd/data-model.git#master +hookId: 81e6bd80-9a2c-11e6-939d-beaa5d9adaf3 +scmContext: github:github.com +sha: ccc49349d3cffbd12ea9e3d41521480b4aa5de5f +type: repo +username: stjohnjohnson +ref: reference +commitAuthors: ['john1', 'john2'] +addedFiles: 'README.md' +modifiedFiles: ['README.md','package.json'] +removedFiles: ['screwdriver.yaml'] \ No newline at end of file diff --git a/test/data/scm.hook.push.invalid-modified-files.yaml b/test/data/scm.hook.push.invalid-modified-files.yaml new file mode 100644 index 00000000..dd90b02b --- /dev/null +++ b/test/data/scm.hook.push.invalid-modified-files.yaml @@ -0,0 +1,14 @@ +# # Invalid SCM Hook modifiedFiles +action: push +branch: master +checkoutUrl: git@github.com:screwdriver-cd/data-model.git#master +hookId: 81e6bd80-9a2c-11e6-939d-beaa5d9adaf3 +scmContext: github:github.com +sha: ccc49349d3cffbd12ea9e3d41521480b4aa5de5f +type: repo +username: stjohnjohnson +ref: reference +commitAuthors: ['john1', 'john2'] +addedFiles: ['README.md'] +modifiedFiles: 'README.md' +removedFiles: ['screwdriver.yaml'] \ No newline at end of file diff --git a/test/data/scm.hook.push.invalid-removed-files.yaml b/test/data/scm.hook.push.invalid-removed-files.yaml new file mode 100644 index 00000000..b57ca134 --- /dev/null +++ b/test/data/scm.hook.push.invalid-removed-files.yaml @@ -0,0 +1,14 @@ +# # Invalid SCM Hook removedFiles +action: push +branch: master +checkoutUrl: git@github.com:screwdriver-cd/data-model.git#master +hookId: 81e6bd80-9a2c-11e6-939d-beaa5d9adaf3 +scmContext: github:github.com +sha: ccc49349d3cffbd12ea9e3d41521480b4aa5de5f +type: repo +username: stjohnjohnson +ref: reference +commitAuthors: ['john1', 'john2'] +addedFiles: ['README.md'] +modifiedFiles: ['README.md','package.json'] +removedFiles: 'screwdriver.yaml' \ No newline at end of file diff --git a/test/data/scm.hook.push.yaml b/test/data/scm.hook.push.yaml index 19935a2f..0b726c00 100644 --- a/test/data/scm.hook.push.yaml +++ b/test/data/scm.hook.push.yaml @@ -8,4 +8,7 @@ sha: ccc49349d3cffbd12ea9e3d41521480b4aa5de5f type: repo username: stjohnjohnson ref: reference -commitAuthors: ['john1', 'john2'] \ No newline at end of file +commitAuthors: ['john1', 'john2'] +addedFiles: ['README.md'] +modifiedFiles: ['README.md','package.json'] +removedFiles: ['screwdriver.yaml'] \ No newline at end of file