Skip to content

Commit

Permalink
Merge pull request #165 from screwdriver-cd/fullTemplateName
Browse files Browse the repository at this point in the history
fix(616): Update full template name
  • Loading branch information
ian-fox authored Jul 21, 2017
2 parents c1412e3 + cac374c commit 9f99afd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
11 changes: 8 additions & 3 deletions config/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ module.exports = {
// Template tags must start with an alpha character (A-Z,a-z) and can only contain A-Z,a-z,0-9,-,_
TEMPLATE_TAG_NAME: /^[a-zA-Z][\w-]+$/,
// Version can only have up to 2 decimals, like 1.2.3
VERSION: /^(\d+)?(\.\d+)?(\.\d+)?$/,
// Full name of template and version. Example: chef/publish@1.2.3 or chef/publish@1-stable
FULL_TEMPLATE_NAME: /^([\w/-]+)(@)?((\d+)?(\.\d+)?(\.\d+)?)(-[\w]+)?$/,
// It can also be just major or major and minor versions, like 1 or 1.2
VERSION: /^(\d+)+(\.\d+)?(\.\d+)?$/,
// Exact version should contain the major, minor, and patch versions, e.g. 1.2.3
EXACT_VERSION: /^(\d+)+(\.\d+)+(\.\d+)+$/,
// Full name of template and version. Can be <TEMPLATE_NAME>@<VERSION> or <TEMPLATE_NAME>@<TEMPLATE_TAG_NAME>
// Example: chef/publish@1.2.3 or chef/publish@stable
// Only <TEMPLATE_NAME> or <TEMPLATE_NAME>@ is also acceptable
FULL_TEMPLATE_NAME: /^([\w/-]+)(@(((\d+)+(\.\d+)?(\.\d+)?)|([a-zA-Z][\w-]+))?)?$/,
// 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,-,_
Expand Down
8 changes: 8 additions & 0 deletions config/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ const TEMPLATE_VERSION = Joi
.regex(Regex.VERSION)
.max(16)
.description('Version of the Template')
.example('1.2');

const TEMPLATE_EXACT_VERSION = Joi
.string()
.regex(Regex.EXACT_VERSION)
.max(16)
.description('Exact version of the Template')
.example('1.2.3');

const TEMPLATE_DESCRIPTION = Joi
Expand Down Expand Up @@ -58,6 +65,7 @@ module.exports = {
name: TEMPLATE_NAME,
templateTag: TEMPLATE_TAG_NAME,
version: TEMPLATE_VERSION,
exactVersion: TEMPLATE_EXACT_VERSION,
description: TEMPLATE_DESCRIPTION,
maintainer: TEMPLATE_MAINTAINER,
config: Job.job
Expand Down
2 changes: 1 addition & 1 deletion models/templateTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const MODEL = {
.example(123345),
name: Template.name,
tag: Template.templateTag,
version: Template.version
version: Template.exactVersion
};

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion test/config/job.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('config job', () => {
describe('template', () => {
it('validates good template', () => {
assert.isNull(validate('config.job.template.good.yaml', config.job.job).error);
assert.isNull(validate('config.job.template-with-label.good.yaml',
assert.isNull(validate('config.job.template-with-tag.good.yaml',
config.job.job).error);
});

Expand Down
1 change: 0 additions & 1 deletion test/data/config.job.template-with-label.good.yaml

This file was deleted.

1 change: 1 addition & 0 deletions test/data/config.job.template-with-tag.good.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
template: node/build@1.2
2 changes: 1 addition & 1 deletion test/data/config.job.template.good.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
template: node/build@1.2.3
template: node/build@1.2
environment:
NODE_ENV: production

0 comments on commit 9f99afd

Please sign in to comment.