Skip to content

Commit

Permalink
feat(1769): Add property to SCHEMA_HOOK (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
yk634 authored Jan 3, 2022
1 parent 2f607cd commit 60e1e1e
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 4 deletions.
17 changes: 16 additions & 1 deletion core/scm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion plugins/scm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions test/core/scm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion test/data/scm.getChangedFilesInput.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
payload:
webhookConfig:
ref: 'refs/heads/master'
before: '9049f1265b7d61be4a8904a9a27120d2064dab3b'
after: '0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c'
Expand Down
14 changes: 14 additions & 0 deletions test/data/scm.hook.push.invalid-added-files.yaml
Original file line number Diff line number Diff line change
@@ -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']
14 changes: 14 additions & 0 deletions test/data/scm.hook.push.invalid-modified-files.yaml
Original file line number Diff line number Diff line change
@@ -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']
14 changes: 14 additions & 0 deletions test/data/scm.hook.push.invalid-removed-files.yaml
Original file line number Diff line number Diff line change
@@ -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'
5 changes: 4 additions & 1 deletion test/data/scm.hook.push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ sha: ccc49349d3cffbd12ea9e3d41521480b4aa5de5f
type: repo
username: stjohnjohnson
ref: reference
commitAuthors: ['john1', 'john2']
commitAuthors: ['john1', 'john2']
addedFiles: ['README.md']
modifiedFiles: ['README.md','package.json']
removedFiles: ['screwdriver.yaml']

0 comments on commit 60e1e1e

Please sign in to comment.