Skip to content

Commit

Permalink
fix: add displayName (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
wahapo committed Oct 14, 2020
1 parent 2b78547 commit c476f2b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/getWorkflow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const hoek = require('@hapi/hoek');

/**
* Remove the ~ prefix for logical OR on select node names.
* @method filterNodeName
Expand Down Expand Up @@ -75,7 +77,20 @@ const calculateNodes = async (jobs, triggerFactory, pipelineId) => {
externalDownstreamAnd, nodes, triggerFactory);
}));

return [...nodes].map(name => ({ name }));
return [...nodes].map((name) => {
const m = { name };
const displayName = hoek.reach(
jobs[name],
'annotations>screwdriver.cd/displayName',
{ separator: '>', default: undefined }
);

if (displayName !== undefined) {
m.displayName = displayName;
}

return m;
});
};

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"sinon": "^7.5.0"
},
"dependencies": {
"@hapi/hoek": "^9.1.0",
"screwdriver-data-schema": "^20.0.0"
},
"release": {
Expand Down
23 changes: 23 additions & 0 deletions test/lib/getWorkflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ describe('getWorkflow', () => {
assert.deepEqual(external, EXPECTED_EXTERNAL);
});

it('should handle displayName', async () => {
const result = await getWorkflow({
jobs: {
foo: {
annotations: {
'screwdriver.cd/displayName': 'baz'
}
},
bar: {}
}
}, triggerFactoryMock);

assert.deepEqual(result, {
nodes: [
{ name: '~pr' },
{ name: '~commit' },
{ name: 'foo', displayName: 'baz' },
{ name: 'bar' }
],
edges: []
});
});

it('should handle detatched jobs', async () => {
const result = await getWorkflow({
jobs: {
Expand Down

0 comments on commit c476f2b

Please sign in to comment.