Skip to content

Commit

Permalink
feat(github): Support GitHub transient environment deployment type
Browse files Browse the repository at this point in the history
Signed-off-by: ricky-sb <10700079+ricky-sb@users.noreply.github.com>
  • Loading branch information
ricky-sb committed Jan 24, 2024
1 parent c02dc5f commit 2eab075
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions docs/services/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ template.app-deployed: |
logURL: "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true"
requiredContexts: []
autoMerge: true
transientEnvironment: false
pullRequestComment:
content: |
Application {{.app.metadata.name}} is now running new version of deployments manifests.
Expand Down
30 changes: 20 additions & 10 deletions pkg/services/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ type GitHubStatus struct {
}

type GitHubDeployment struct {
State string `json:"state,omitempty"`
Environment string `json:"environment,omitempty"`
EnvironmentURL string `json:"environmentURL,omitempty"`
LogURL string `json:"logURL,omitempty"`
RequiredContexts []string `json:"requiredContexts"`
AutoMerge *bool `json:"autoMerge,omitempty"`
State string `json:"state,omitempty"`
Environment string `json:"environment,omitempty"`
EnvironmentURL string `json:"environmentURL,omitempty"`
LogURL string `json:"logURL,omitempty"`
RequiredContexts []string `json:"requiredContexts"`
AutoMerge *bool `json:"autoMerge,omitempty"`
TransientEnvironment *bool `json:"transientEnvironment,omitempty"`
}

type GitHubPullRequestComment struct {
Expand Down Expand Up @@ -211,6 +212,14 @@ func (g *GitHubNotification) GetTemplater(name string, f texttemplate.FuncMap) (
} else {
notification.GitHub.Deployment.AutoMerge = g.Deployment.AutoMerge
}

if g.Deployment.TransientEnvironment == nil {
deploymentTransientEnvironmentDefault := false
notification.GitHub.Deployment.TransientEnvironment = &deploymentTransientEnvironmentDefault

Check warning on line 218 in pkg/services/github.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/github.go#L217-L218

Added lines #L217 - L218 were not covered by tests
} else {
notification.GitHub.Deployment.TransientEnvironment = g.Deployment.TransientEnvironment
}

notification.GitHub.Deployment.RequiredContexts = g.Deployment.RequiredContexts
}

Expand Down Expand Up @@ -334,10 +343,11 @@ func (g gitHubService) Send(notification Notification, _ Destination) error {
u[0],
u[1],
&github.DeploymentRequest{
Ref: &notification.GitHub.revision,
Environment: &notification.GitHub.Deployment.Environment,
RequiredContexts: &notification.GitHub.Deployment.RequiredContexts,
AutoMerge: notification.GitHub.Deployment.AutoMerge,
Ref: &notification.GitHub.revision,
Environment: &notification.GitHub.Deployment.Environment,
RequiredContexts: &notification.GitHub.Deployment.RequiredContexts,
AutoMerge: notification.GitHub.Deployment.AutoMerge,
TransientEnvironment: notification.GitHub.Deployment.TransientEnvironment,

Check warning on line 350 in pkg/services/github.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/github.go#L346-L350

Added lines #L346 - L350 were not covered by tests
},
)
if err != nil {
Expand Down
15 changes: 9 additions & 6 deletions pkg/services/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,19 @@ func TestSend_GitHubService_BadURL(t *testing.T) {

func TestGetTemplater_GitHub_Deployment(t *testing.T) {
f := false
tr := true
n := Notification{
GitHub: &GitHubNotification{
RepoURLPath: "{{.sync.spec.git.repo}}",
RevisionPath: "{{.sync.status.lastSyncedCommit}}",
Deployment: &GitHubDeployment{
State: "success",
Environment: "production",
EnvironmentURL: "https://argoproj.github.io",
LogURL: "https://argoproj.github.io/log",
RequiredContexts: []string{},
AutoMerge: &f,
State: "success",
Environment: "production",
EnvironmentURL: "https://argoproj.github.io",
LogURL: "https://argoproj.github.io/log",
RequiredContexts: []string{},
AutoMerge: &f,
TransientEnvironment: &tr,
},
},
}
Expand Down Expand Up @@ -174,6 +176,7 @@ func TestGetTemplater_GitHub_Deployment(t *testing.T) {
assert.Equal(t, "https://argoproj.github.io/log", notification.GitHub.Deployment.LogURL)
assert.Len(t, notification.GitHub.Deployment.RequiredContexts, 0)
assert.Equal(t, &f, notification.GitHub.Deployment.AutoMerge)
assert.Equal(t, &tr, notification.GitHub.Deployment.TransientEnvironment)
}

func TestNewGitHubService_GitHubOptions(t *testing.T) {
Expand Down

0 comments on commit 2eab075

Please sign in to comment.