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 and logs2webhooks #256

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions internal/lagoon/client/_lgraphql/projectByName.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ query (
autoIdle
factsUi
problemsUi
deployTargetConfigs {
branches
deployTarget{
id
name
token
}
id
project{
autoIdle
gitUrl
name
productionEnvironment
storageCalc
}
pullrequests
weight
}
groups{
... on Group {
__typename
Expand Down
358 changes: 194 additions & 164 deletions internal/lagoon/client/lgraphql/lgraphql.go

Large diffs are not rendered by default.

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
Loading