Skip to content

Commit 3f88c46

Browse files
fix annotate image (#333)
* fix annotate image * update version
1 parent 3dd3a0d commit 3f88c46

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable no-use-before-define,object-curly-newline,arrow-body-style */
22

3+
const _ = require('lodash');
4+
const CFError = require('cf-errors');
35
const Promise = require('bluebird');
46
const { sdk } = require('../../../../logic');
57

@@ -11,21 +13,27 @@ class AnnotationLogic {
1113
annotations = await sdk.annotations.list({ entityId, entityType });
1214
} catch (error) {
1315
if (error.statusCode === 404) {
14-
throw new Error('Annotations not found for specified entity');
16+
throw new CFError({
17+
message: `Annotations not found for specified entity: type = ${entityType}; id = ${entityId}`,
18+
cause: error,
19+
});
1520
} else {
1621
throw error;
1722
}
1823
}
1924

20-
if (labels && labels.length) {
21-
annotations = annotations.filter(annotation => labels.includes(annotation.key));
25+
if (_.isArray(labels) && !_.isEmpty(labels)) {
26+
annotations = _.filter(annotations, annotation => labels.includes(annotation.key));
2227
}
2328

2429
return annotations;
2530
}
2631

2732
static createAnnotations({ entityId, entityType, labels }) {
28-
if (!labels || !labels.length) {
33+
if (!_.isArray(labels)) {
34+
throw new Error('Labels should be an array');
35+
}
36+
if (_.isEmpty(labels)) {
2937
throw new Error('Labels are required for set command');
3038
}
3139

@@ -34,15 +42,15 @@ class AnnotationLogic {
3442
}
3543

3644
static deleteAnnotations({ entityId, entityType, labels }) {
37-
if (labels && labels.length) {
45+
if (!_.isEmpty(labels)) {
3846
return Promise.map(labels, key => sdk.annotations.delete({ entityId, entityType, key }));
3947
}
4048

4149
return sdk.annotations.delete({ entityId, entityType });
4250
}
4351

4452
static _parseAnnotations(labels) {
45-
return labels.map((label) => {
53+
return _.map(labels, (label) => {
4654
const [key, value] = label.split('=');
4755
return { key, value };
4856
});

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const command = new Command({
2121
describe: 'Id of resource for annotation',
2222
required: true,
2323
})
24+
.positional('labels', {
25+
describe: 'Labels',
26+
required: true,
27+
array: true,
28+
})
2429
.example('codefresh create annotation image 2dfacdaad466 coverage=75%', 'Annotate entity with a single label')
2530
.example('codefresh create annotation image 2dfacdaad466 coverage=75% tests_passed=true', 'Annotate entity with multiple labels'),
2631
handler: async (argv) => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const command = new Command({
2121
describe: 'Id of resource for annotation',
2222
required: true,
2323
})
24+
.positional('labels', {
25+
describe: 'Labels to delete',
26+
array: true,
27+
})
2428
.example('codefresh delete annotation image 2dfacdaad466 coverage tests_passed', 'Delete specified annotations')
2529
.example('codefresh delete annotation image 2dfacdaad466', 'Delete all annotations of entity'),
2630
handler: async (argv) => {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const command = new Command({
2424
describe: 'Id of resource for annotation',
2525
required: true,
2626
})
27+
.positional('labels', {
28+
describe: 'Labels to filter by',
29+
array: true,
30+
default: [],
31+
})
2732
.example('codefresh get annotation image 2dfacdaad466', 'Get all annotations for entity')
2833
.example('codefresh get annotation image 2dfacdaad466 coverage tests_passed', 'Get specified annotations'),
2934
handler: async (argv) => {

lib/interface/cli/commands/image/annotate.cmd.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const command = new Command({
2525
describe: 'annotations to add to the image',
2626
default: [],
2727
alias: 'l',
28+
array: true,
2829
})
2930
.example('codefresh annotate image 2dfacdaad466 -l coverage=75%', 'Annotate an image with a single label')
3031
.example('codefresh annotate image 2dfacdaad466 -l coverage=75% -l tests_passed=true', 'Annotate an image with multiple labels');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.19.6",
3+
"version": "0.19.7",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)