1
1
const Command = require ( '../../Command' ) ;
2
- const { parseFamiliarName } = require ( '@codefresh-io/docker-reference' ) ;
3
2
const annotateRoot = require ( '../root/annotate.cmd' ) ;
4
- const CFError = require ( 'cf-errors' ) ;
5
- const { sdk } = require ( '../../../../logic' ) ;
6
3
const annotationLogic = require ( '../annotation/annotation.logic' ) ;
7
4
8
5
const command = new Command ( {
@@ -27,32 +24,11 @@ const command = new Command({
27
24
array : true ,
28
25
} )
29
26
. 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' ) ;
31
29
} ,
32
30
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 } ) ;
56
32
console . log ( 'Annotations added successfully' ) ;
57
33
} ,
58
34
} ) ;
0 commit comments