Skip to content

Commit 9147ea3

Browse files
authored
fix(3438): Job that trigger on tags are not triggering when tags are pushed from SD builds (#3439)
1 parent e86866b commit 9147ea3

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

plugins/webhooks/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ async function startHookEvent(request, h, webhookConfig) {
14211421
}
14221422

14231423
// if skip ci then don't return
1424-
if (ignoreUser && ignoreUser.length !== 0 && !skipMessage) {
1424+
if (action !== 'tag' && action !== 'release' && ignoreUser && ignoreUser.length !== 0 && !skipMessage) {
14251425
const commitAuthors =
14261426
Array.isArray(webhookConfig.commitAuthors) && webhookConfig.commitAuthors.length !== 0
14271427
? webhookConfig.commitAuthors

test/plugins/webhooks.helper.test.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,55 @@ describe('startHookEvent test', () => {
584584
});
585585
});
586586

587+
it('returns 201 on success when tag is created by an ignored user', () => {
588+
parsed.username = 'batman';
589+
590+
const tagWorkflowMock = {
591+
nodes: [{ name: '~tag' }, { name: 'main' }],
592+
edges: [{ src: '~tag', dest: 'main' }]
593+
};
594+
595+
pipelineMock.workflowGraph = tagWorkflowMock;
596+
pipelineMock.jobs = Promise.resolve([mainJobMock]);
597+
598+
return startHookEvent(request, responseHandler, parsed).then(reply => {
599+
assert.equal(reply.statusCode, 201);
600+
assert.calledOnce(pipelineFactoryMock.scm.getCommitRefSha);
601+
assert.calledWith(pipelineFactoryMock.scm.getCommitRefSha, sinon.match({ refType: 'tags' }));
602+
assert.calledTwice(pipelineFactoryMock.list);
603+
assert.calledWith(pipelineFactoryMock.list.firstCall, {
604+
params: { state: 'ACTIVE' },
605+
search: { field: 'scmUri', keyword: 'github.com:123456:%' }
606+
});
607+
assert.calledWith(pipelineFactoryMock.list.secondCall, {
608+
params: { state: 'ACTIVE' },
609+
search: { field: 'subscribedScmUrlsWithActions', keyword: '%github.com:123456:%' }
610+
});
611+
assert.calledWith(eventFactoryMock.create, {
612+
pipelineId: pipelineMock.id,
613+
type: 'pipeline',
614+
webhooks: true,
615+
username: parsed.username,
616+
scmContext,
617+
sha,
618+
configPipelineSha: latestSha,
619+
startFrom: '~tag',
620+
baseBranch: 'master',
621+
causeMessage: `Merged by ${parsed.username}`,
622+
changedFiles: undefined,
623+
ref: 'v0.0.1',
624+
releaseName: undefined,
625+
meta: {
626+
sd: {
627+
tag: {
628+
name: 'v0.0.1'
629+
}
630+
}
631+
}
632+
});
633+
});
634+
});
635+
587636
it('returns 201 on success on a regular expression', () => {
588637
const tagWorkflowMock1 = {
589638
nodes: [{ name: '~tag:/^tag-test-/' }, { name: 'main' }],
@@ -910,6 +959,52 @@ describe('startHookEvent test', () => {
910959
});
911960
});
912961

962+
it('returns 201 on success', () => {
963+
parsed.username = 'batman';
964+
965+
const releaseWorkflowMock = {
966+
nodes: [{ name: '~release' }, { name: 'main' }],
967+
edges: [{ src: '~release', dest: 'main' }]
968+
};
969+
970+
pipelineMock.workflowGraph = releaseWorkflowMock;
971+
pipelineMock.jobs = Promise.resolve([mainJobMock]);
972+
pipelineFactoryMock.list.resolves([pipelineMock]);
973+
974+
return startHookEvent(request, responseHandler, parsed).then(reply => {
975+
assert.equal(reply.statusCode, 201);
976+
assert.calledOnce(pipelineFactoryMock.scm.getCommitRefSha);
977+
assert.calledWith(pipelineFactoryMock.scm.getCommitRefSha, sinon.match({ refType: 'tags' }));
978+
assert.calledWith(eventFactoryMock.create, {
979+
pipelineId: pipelineMock.id,
980+
type: 'pipeline',
981+
webhooks: true,
982+
username: parsed.username,
983+
scmContext,
984+
sha,
985+
configPipelineSha: latestSha,
986+
startFrom: '~release',
987+
baseBranch: 'master',
988+
causeMessage: `Merged by ${parsed.username}`,
989+
changedFiles: undefined,
990+
releaseName: 'release01',
991+
ref: 'v0.0.1',
992+
meta: {
993+
sd: {
994+
release: {
995+
id: 123456,
996+
name: 'release01',
997+
author: 'testuser'
998+
},
999+
tag: {
1000+
name: 'v0.0.1'
1001+
}
1002+
}
1003+
}
1004+
});
1005+
});
1006+
});
1007+
9131008
it('returns 201 on success on a regular expression', () => {
9141009
const releaseWorkflowMock1 = {
9151010
nodes: [{ name: '~release:/^release-test-/' }, { name: 'main' }],

0 commit comments

Comments
 (0)