Merge pull request #91 from sgotti/cmd_fix_variable_create_update

cmd: fix variable create/update
This commit is contained in:
Simone Gotti 2019-08-29 18:06:28 +02:00 committed by GitHub
commit 409033c9a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 4 deletions

View File

@ -19,6 +19,8 @@ import (
"io/ioutil"
"os"
config "agola.io/agola/internal/config"
cstypes "agola.io/agola/services/configstore/types"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"
@ -91,7 +93,7 @@ type VariableValue struct {
SecretName string `json:"secret_name,omitempty"`
SecretVar string `json:"secret_var,omitempty"`
When *gwapitypes.When `json:"when,omitempty"`
When *config.When `json:"when,omitempty"`
}
func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
@ -121,7 +123,7 @@ func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
rvalues = append(rvalues, gwapitypes.VariableValueRequest{
SecretName: value.SecretName,
SecretVar: value.SecretVar,
When: value.When,
When: fromCsWhen(value.When.ToCSWhen()),
})
}
req := &gwapitypes.CreateVariableRequest{
@ -148,3 +150,36 @@ func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
return nil
}
func fromCsWhenCondition(apiwc cstypes.WhenCondition) gwapitypes.WhenCondition {
return gwapitypes.WhenCondition{
Type: gwapitypes.WhenConditionType(apiwc.Type),
Match: apiwc.Match,
}
}
func fromCsWhenConditions(apiwcs *cstypes.WhenConditions) *gwapitypes.WhenConditions {
if apiwcs == nil {
return nil
}
wcs := &gwapitypes.WhenConditions{
Include: make([]gwapitypes.WhenCondition, len(apiwcs.Include)),
Exclude: make([]gwapitypes.WhenCondition, len(apiwcs.Exclude)),
}
for i, include := range apiwcs.Include {
wcs.Include[i] = fromCsWhenCondition(include)
}
for i, exclude := range apiwcs.Exclude {
wcs.Exclude[i] = fromCsWhenCondition(exclude)
}
return wcs
}
func fromCsWhen(apiwhen *cstypes.When) *gwapitypes.When {
return &gwapitypes.When{
Branch: fromCsWhenConditions(apiwhen.Branch),
Tag: fromCsWhenConditions(apiwhen.Tag),
Ref: fromCsWhenConditions(apiwhen.Ref),
}
}

View File

@ -94,7 +94,7 @@ func variableUpdate(cmd *cobra.Command, ownertype string, args []string) error {
rvalues = append(rvalues, gwapitypes.VariableValueRequest{
SecretName: value.SecretName,
SecretVar: value.SecretVar,
When: value.When,
When: fromCsWhen(value.When.ToCSWhen()),
})
}
req := &gwapitypes.UpdateVariableRequest{

View File

@ -23,9 +23,9 @@ import (
"time"
slog "agola.io/agola/internal/log"
"agola.io/agola/internal/testutil"
"github.com/docker/docker/api/types"
uuid "github.com/satori/go.uuid"
"agola.io/agola/internal/testutil"
"github.com/google/go-cmp/cmp"
"go.uber.org/zap"

View File

@ -235,6 +235,9 @@ func fromApiWhenCondition(apiwc gwapitypes.WhenCondition) cstypes.WhenCondition
}
func fromApiWhenConditions(apiwcs *gwapitypes.WhenConditions) *cstypes.WhenConditions {
if apiwcs == nil {
return nil
}
wcs := &cstypes.WhenConditions{
Include: make([]cstypes.WhenCondition, len(apiwcs.Include)),
Exclude: make([]cstypes.WhenCondition, len(apiwcs.Exclude)),
@ -265,6 +268,9 @@ func fromCsWhenCondition(apiwc cstypes.WhenCondition) gwapitypes.WhenCondition {
}
func fromCsWhenConditions(apiwcs *cstypes.WhenConditions) *gwapitypes.WhenConditions {
if apiwcs == nil {
return nil
}
wcs := &gwapitypes.WhenConditions{
Include: make([]gwapitypes.WhenCondition, len(apiwcs.Include)),
Exclude: make([]gwapitypes.WhenCondition, len(apiwcs.Exclude)),