From 6306bfe9e72517fa94876858d2fafcc1a0a45ccc Mon Sep 17 00:00:00 2001 From: Ewelina Wilkosz Date: Fri, 1 Sep 2023 13:16:39 +0200 Subject: [PATCH] Add --name flag to artifact reporting. Fix kosli-cli/server#882 --- cmd/kosli/reportArtifact.go | 21 ++++++++++++++++----- cmd/kosli/root.go | 1 + cmd/kosli/testdata/output/docs/artifact.md | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/kosli/reportArtifact.go b/cmd/kosli/reportArtifact.go index e4093f195..ac1841264 100644 --- a/cmd/kosli/reportArtifact.go +++ b/cmd/kosli/reportArtifact.go @@ -17,6 +17,7 @@ type reportArtifactOptions struct { flowName string gitReference string srcRepoRoot string + name string payload ArtifactPayload } @@ -89,8 +90,8 @@ func newReportArtifactCmd(out io.Writer) *cobra.Command { cmd.Flags().StringVarP(&o.payload.BuildUrl, "build-url", "b", DefaultValue(ci, "build-url"), buildUrlFlag) cmd.Flags().StringVarP(&o.payload.CommitUrl, "commit-url", "u", DefaultValue(ci, "commit-url"), commitUrlFlag) cmd.Flags().StringVar(&o.srcRepoRoot, "repo-root", ".", repoRootFlag) + cmd.Flags().StringVarP(&o.name, "name", "n", "", artifactName) addFingerprintFlags(cmd, o.fingerprintOptions) - // cmd.Flags().StringSliceVarP(&o.fingerprintOptions.excludePaths, "exclude", "e", []string{}, excludePathsFlag) addDryRunFlag(cmd) @@ -104,18 +105,28 @@ func newReportArtifactCmd(out io.Writer) *cobra.Command { func (o *reportArtifactOptions) run(args []string) error { if o.payload.Fingerprint != "" { - o.payload.Filename = args[0] + if o.name != "" { + o.payload.Filename = o.name + } else { + o.payload.Filename = args[0] + } } else { var err error o.payload.Fingerprint, err = GetSha256Digest(args[0], o.fingerprintOptions, logger) if err != nil { return err } - if o.fingerprintOptions.artifactType == "dir" || o.fingerprintOptions.artifactType == "file" { - o.payload.Filename = filepath.Base(args[0]) + + if o.name != "" { + o.payload.Filename = o.name } else { - o.payload.Filename = args[0] + if o.fingerprintOptions.artifactType == "dir" || o.fingerprintOptions.artifactType == "file" { + o.payload.Filename = filepath.Base(args[0]) + } else { + o.payload.Filename = args[0] + } } + } gitView, err := gitview.New(o.srcRepoRoot) diff --git a/cmd/kosli/root.go b/cmd/kosli/root.go index 450f5a79a..5824b02ba 100644 --- a/cmd/kosli/root.go +++ b/cmd/kosli/root.go @@ -45,6 +45,7 @@ More details can be found here: https://aws.github.io/aws-sdk-go-v2/docs/configu // flags apiTokenFlag = "The Kosli API token." + artifactName = "[optional] Artifact display name, if different from file, image or directory name." orgFlag = "The Kosli organization." hostFlag = "[defaulted] The Kosli endpoint." dryRunFlag = "[optional] Run in dry-run mode. When enabled, no data is sent to Kosli and the CLI exits with 0 exit code regardless of any errors." diff --git a/cmd/kosli/testdata/output/docs/artifact.md b/cmd/kosli/testdata/output/docs/artifact.md index 0e7017dd5..46e86be27 100644 --- a/cmd/kosli/testdata/output/docs/artifact.md +++ b/cmd/kosli/testdata/output/docs/artifact.md @@ -26,6 +26,7 @@ artifact {IMAGE-NAME | FILE-PATH | DIR-PATH} [flags] | -f, --flow string | The Kosli flow name. | | -g, --git-commit string | The git commit from which the artifact was created. (defaulted in some CIs: https://docs.kosli.com/ci-defaults ). | | -h, --help | help for artifact | +| -n, --name string | [optional] Artifact display name, if different from file, image or directory name. | | --registry-password string | [conditional] The docker registry password or access token. Only required if you want to read docker image SHA256 digest from a remote docker registry. | | --registry-provider string | [conditional] The docker registry provider or url. Only required if you want to read docker image SHA256 digest from a remote docker registry. | | --registry-username string | [conditional] The docker registry username. Only required if you want to read docker image SHA256 digest from a remote docker registry. |