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

fix(1082): [6] add regex validation of commit branch filter. #247

Merged
merged 8 commits into from
Jun 11, 2018

Conversation

wdstar
Copy link
Contributor

@wdstar wdstar commented Jun 1, 2018

Context

SCM Branch-specific jobs

Objective

This PR adds regex validation of commit branch filter (e.g. /^user-.*$/).

References

config/regex.js Outdated
@@ -49,6 +49,8 @@ module.exports = {
// Can be ~pr, ~commit, or ~commit:branchName, or ~sd@123:component
// Note: if you modify this regex, you must modify `sdJoi` definition in the `config/job.js`
TRIGGER: /^~(sd@\d+:[\w-]+|pr|commit(:(.+))?)$/,
// Can be ~commit or ~commit:master
Copy link
Contributor

Choose a reason for hiding this comment

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

~commit:branchName is better.

Copy link
Contributor

@yuichi10 yuichi10 Jun 4, 2018

Choose a reason for hiding this comment

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

Thanks I will fix this comment too

Copy link
Contributor

@yokawara yokawara left a comment

Choose a reason for hiding this comment

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

otherwise LGTM

config/job.js Outdated
name: 'commitBranch',
validate(params, value, state, options) {
const matched = Regex.TRIGGER.exec(value);
const brFilter = matched[3];
Copy link
Member

Choose a reason for hiding this comment

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

It seems to be a magic number.

config/job.js Outdated
validate(params, value, state, options) {
const regexPos = 3;
const matched = Regex.TRIGGER.exec(value);
const brFilter = matched[regexPos];
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also add comments to these parsing.

Copy link
Contributor

@yuichi10 yuichi10 Jun 5, 2018

Choose a reason for hiding this comment

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

Sorry my variable name is not good I will fix the name regexPos to specificBranchPos.
After this correction and see the Regex.TRIGGER, maybe this code give you a sense.

Is this OK?

Copy link
Contributor

Choose a reason for hiding this comment

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

I added comments.

@catto catto changed the title fix(1082): add regex validation of commit branch filter. fix(1082): [6] add regex validation of commit branch filter. Jun 5, 2018
Copy link
Member

@tk3fftk tk3fftk left a comment

Choose a reason for hiding this comment

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

LGTM

config/job.js Outdated
{
name: 'commitBranch',
validate(params, value, state, options) {
const specificBranchPos = 3;
Copy link
Member

@tkyi tkyi Jun 8, 2018

Choose a reason for hiding this comment

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

I think it's more clear this is a constant/hardcoded value if you put it in all caps like https://github.com/screwdriver-cd/executor-k8s-vm/blob/master/index.js#L14

Copy link
Contributor

Choose a reason for hiding this comment

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

I fixed!

Copy link
Member

@tkyi tkyi left a comment

Choose a reason for hiding this comment

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

Small comment, otherwise LGTM 👍

Copy link
Member

@tkyi tkyi left a comment

Choose a reason for hiding this comment

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

👍

@tkyi tkyi merged commit d04199f into screwdriver-cd:master Jun 11, 2018
@tk3fftk tk3fftk deleted the commit-br-regex branch June 12, 2018 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants