Skip to content

Commit

Permalink
fix: Only add template info and prNum to executor start if it exists (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi authored Oct 27, 2023
1 parent 6246053 commit d37365a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
34 changes: 24 additions & 10 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class BuildModel extends BaseModel {
async start(startConfig = {}) {
const { causeMessage } = startConfig;

let template = {};
const template = {};

// Get template info
if (this.templateId) {
Expand All @@ -502,13 +502,21 @@ class BuildModel extends BaseModel {

const { id, name, namespace, version } = await templateFactory.get(this.templateId);

template = {
id,
fullName: `${namespace}/${name}`,
name,
namespace,
version
};
if (id) {
template.id = id;
}
if (name) {
template.name = name;
}
if (namespace) {
template.namespace = namespace;
}
if (namespace && name) {
template.fullName = `${namespace}/${name}`;
}
if (version) {
template.version = version;
}
}

// Make sure that a pipeline and job is associated with the build
Expand All @@ -534,18 +542,24 @@ class BuildModel extends BaseModel {
scmContext: pipeline.scmContext,
configPipelineId: pipeline.configPipelineId
},
template,
causeMessage: causeMessage || '',
freezeWindows: hoek.reach(job.permutations[0], 'freezeWindows', { default: [] }),
apiUri: this[apiUri],
container: this.container,
tokenGen: this[tokenGen],
token: getToken(this, job, pipeline),
isPR: job.isPR(),
prNum,
prParentJobId: job.prParentJobId
};

if (template && !hoek.deepEqual(template, {})) {
config.template = template;
}

if (prNum) {
config.prNum = prNum;
}

if (this.buildClusterName) {
config.buildClusterName = this.buildClusterName;
}
Expand Down
8 changes: 2 additions & 6 deletions test/lib/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ describe('Build Model', () => {
templateMock = {
id: 8888,
name: 'docker',
namespace: 'sd',
version: '1.0.0'
namespace: 'sd'
};
tokenGen = sinon.stub().returns(token);
const uF = {
Expand Down Expand Up @@ -1179,8 +1178,6 @@ describe('Build Model', () => {
tokenGen,
pipelineId,
isPR: false,
prNum: null,
template: {},
prParentJobId
};
expectedUpdateCommitStatusConfig = {
Expand Down Expand Up @@ -1229,8 +1226,7 @@ describe('Build Model', () => {
id: templateMock.id,
fullName: `${templateMock.namespace}/${templateMock.name}`,
name: templateMock.name,
namespace: templateMock.namespace,
version: templateMock.version
namespace: templateMock.namespace
};

return build.start().then(() => {
Expand Down

0 comments on commit d37365a

Please sign in to comment.