-
Notifications
You must be signed in to change notification settings - Fork 25
James C CLI updates tags #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
7be8677
8633a04
07267fd
b6f2420
1acd930
a1e3d89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ## galasactl runs update | ||
|
|
||
| Update tags for a named test run. | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Update tags for a named test run. | ||
|
|
||
| ``` | ||
| galasactl runs update [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| --add-tags strings comma-separated list of tags to add | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the --add-tags flag also be supplied like: If so, it would be good to make it clear that you can either supply a comma-separated list or multiple |
||
| -h, --help Displays the options for the 'runs update' command. | ||
| --name string the name of the test run we want to update | ||
| --remove-tags strings comma-separated list of tags to remove | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the --remove-tags flag also be supplied like: --remove-tags tag1 --remove-tags tag2 If so, it would be good to make it clear that you can either supply a comma-separated list or multiple --remove-tags flags |
||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties | ||
| --galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead. | ||
| -l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging. | ||
| --rate-limit-retries int The maximum number of retries that should be made when requests to the Galasa Service fail due to rate limits being exceeded. Must be a whole number. Defaults to 3 retries (default 3) | ||
| --rate-limit-retry-backoff-secs float The amount of time in seconds to wait before retrying a command if it failed due to rate limits being exceeded. Defaults to 1 second. (default 1) | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /* | ||
| * Copyright contributors to the Galasa project | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/galasa-dev/cli/pkg/api" | ||
| "github.com/galasa-dev/cli/pkg/runs" | ||
| "github.com/galasa-dev/cli/pkg/spi" | ||
| "github.com/galasa-dev/cli/pkg/utils" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // Objective: Allow the user to do this: | ||
| // runs update --name U12345 --add-tags tag1,tag2 --remove-tags tag3 | ||
|
|
||
| // Variables set by cobra's command-line parsing. | ||
| type RunsUpdateCmdValues struct { | ||
| runName string | ||
| addTags []string | ||
| removeTags []string | ||
| } | ||
|
|
||
| type RunsUpdateCommand struct { | ||
| values *RunsUpdateCmdValues | ||
| cobraCommand *cobra.Command | ||
| } | ||
|
|
||
| func NewRunsUpdateCommand(factory spi.Factory, runsCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) (spi.GalasaCommand, error) { | ||
| cmd := new(RunsUpdateCommand) | ||
| err := cmd.init(factory, runsCommand, commsFlagSet) | ||
| return cmd, err | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Public methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func (cmd *RunsUpdateCommand) Name() string { | ||
| return COMMAND_NAME_RUNS_UPDATE | ||
| } | ||
|
|
||
| func (cmd *RunsUpdateCommand) CobraCommand() *cobra.Command { | ||
| return cmd.cobraCommand | ||
| } | ||
|
|
||
| func (cmd *RunsUpdateCommand) Values() interface{} { | ||
| return cmd.values | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // Private methods | ||
| // ------------------------------------------------------------------------------------------------ | ||
| func (cmd *RunsUpdateCommand) init(factory spi.Factory, runsCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error { | ||
| var err error | ||
| cmd.values = &RunsUpdateCmdValues{} | ||
| cmd.cobraCommand, err = cmd.createCobraCommand(factory, runsCommand, commsFlagSet.Values().(*CommsFlagSetValues)) | ||
| return err | ||
| } | ||
|
|
||
| func (cmd *RunsUpdateCommand) createCobraCommand( | ||
| factory spi.Factory, | ||
| runsCommand spi.GalasaCommand, | ||
| commsFlagSetValues *CommsFlagSetValues, | ||
| ) (*cobra.Command, error) { | ||
|
|
||
| var err error | ||
|
|
||
| runsUpdateCobraCmd := &cobra.Command{ | ||
| Use: "update", | ||
| Short: "Update tags for a named test run.", | ||
| Long: "Update tags for a named test run.", | ||
| Args: cobra.NoArgs, | ||
| Aliases: []string{"runs update"}, | ||
| RunE: func(cobraCmd *cobra.Command, args []string) error { | ||
| return cmd.executeRunsUpdate(factory, commsFlagSetValues) | ||
| }, | ||
| } | ||
|
|
||
| runsUpdateCobraCmd.Flags().StringVar(&cmd.values.runName, "name", "", "the name of the test run we want to update") | ||
| runsUpdateCobraCmd.MarkFlagRequired("name") | ||
|
|
||
| runsUpdateCobraCmd.Flags().StringSliceVar(&cmd.values.addTags, "add-tags", nil, "comma-separated list of tags to add") | ||
| runsUpdateCobraCmd.Flags().StringSliceVar(&cmd.values.removeTags, "remove-tags", nil, "comma-separated list of tags to remove") | ||
|
|
||
| runsCommand.CobraCommand().AddCommand(runsUpdateCobraCmd) | ||
|
|
||
| return runsUpdateCobraCmd, err | ||
| } | ||
|
|
||
| func (cmd *RunsUpdateCommand) executeRunsUpdate( | ||
| factory spi.Factory, | ||
| commsFlagSetValues *CommsFlagSetValues, | ||
| ) error { | ||
|
|
||
| var err error | ||
|
|
||
| // Operations on the file system will all be relative to the current folder. | ||
| fileSystem := factory.GetFileSystem() | ||
|
|
||
| err = utils.CaptureLog(fileSystem, commsFlagSetValues.logFileName) | ||
| if err == nil { | ||
| commsFlagSetValues.isCapturingLogs = true | ||
|
|
||
| // Get the ability to query environment variables. | ||
| env := factory.GetEnvironment() | ||
|
|
||
| var galasaHome spi.GalasaHome | ||
| galasaHome, err = utils.NewGalasaHome(fileSystem, env, commsFlagSetValues.CmdParamGalasaHomePath) | ||
| if err == nil { | ||
|
|
||
| var commsClient api.APICommsClient | ||
| commsClient, err = api.NewAPICommsClient( | ||
| commsFlagSetValues.bootstrap, | ||
| commsFlagSetValues.maxRetries, | ||
| commsFlagSetValues.retryBackoffSeconds, | ||
| factory, | ||
| galasaHome, | ||
| ) | ||
|
|
||
| if err == nil { | ||
|
|
||
| var console = factory.GetStdOutConsole() | ||
| timeService := factory.GetTimeService() | ||
|
|
||
| // Call to process the command in a unit-testable way. | ||
| err = runs.RunsUpdate( | ||
| cmd.values.runName, | ||
| cmd.values.addTags, | ||
| cmd.values.removeTags, | ||
| console, | ||
| commsClient, | ||
| timeService, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return err | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it's true that
runs updateonly updates tags at the moment, maybe this description could be made more general to something like: "Update the record of an existing test run on a Galasa service"?It's also worth explicitly saying that this affects existing test runs on a Galasa service since I don't believe we're setting tags for local runs.