-
Notifications
You must be signed in to change notification settings - Fork 5
Update application version command #30
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package version | ||
|
|
||
| //go:generate ${PROJECT_DIR}/scripts/mockgen.sh ${GOFILE} | ||
|
|
||
| import ( | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/app" | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/commands" | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/commands/utils" | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/common" | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/model" | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/service" | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/service/versions" | ||
| commonCLiCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands" | ||
| pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common" | ||
| "github.com/jfrog/jfrog-cli-core/v2/plugins/components" | ||
| coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" | ||
| "github.com/jfrog/jfrog-client-go/utils/errorutils" | ||
| "github.com/jfrog/jfrog-client-go/utils/log" | ||
| ) | ||
|
|
||
| type updateAppVersionCommand struct { | ||
| versionService versions.VersionService | ||
| serverDetails *coreConfig.ServerDetails | ||
| applicationKey string | ||
| version string | ||
| requestPayload *model.UpdateAppVersionRequest | ||
| } | ||
|
|
||
| func (uv *updateAppVersionCommand) Run() error { | ||
| log.Info("Updating application version:", uv.applicationKey, "version:", uv.version) | ||
|
|
||
| ctx, err := service.NewContext(*uv.serverDetails) | ||
| if err != nil { | ||
| log.Error("Failed to create service context:", err) | ||
| return err | ||
| } | ||
|
|
||
| err = uv.versionService.UpdateAppVersion(ctx, uv.applicationKey, uv.version, uv.requestPayload) | ||
| if err != nil { | ||
| log.Error("Failed to update application version:", err) | ||
| return err | ||
| } | ||
|
|
||
| log.Info("Successfully updated application version:", uv.applicationKey, "version:", uv.version) | ||
| return nil | ||
| } | ||
|
|
||
| func (uv *updateAppVersionCommand) ServerDetails() (*coreConfig.ServerDetails, error) { | ||
| return uv.serverDetails, nil | ||
| } | ||
|
|
||
| func (uv *updateAppVersionCommand) CommandName() string { | ||
| return commands.VersionUpdate | ||
| } | ||
|
|
||
| func (uv *updateAppVersionCommand) prepareAndRunCommand(ctx *components.Context) error { | ||
| if len(ctx.Arguments) != 2 { | ||
| return pluginsCommon.WrongNumberOfArgumentsHandler(ctx) | ||
| } | ||
|
|
||
| if err := uv.parseFlagsAndSetFields(ctx); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| var err error | ||
| uv.requestPayload, err = uv.buildRequestPayload(ctx) | ||
| if errorutils.CheckError(err) != nil { | ||
| return err | ||
| } | ||
|
|
||
| return commonCLiCommands.Exec(uv) | ||
| } | ||
|
|
||
| // parseFlagsAndSetFields parses CLI flags and sets struct fields accordingly. | ||
| func (uv *updateAppVersionCommand) parseFlagsAndSetFields(ctx *components.Context) error { | ||
| uv.applicationKey = ctx.Arguments[0] | ||
| uv.version = ctx.Arguments[1] | ||
|
|
||
| serverDetails, err := utils.ServerDetailsByFlags(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| uv.serverDetails = serverDetails | ||
| return nil | ||
| } | ||
|
|
||
| func (uv *updateAppVersionCommand) buildRequestPayload(ctx *components.Context) (*model.UpdateAppVersionRequest, error) { | ||
| request := &model.UpdateAppVersionRequest{} | ||
|
|
||
| if ctx.IsFlagSet(commands.TagFlag) { | ||
| request.Tag = ctx.GetStringFlagValue(commands.TagFlag) | ||
| } | ||
|
|
||
| // Handle properties - use spec format: key=value1[,value2,...] | ||
| if ctx.IsFlagSet(commands.PropertiesFlag) { | ||
| properties, err := utils.ParseListPropertiesFlag(ctx.GetStringFlagValue(commands.PropertiesFlag)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| request.Properties = properties | ||
| } | ||
|
|
||
| // Handle delete properties | ||
| if ctx.IsFlagSet(commands.DeletePropertyFlag) { | ||
| deleteProps := utils.ParseSliceFlag(ctx.GetStringFlagValue(commands.DeletePropertyFlag)) | ||
| request.DeleteProperties = deleteProps | ||
| } | ||
|
|
||
| return request, nil | ||
| } | ||
|
|
||
| func GetUpdateAppVersionCommand(appContext app.Context) components.Command { | ||
| cmd := &updateAppVersionCommand{versionService: appContext.GetVersionService()} | ||
| return components.Command{ | ||
| Name: commands.VersionUpdate, | ||
| Description: "Updates the user-defined annotations (tag and custom key-value properties) for a specified application version.", | ||
| Category: common.CategoryVersion, | ||
| Aliases: []string{"vu"}, | ||
| Arguments: []components.Argument{ | ||
| { | ||
| Name: "app-key", | ||
| Description: "The application key of the application for which the version is being updated.", | ||
| Optional: false, | ||
| }, | ||
| { | ||
| Name: "version", | ||
| Description: "The version number (in SemVer format) for the application version to update.", | ||
| Optional: false, | ||
| }, | ||
| }, | ||
| Flags: commands.GetCommandFlags(commands.VersionUpdate), | ||
| Action: cmd.prepareAndRunCommand, | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.