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(3112): Add support to start an event from a stage #569

Merged
merged 1 commit into from
Jul 4, 2024
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
2 changes: 2 additions & 0 deletions config/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module.exports = {
INTERNAL_TRIGGER: /^~([\w-]+)$/,
// Stages can only be named with A-Z,a-z,0-9,-,_
STAGE_NAME: /^[\w-]+$/,
// Stage name prefixed with @stage. Ex: stage@prod
QUALIFIED_STAGE_NAME: /^stage@([\w-]+)$/,
// Stage trigger like ~stage@deploy or ~stage@stageName:jobName or stage@deploy or stage@stageName:jobName
STAGE_TRIGGER: /^~?stage@([\w-]+)(?::([\w-]+))?$/,
// Don't combine EXTERNAL_TRIGGER and EXTERNAL_TRIGGER_AND for backward compatibility
Expand Down
3 changes: 2 additions & 1 deletion models/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const parentBuildId = require('./build').get.extract('parentBuildId');
const parentBuilds = require('./build').get.extract('parentBuilds');
const buildId = require('./build').get.extract('id');
const prNum = Scm.hook.extract('prNum');
const { QUALIFIED_STAGE_NAME } = require('../config/regex');

const MODEL = {
id: Joi.number().integer().positive().description('Identifier of this event').example(123345),
Expand Down Expand Up @@ -48,7 +49,7 @@ const MODEL = {
.description('SHA of the configuration pipeline this project depends on')
.example('ccc49349d3cffbd12ea9e3d41521480b4aa5de5f'),
startFrom: Joi.alternatives()
.try(trigger, jobName)
.try(trigger, jobName, QUALIFIED_STAGE_NAME)
.description('Event start point - a job name or trigger name (~commit/~pr)')
.example('~commit'),
type: Joi.string().valid('pr', 'pipeline').max(10).description('Type of the event').example('pr'),
Expand Down
31 changes: 30 additions & 1 deletion test/models/event.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,37 @@ const { validate } = require('../helper');

describe('model event', () => {
describe('base', () => {
const schema = models.event.base;
const baseYamlFile = 'event.yaml';

it('validates the base', () => {
assert.isNull(validate('event.yaml', models.event.base).error);
assert.isNull(validate(baseYamlFile, schema).error);
});

describe('tests for startFrom', () => {
[null, '', '~some-internal-job-name', '~stage@integration', '~stage@integration:setup'].forEach(
startFrom => {
it('validates the invalid startFrom', () => {
assert.isNotNull(validate(baseYamlFile, schema, { startFrom }).error);
});
}
);

[
'~commit',
'~pr',
'~tag',
'~release',
'some-internal-job-name',
'stage@integration',
'stage@integration:setup',
'sd@123:some-external-job-name',
'~sd@123:some-external-job-name'
].forEach(startFrom => {
it('validates the valid startFrom', () => {
assert.isNull(validate(baseYamlFile, schema, { startFrom }).error);
});
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/models/templatetag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ describe('model template tag', () => {
});

[null, '', 'some_invalid_type', 'JOBS', 'PIPELINES'].forEach(validType => {
it('validates the invalid states', () => {
it('validates the invalid types', () => {
assert.isNotNull(
validate('templatetag.yaml', models.templateTag.base, { templateType: validType }).error
);
});
});

['JOB', 'PIPELINE'].forEach(validType => {
it('validates the valid states', () => {
it('validates the valid types', () => {
assert.isNull(validate('templatetag.yaml', models.templateTag.base, { templateType: validType }).error);
});
});
Expand Down