Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(1769): [1] Add property to SCHEMA_HOOK #471

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted is used in git command, so I think that it is better to use deleted instead of removed.

https://git-scm.com/docs/git-status#_output

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitHub and GitLab webhook specification treats deleted files as removed, so I think it's better to leave them as removed.

https://docs.github.com/ja/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey, I see. Thank you.

.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']