Skip to content

Commit 7e49659

Browse files
Annotate images based on name (#868)
## What ## Why ## Notes
1 parent 04b5e0a commit 7e49659

File tree

3 files changed

+4
-60
lines changed

3 files changed

+4
-60
lines changed

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

+3-27
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
const Command = require('../../Command');
2-
const { parseFamiliarName } = require('@codefresh-io/docker-reference');
32
const annotateRoot = require('../root/annotate.cmd');
4-
const CFError = require('cf-errors');
5-
const { sdk } = require('../../../../logic');
63
const annotationLogic = require('../annotation/annotation.logic');
74

85
const command = new Command({
@@ -27,32 +24,11 @@ const command = new Command({
2724
array: true,
2825
})
2926
.example('codefresh annotate image 2dfacdaad466 -l coverage=75%', 'Annotate an image with a single label')
30-
.example('codefresh annotate image 2dfacdaad466 -l coverage=75% -l tests_passed=true', 'Annotate an image with multiple labels');
27+
.example('codefresh annotate image 2dfacdaad466 -l coverage=75% -l tests_passed=true', 'Annotate an image with multiple labels')
28+
.example('codefresh annotate image codefresh/cli:latest -l coverage=75% -l tests_passed=true', 'Annotate an image by name with multiple labels');
3129
},
3230
handler: async (argv) => {
33-
let dockerImageId = argv.id;
34-
const useFullName = dockerImageId.includes(':');
35-
36-
if (useFullName) {
37-
const { repository, tag } = parseFamiliarName(dockerImageId);
38-
const results = await sdk.images.list({
39-
imageDisplayNameRegex: repository,
40-
tag,
41-
select: 'internalImageId',
42-
});
43-
44-
if (!results.length) {
45-
throw new CFError('Image does not exist');
46-
}
47-
48-
if (results.length > 1) {
49-
throw new CFError(`Could not get image id. ${results.length} images found.`);
50-
}
51-
52-
dockerImageId = results[0].internalImageId;
53-
}
54-
55-
await annotationLogic.createAnnotations({ entityId: dockerImageId, entityType: 'image', labels: argv.label });
31+
await annotationLogic.createAnnotations({ entityId: argv.id, entityType: 'image', labels: argv.label });
5632
console.log('Annotations added successfully');
5733
},
5834
});

lib/interface/cli/commands/image/image.sdk.spec.js

-32
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,5 @@ describe('image commands', () => {
9898
await annotateCmd.handler(argv);
9999
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
100100
});
101-
102-
it('should handle annotating given full image name', async () => {
103-
const argv = { id: 'repo/name:tag', label: ['test=test'] };
104-
const responses = [
105-
{ statusCode: 200, body: [{ internalImageId: 'some id' }] },
106-
DEFAULT_RESPONSE,
107-
];
108-
request.__queueResponses(responses);
109-
await annotateCmd.handler(argv);
110-
await verifyResponsesReturned(responses); // eslint-disable-line
111-
});
112-
113-
it('should throw on no images found given image full name', async () => {
114-
const argv = { id: 'repo/name:tag', label: ['test=test'] };
115-
const response = { statusCode: 200, body: [] };
116-
request.__setResponse(response);
117-
118-
await expect(annotateCmd.handler(argv)).rejects.toThrow();
119-
await verifyResponsesReturned([response]); // eslint-disable-line
120-
});
121-
122-
it('should throw on multiple images found given image full name', async () => {
123-
const argv = { id: 'repo/name:tag', label: ['test=test'] };
124-
const response = {
125-
statusCode: 200,
126-
body: [{ internalImageId: 'some id' }, { internalImageId: 'another id' }],
127-
};
128-
request.__setResponse(response);
129-
130-
await expect(annotateCmd.handler(argv)).rejects.toThrow();
131-
await verifyResponsesReturned([response]); // eslint-disable-line
132-
});
133101
});
134102
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.88.1",
3+
"version": "0.88.2",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)