diff --git a/lib/interface/cli/commands/image/annotate.cmd.js b/lib/interface/cli/commands/image/annotate.cmd.js index 76ceb0368..df8ff097e 100644 --- a/lib/interface/cli/commands/image/annotate.cmd.js +++ b/lib/interface/cli/commands/image/annotate.cmd.js @@ -1,8 +1,5 @@ const Command = require('../../Command'); -const { parseFamiliarName } = require('@codefresh-io/docker-reference'); const annotateRoot = require('../root/annotate.cmd'); -const CFError = require('cf-errors'); -const { sdk } = require('../../../../logic'); const annotationLogic = require('../annotation/annotation.logic'); const command = new Command({ @@ -27,32 +24,11 @@ const command = new Command({ array: true, }) .example('codefresh annotate image 2dfacdaad466 -l coverage=75%', 'Annotate an image with a single label') - .example('codefresh annotate image 2dfacdaad466 -l coverage=75% -l tests_passed=true', 'Annotate an image with multiple labels'); + .example('codefresh annotate image 2dfacdaad466 -l coverage=75% -l tests_passed=true', 'Annotate an image with multiple labels') + .example('codefresh annotate image codefresh/cli:latest -l coverage=75% -l tests_passed=true', 'Annotate an image by name with multiple labels'); }, handler: async (argv) => { - let dockerImageId = argv.id; - const useFullName = dockerImageId.includes(':'); - - if (useFullName) { - const { repository, tag } = parseFamiliarName(dockerImageId); - const results = await sdk.images.list({ - imageDisplayNameRegex: repository, - tag, - select: 'internalImageId', - }); - - if (!results.length) { - throw new CFError('Image does not exist'); - } - - if (results.length > 1) { - throw new CFError(`Could not get image id. ${results.length} images found.`); - } - - dockerImageId = results[0].internalImageId; - } - - await annotationLogic.createAnnotations({ entityId: dockerImageId, entityType: 'image', labels: argv.label }); + await annotationLogic.createAnnotations({ entityId: argv.id, entityType: 'image', labels: argv.label }); console.log('Annotations added successfully'); }, }); diff --git a/lib/interface/cli/commands/image/image.sdk.spec.js b/lib/interface/cli/commands/image/image.sdk.spec.js index c2758315c..35d4d5ac5 100644 --- a/lib/interface/cli/commands/image/image.sdk.spec.js +++ b/lib/interface/cli/commands/image/image.sdk.spec.js @@ -98,37 +98,5 @@ describe('image commands', () => { await annotateCmd.handler(argv); await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line }); - - it('should handle annotating given full image name', async () => { - const argv = { id: 'repo/name:tag', label: ['test=test'] }; - const responses = [ - { statusCode: 200, body: [{ internalImageId: 'some id' }] }, - DEFAULT_RESPONSE, - ]; - request.__queueResponses(responses); - await annotateCmd.handler(argv); - await verifyResponsesReturned(responses); // eslint-disable-line - }); - - it('should throw on no images found given image full name', async () => { - const argv = { id: 'repo/name:tag', label: ['test=test'] }; - const response = { statusCode: 200, body: [] }; - request.__setResponse(response); - - await expect(annotateCmd.handler(argv)).rejects.toThrow(); - await verifyResponsesReturned([response]); // eslint-disable-line - }); - - it('should throw on multiple images found given image full name', async () => { - const argv = { id: 'repo/name:tag', label: ['test=test'] }; - const response = { - statusCode: 200, - body: [{ internalImageId: 'some id' }, { internalImageId: 'another id' }], - }; - request.__setResponse(response); - - await expect(annotateCmd.handler(argv)).rejects.toThrow(); - await verifyResponsesReturned([response]); // eslint-disable-line - }); }); }); diff --git a/package.json b/package.json index 658f5de62..1ece7c5f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.88.1", + "version": "0.88.2", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,