Skip to content
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

feature add deploytargets to import command #257

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a36d33e
added factsUI and problemsUI to projectByName
pkalab Dec 1, 2022
129d649
added FactsUI and ProblemsUI to get project output
pkalab Dec 1, 2022
c2ebc92
run make gen
pkalab Dec 1, 2022
78d3edf
Merge branch 'uselagoon:main' into main
polinashtanko Dec 1, 2022
6ac50e4
Merge branch 'main' of github.com:polinashtanko/lagoon-cli
pkalab Dec 1, 2022
e1721e9
updated test cases
pkalab Dec 1, 2022
e686ce6
Merge branch 'main' of github.com:polinashtanko/lagoon-cli into featu…
pkalab Dec 1, 2022
2f5ec62
added DeployTargetConfigs
pkalab Dec 7, 2022
7adbefa
Added DeployTargetConfigs to export command
pkalab Dec 11, 2022
3eb4894
test
pkalab Dec 12, 2022
7af371b
test
pkalab Dec 12, 2022
c8b533f
Merge branch 'feature-add-deploytargets-and-logs2webhooks' of github.…
pkalab Dec 12, 2022
44603aa
added deployTargetConfigs
pkalab Dec 12, 2022
04df61b
deployTargetConfig
pkalab Dec 22, 2022
0fe255f
deploytargetconfigs tests updated
pkalab Dec 28, 2022
9fafc68
removed launch
pkalab Dec 28, 2022
b27ef1e
changed identation on json files
pkalab Jan 4, 2023
a402418
Delete .DS_Store
polinashtanko Jan 6, 2023
90a6b3c
added deployTargetConfigs to import
pkalab Jan 13, 2023
e8f7526
import deployTargetConfig without DeployTarget
pkalab Jan 19, 2023
84fab7f
removed deployTarget
pkalab Jan 22, 2023
3b3680a
Merge branch 'main' into polinashtanko-feature-add-deploytargets-and-…
polinashtanko Jan 22, 2023
1d4d116
Merge branch 'main' into polinashtanko-feature-add-deploytargets-and-…
shreddedbacon Feb 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions internal/lagoon/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type Importer interface {
context.Context, *schema.ProjectGroupsInput, *schema.Project) error
AddNotificationToProject(context.Context,
*schema.AddNotificationToProjectInput, *schema.Project) error
AddDeployTargetConfiguration(context.Context,
*schema.AddDeployTargetConfigInput, *schema.DeployTargetConfig) error
}

// Import creates objects in the Lagoon API based on a configuration object.
Expand Down Expand Up @@ -176,6 +178,7 @@ func Import(ctx context.Context, i Importer, r io.Reader, keepGoing bool,
continue // next project
}
}

// add project env-vars
for _, ev := range p.EnvVariables {
err := i.AddEnvVariable(ctx, &schema.EnvVariableInput{
Expand All @@ -190,6 +193,23 @@ func Import(ctx context.Context, i Importer, r io.Reader, keepGoing bool,
l.Printf("couldn't add Project EnvVariable: %v", err)
}
}
for _, d := range p.DeployTargetConfig {
err := i.AddDeployTargetConfiguration(ctx, &schema.AddDeployTargetConfigInput{
ID: d.ID,
Project: p.ID,
Weight: d.Weight,
Branches: d.Branches,
Pullrequests: d.Pullrequests,
DeployTarget: d.DeployTarget.ID,
DeployTargetProjectPattern: d.DeployTargetProjectPattern,
}, nil)
if err != nil {
if !keepGoing {
return fmt.Errorf("couldn't add Project DeployTargetConfig: %w", err)
}
l.Printf("couldn't add Project DeployTargetConfig: %v", err)
}
}
// add project environments
for _, env := range p.Environments {
newEnv := schema.Environment{}
Expand Down
18 changes: 18 additions & 0 deletions internal/lagoon/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type importCalls struct {
AddEnvironmentInputs []schema.AddEnvironmentInput
ProjectGroupsInputs []schema.ProjectGroupsInput
AddNotificationToProjectInputs []schema.AddNotificationToProjectInput
AddDeployTargetConfigInputs []schema.AddDeployTargetConfigInput
}

func TestImport(t *testing.T) {
Expand All @@ -42,6 +43,7 @@ func TestImport(t *testing.T) {
"exhaustive": {input: "testdata/exhaustive.import.yaml", expect: &importCalls{
NewProjectID: 99,
NewEnvironmentID: 88,

AddGroupInputs: []schema.AddGroupInput{
{Name: "abc"},
},
Expand Down Expand Up @@ -90,6 +92,16 @@ func TestImport(t *testing.T) {
GroupRole: api.MaintainerRole,
},
},
AddDeployTargetConfigInputs: []schema.AddDeployTargetConfigInput{
{

ID: 1234,
Weight: 123,
Branches: "master",
Pullrequests: "This project is configured with DeployTargets",
DeployTargetProjectPattern: "test",
},
},
AddNotificationSlackInputs: []schema.AddNotificationSlackInput{
{
Name: "example-slack",
Expand Down Expand Up @@ -200,6 +212,12 @@ func TestImport(t *testing.T) {
importer.EXPECT().AddUserToGroup(
ctx, &tc.expect.UserGroupRoleInputs[i], nil)
}

for i := range tc.expect.AddDeployTargetConfigInputs {
importer.EXPECT().AddDeployTargetConfiguration(
ctx, &tc.expect.AddDeployTargetConfigInputs[i], nil)
}

for i := range tc.expect.AddNotificationSlackInputs {
importer.EXPECT().AddNotificationSlack(
ctx, &tc.expect.AddNotificationSlackInputs[i], nil)
Expand Down
12 changes: 12 additions & 0 deletions internal/lagoon/testdata/exhaustive.import.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
deployTargetConfigs:
- branches: master
id: 1234
pullrequests: "This project is configured with DeployTargets"
weight: 123
deployTargetProjectPattern: test
groups:
- name: abc
users:
Expand All @@ -23,6 +29,12 @@ notifications:
projects:
- autoIdle: 1
branches: ^(master|develop|production)$
deployTargetConfigs:
- branches: master
id: 1234
pullrequests: "This project is configured with DeployTargets"
weight: 123
deployTargetProjectPattern: test
developmentEnvironmentsLimit: 10
envVariables:
- name: ENABLE_REDIS
Expand Down
69 changes: 0 additions & 69 deletions internal/mock/mock_importer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions internal/schema/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
// Fields for comprising structs are dictated by the add* Lagoon APIs.
type Config struct {
// API objects
Projects []ProjectConfig `json:"projects,omitempty"`
Groups []GroupConfig `json:"groups,omitempty"`
Users []User `json:"users,omitempty"`
Notifications *NotificationsConfig `json:"notifications,omitempty"`
Projects []ProjectConfig `json:"projects,omitempty"`
Groups []GroupConfig `json:"groups,omitempty"`
Users []User `json:"users,omitempty"`
Notifications *NotificationsConfig `json:"notifications,omitempty"`
DeployTargetConfigs []DeployTargetConfig `json:"deployTargetConfigs,omitempty"`
}

// UnmarshalJSON implements json.Unmarshaler interface to control how lagoon
Expand Down