-
Notifications
You must be signed in to change notification settings - Fork 5
Add Version-Release command
#27
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
16 commits
Select commit
Hold shift + click to select a range
eda6038
add release cmd
EyalDelarea bbbce0d
pull main
EyalDelarea b18eead
format
EyalDelarea 3f20e75
go mod and flag fix
EyalDelarea f13b845
improve test
EyalDelarea fadaac5
Refactor
EyalDelarea 10bc350
rename
EyalDelarea ba14f86
Standardized
EyalDelarea 3dce73b
Merge branch 'main' of https://github.com/jfrog/jfrog-cli-application…
EyalDelarea 9ef3fe3
Refactor to use existing logic
EyalDelarea bc93550
CR
EyalDelarea 059415f
CR
EyalDelarea 03655ee
Add PropsFlag to version release and include artifact properties in p…
EyalDelarea 1884307
Refactor PromoteAppVersionRequest to use CommonPromoteAppVersion for …
EyalDelarea 662661c
remove comment
EyalDelarea fb90dff
remove comment
EyalDelarea 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
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,113 @@ | ||
| 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" | ||
| ) | ||
|
|
||
| type releaseAppVersionCommand struct { | ||
| versionService versions.VersionService | ||
| serverDetails *coreConfig.ServerDetails | ||
| applicationKey string | ||
| version string | ||
| requestPayload *model.ReleaseAppVersionRequest | ||
| sync bool | ||
| } | ||
|
|
||
| func (rv *releaseAppVersionCommand) Run() error { | ||
| ctx, err := service.NewContext(*rv.serverDetails) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return rv.versionService.ReleaseAppVersion(ctx, rv.applicationKey, rv.version, rv.requestPayload, rv.sync) | ||
| } | ||
|
|
||
| func (rv *releaseAppVersionCommand) ServerDetails() (*coreConfig.ServerDetails, error) { | ||
| return rv.serverDetails, nil | ||
| } | ||
|
|
||
| func (rv *releaseAppVersionCommand) CommandName() string { | ||
| return commands.VersionRelease | ||
| } | ||
|
|
||
| func (rv *releaseAppVersionCommand) prepareAndRunCommand(ctx *components.Context) error { | ||
| if len(ctx.Arguments) != 2 { | ||
| return pluginsCommon.WrongNumberOfArgumentsHandler(ctx) | ||
| } | ||
|
|
||
| // Extract from arguments | ||
| rv.applicationKey = ctx.Arguments[0] | ||
| rv.version = ctx.Arguments[1] | ||
|
|
||
| // Extract sync flag value | ||
| rv.sync = ctx.GetBoolTFlagValue(commands.SyncFlag) | ||
|
|
||
| serverDetails, err := utils.ServerDetailsByFlags(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| rv.serverDetails = serverDetails | ||
| rv.requestPayload, err = rv.buildRequestPayload(ctx) | ||
| if errorutils.CheckError(err) != nil { | ||
| return err | ||
| } | ||
| return commonCLiCommands.Exec(rv) | ||
| } | ||
|
|
||
| func (rv *releaseAppVersionCommand) buildRequestPayload(ctx *components.Context) (*model.ReleaseAppVersionRequest, error) { | ||
| promotionType, includedRepos, excludedRepos, err := BuildPromotionParams(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| artifactProps, err := ParseArtifactProps(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return model.NewReleaseAppVersionRequest( | ||
| promotionType, | ||
| includedRepos, | ||
| excludedRepos, | ||
| artifactProps, | ||
| ), nil | ||
| } | ||
|
|
||
| func GetReleaseAppVersionCommand(appContext app.Context) components.Command { | ||
| cmd := &releaseAppVersionCommand{ | ||
| versionService: appContext.GetVersionService(), | ||
| } | ||
| return components.Command{ | ||
| Name: commands.VersionRelease, | ||
| Description: "Release application version.", | ||
| Category: common.CategoryVersion, | ||
| Aliases: []string{"vr"}, | ||
| Arguments: []components.Argument{ | ||
| { | ||
| Name: "application-key", | ||
| Description: "The application key.", | ||
| Optional: false, | ||
| }, | ||
| { | ||
| Name: "version", | ||
| Description: "The version to release.", | ||
| Optional: false, | ||
| }, | ||
| }, | ||
| Flags: commands.GetCommandFlags(commands.VersionRelease), | ||
| Action: cmd.prepareAndRunCommand, | ||
| } | ||
| } |
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,95 @@ | ||
| package version | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| mockversions "github.com/jfrog/jfrog-cli-application/apptrust/service/versions/mocks" | ||
| "go.uber.org/mock/gomock" | ||
|
|
||
| "github.com/jfrog/jfrog-cli-application/apptrust/model" | ||
| "github.com/jfrog/jfrog-cli-core/v2/utils/config" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestReleaseAppVersionCommand_Run(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| sync bool | ||
| }{ | ||
| { | ||
| name: "sync flag true", | ||
| sync: true, | ||
| }, | ||
| { | ||
| name: "sync flag false", | ||
| sync: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
|
|
||
| serverDetails := &config.ServerDetails{Url: "https://example.com"} | ||
| applicationKey := "app-key" | ||
| version := "1.0.0" | ||
| requestPayload := model.NewReleaseAppVersionRequest( | ||
| model.PromotionTypeCopy, | ||
| nil, // includedRepos | ||
| nil, // excludedRepos | ||
| nil, // artifactProps | ||
| ) | ||
|
|
||
| mockVersionService := mockversions.NewMockVersionService(ctrl) | ||
| mockVersionService.EXPECT().ReleaseAppVersion(gomock.Any(), applicationKey, version, requestPayload, tt.sync). | ||
| Return(nil).Times(1) | ||
|
|
||
| cmd := &releaseAppVersionCommand{ | ||
| versionService: mockVersionService, | ||
| serverDetails: serverDetails, | ||
| applicationKey: applicationKey, | ||
| version: version, | ||
| requestPayload: requestPayload, | ||
| sync: tt.sync, | ||
| } | ||
|
|
||
| err := cmd.Run() | ||
| assert.NoError(t, err) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestReleaseAppVersionCommand_Run_Error(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
|
|
||
| serverDetails := &config.ServerDetails{Url: "https://example.com"} | ||
| applicationKey := "app-key" | ||
| version := "1.0.0" | ||
| requestPayload := model.NewReleaseAppVersionRequest( | ||
| model.PromotionTypeCopy, | ||
| nil, // includedRepos | ||
| nil, // excludedRepos | ||
| nil, // artifactProps | ||
| ) | ||
| expectedError := errors.New("service error occurred") | ||
|
|
||
| mockVersionService := mockversions.NewMockVersionService(ctrl) | ||
| mockVersionService.EXPECT().ReleaseAppVersion(gomock.Any(), applicationKey, version, requestPayload, false). | ||
| Return(expectedError).Times(1) | ||
|
|
||
| cmd := &releaseAppVersionCommand{ | ||
| versionService: mockVersionService, | ||
| serverDetails: serverDetails, | ||
| applicationKey: applicationKey, | ||
| version: version, | ||
| requestPayload: requestPayload, | ||
| sync: false, | ||
| } | ||
|
|
||
| err := cmd.Run() | ||
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), "service error occurred") | ||
| } |
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,51 @@ | ||
| package version | ||
|
|
||
| import ( | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/commands" | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/commands/utils" | ||
| "github.com/jfrog/jfrog-cli-application/apptrust/model" | ||
| "github.com/jfrog/jfrog-cli-core/v2/plugins/components" | ||
| "github.com/jfrog/jfrog-client-go/utils/errorutils" | ||
| ) | ||
|
|
||
| // BuildPromotionParams extracts common promotion parameters from command context | ||
| // Used by both promote and release commands | ||
| func BuildPromotionParams(ctx *components.Context) (string, []string, []string, error) { | ||
| var includedRepos []string | ||
| var excludedRepos []string | ||
|
|
||
| if includeReposStr := ctx.GetStringFlagValue(commands.IncludeReposFlag); includeReposStr != "" { | ||
| includedRepos = utils.ParseSliceFlag(includeReposStr) | ||
| } | ||
|
|
||
| if excludeReposStr := ctx.GetStringFlagValue(commands.ExcludeReposFlag); excludeReposStr != "" { | ||
| excludedRepos = utils.ParseSliceFlag(excludeReposStr) | ||
| } | ||
|
|
||
| promotionType := ctx.GetStringFlagValue(commands.PromotionTypeFlag) | ||
|
|
||
| validatedPromotionType, err := utils.ValidateEnumFlag(commands.PromotionTypeFlag, promotionType, model.PromotionTypeCopy, model.PromotionTypeValues) | ||
| if err != nil { | ||
| return "", nil, nil, err | ||
| } | ||
|
|
||
| // If dry-run is true, override with dry_run | ||
| dryRun := ctx.GetBoolFlagValue(commands.DryRunFlag) | ||
| if dryRun { | ||
| validatedPromotionType = model.PromotionTypeDryRun | ||
| } | ||
|
|
||
| return validatedPromotionType, includedRepos, excludedRepos, nil | ||
| } | ||
|
|
||
| // ParseArtifactProps extracts artifact properties from command context | ||
| func ParseArtifactProps(ctx *components.Context) (map[string]string, error) { | ||
| if propsStr := ctx.GetStringFlagValue(commands.PropsFlag); propsStr != "" { | ||
| props, err := utils.ParseMapFlag(propsStr) | ||
| if err != nil { | ||
| return nil, errorutils.CheckErrorf("failed to parse properties: %s", err.Error()) | ||
| } | ||
| return props, nil | ||
| } | ||
| return nil, nil | ||
| } | ||
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.