Skip to content

Commit 9dc2114

Browse files
Cr 16433 (#796)
* add display option to annotation * bump * wip * trigger * wip * wip * lint * fix typo * trigger * trigger * trigger
1 parent 6dc719d commit 9dc2114

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

lib/interface/cli/commands/annotation/annotation.logic.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,41 @@ class AnnotationLogic {
2222
}
2323

2424
if (_.isArray(labels) && !_.isEmpty(labels)) {
25-
annotations = _.filter(annotations, annotation => labels.includes(annotation.key));
25+
annotations = _.filter(annotations, (annotation) => labels.includes(annotation.key));
2626
}
2727

2828
return annotations;
2929
}
3030

31-
static createAnnotations({ entityId, entityType, labels }) {
31+
static createAnnotations({ entityId, entityType, labels, display }) {
3232
if (!_.isArray(labels)) {
3333
throw new Error('Labels should be an array');
3434
}
3535
if (_.isEmpty(labels)) {
3636
throw new Error('Labels are required for set command');
3737
}
38+
if (display && entityType !== 'workflow') {
39+
throw new Error('display option is supporeted only for workflow annotation');
40+
}
3841

3942
const annotations = AnnotationLogic._parseAnnotations(labels);
40-
return Promise.map(annotations, ({ key, value }) => sdk.annotations.create({ entityId, entityType, key, value }), { concurrency: 1 });
43+
return Promise.map(
44+
annotations,
45+
({ key, value }) => sdk.annotations.create({
46+
entityId,
47+
entityType,
48+
key,
49+
value,
50+
display,
51+
}),
52+
{ concurrency: 1 },
53+
);
4154
}
4255

4356
static deleteAnnotations({ entityId, entityType, labels }) {
4457
if (!_.isEmpty(labels)) {
45-
return Promise.map(labels, key => sdk.annotations.delete({ entityId, entityType, key }), { concurrency: 1 });
58+
return Promise.map(labels, (key) => sdk.annotations.delete({ entityId, entityType, key }), { concurrency: 1 });
4659
}
47-
4860
return sdk.annotations.delete({ entityId, entityType });
4961
}
5062

lib/interface/cli/commands/annotation/create.cmd.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const _ = require('lodash');
21
const Command = require('../../Command');
32
const createRoot = require('../root/create.cmd');
43
const Logic = require('./annotation.logic');
@@ -12,7 +11,7 @@ const command = new Command({
1211
title: 'create',
1312
// weight: 50,
1413
},
15-
builder: yargs => yargs
14+
builder: (yargs) => yargs
1615
.positional('entity-type', {
1716
describe: 'Type of resource for annotation',
1817
required: true,
@@ -25,13 +24,18 @@ const command = new Command({
2524
describe: 'Labels',
2625
required: true,
2726
array: true,
27+
}).option('display', {
28+
describe: 'annotation to display on build',
29+
type: 'string',
2830
})
2931
.example('codefresh create annotation image 2dfacdaad466 coverage=75%', 'Annotate entity with a single label')
30-
.example('codefresh create annotation image 2dfacdaad466 coverage=75% tests_passed=true', 'Annotate entity with multiple labels'),
32+
.example('codefresh create annotation image 2dfacdaad466 coverage=75% tests_passed=true', 'Annotate entity with multiple labels')
33+
// eslint-disable-next-line max-len
34+
.example('codefresh create annotation image 2dfacdaad466 coverage=75% tests_passed=true --display coverage', 'Annotate entity with multiple labels and display selection'),
3135
handler: async (argv) => {
32-
const { entityType, entityId, labels } = argv;
36+
const { entityType, entityId, labels, display } = argv;
3337

34-
await Logic.createAnnotations({ entityId, entityType, labels });
38+
await Logic.createAnnotations({ entityId, entityType, labels, display });
3539
console.log('Annotations was created');
3640
},
3741
});

0 commit comments

Comments
 (0)