Skip to content

Commit

Permalink
fix(2767): Relax job name Regex to allow stage setup/teardown jobs (#539
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sagar1312 authored Oct 31, 2023
1 parent b171c83 commit dd4d7fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ module.exports = {
// Steps can only be named with A-Z,a-z,0-9,-,_
STEP_NAME: /^[\w-]+$/,
// Jobs can only be named with A-Z,a-z,0-9,-,_
JOB_NAME: /^[\w-]+$/,
// Also allow stage setup/teardown like stage@stage-name:setup
JOB_NAME: /^(([\w-]+)|(?:stage@([\w-]+):(setup|teardown)))$/,
// PR JOB Name can only be PR-1 or PR-1:main, group1: PR-prNum, group2: jobName
PR_JOB_NAME: /^(PR-\d+)(?::([\w-]+))?$/,
// Match all possible job name
Expand Down
2 changes: 1 addition & 1 deletion models/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MODEL = {
id: Joi.number().integer().positive().description('Identifier of this Job').example(123345),

name: Joi.string()
.regex(/^(PR-[0-9]+:)?[\w-]+$/)
.regex(/^(PR-[0-9]+:)?(([\w-]+)|(?:stage@([\w-]+):(setup|teardown)))$/)
.max(110)
.description('Name of the Job')
.example('main'),
Expand Down
5 changes: 5 additions & 0 deletions test/config/regex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,15 @@ describe('config regex', () => {
describe('jobs', () => {
it('checks good job names', () => {
assert.isTrue(config.regex.JOB_NAME.test('foo-BAR_15'));
assert.isTrue(config.regex.JOB_NAME.test('stage@integration:setup'));
assert.isTrue(config.regex.JOB_NAME.test('stage@production-blue:teardown'));
});

it('fails on bad job names', () => {
assert.isFalse(config.regex.JOB_NAME.test('run all the things'));
assert.isFalse(config.regex.JOB_NAME.test('stage@integration'));
assert.isFalse(config.regex.JOB_NAME.test('stage@integration:deploy'));
assert.isFalse(config.regex.JOB_NAME.test('integration:deploy'));
});

it('checks good PR job names', () => {
Expand Down

0 comments on commit dd4d7fe

Please sign in to comment.