Skip to content

Commit

Permalink
Add --name flag to artifact reporting. Fix kosli-cli/server#882
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewelina Wilkosz committed Sep 1, 2023
1 parent f4241c7 commit 6306bfe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/kosli/reportArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type reportArtifactOptions struct {
flowName string
gitReference string
srcRepoRoot string
name string
payload ArtifactPayload
}

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/kosli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
1 change: 1 addition & 0 deletions cmd/kosli/testdata/output/docs/artifact.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down

0 comments on commit 6306bfe

Please sign in to comment.