Skip to content

Commit

Permalink
feat: add badges to pipeline update PUT api
Browse files Browse the repository at this point in the history
  • Loading branch information
adong committed Oct 24, 2023
1 parent 10b3a7c commit 9a75660
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugins/pipelines/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = () => ({
},

handler: async (request, h) => {
const { checkoutUrl, rootDir, settings } = request.payload;
const { checkoutUrl, rootDir, settings, badges } = request.payload;
const { id } = request.params;
const { pipelineFactory, userFactory, secretFactory } = request.server.app;
const { scmContext, username } = request.auth.credentials;
Expand Down Expand Up @@ -146,6 +146,10 @@ module.exports = () => ({
);
}

if (badges) {
oldPipeline.badges = { ...oldPipeline.badges, ...badges };
}

// update pipeline
const updatedPipeline = await oldPipeline.update();

Expand Down
16 changes: 16 additions & 0 deletions test/plugins/pipelines.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,22 @@ describe('pipeline plugin test', () => {
});
});

it('returns 200 when update the pipeline for sonar badges', () => {
options.payload.badges = {
sonar: {
name: 'my-sonar-dashboard',
uri: 'https://sonar.screwdriver.cd/pipeline112233'
}
};

return server.inject(options).then(reply => {
assert.calledOnce(pipelineMock.update);
assert.include(reply.payload, 'my-sonar-dashboard');
assert.include(reply.payload, 'https://sonar.screwdriver.cd/pipeline112233');
assert.equal(reply.statusCode, 200);
});
});

it('returns 404 when the pipeline id is not found', () => {
pipelineFactoryMock.get.withArgs({ id }).resolves(null);

Expand Down

0 comments on commit 9a75660

Please sign in to comment.