diff --git a/docs/services/github.md b/docs/services/github.md index b093219f..a3f89f8c 100644 --- a/docs/services/github.md +++ b/docs/services/github.md @@ -81,5 +81,6 @@ template.app-deployed: | **Notes**: - If the message is set to 140 characters or more, it will be truncated. - If `github.repoURLPath` and `github.revisionPath` are same as above, they can be omitted. -- By default, github deployments utilize automerge to ensure the requested ref is up to date with the default branch. +- Automerge is optional and `true` by default for github deployments to ensure the requested ref is up to date with the default branch. Setting this option to `false` is required if you would like to deploy older refs in your default branch. + For more information see the [Github Deployment API Docs](https://docs.github.com/en/rest/deployments/deployments?apiVersion=2022-11-28#create-a-deployment). diff --git a/pkg/services/github.go b/pkg/services/github.go index fdeb80b0..6cd3646f 100644 --- a/pkg/services/github.go +++ b/pkg/services/github.go @@ -52,7 +52,7 @@ type GitHubDeployment struct { EnvironmentURL string `json:"environmentURL,omitempty"` LogURL string `json:"logURL,omitempty"` RequiredContexts []string `json:"requiredContexts"` - AutoMerge bool `json:"autoMerge,omitempty"` + AutoMerge *bool `json:"autoMerge,omitempty"` } const ( @@ -192,7 +192,12 @@ func (g *GitHubNotification) GetTemplater(name string, f texttemplate.FuncMap) ( } notification.GitHub.Deployment.LogURL = logURLData.String() - notification.GitHub.Deployment.AutoMerge = g.Deployment.AutoMerge + if g.Deployment.AutoMerge == nil { + deploymentAutoMergeDefault := true + notification.GitHub.Deployment.AutoMerge = &deploymentAutoMergeDefault + } else { + notification.GitHub.Deployment.AutoMerge = g.Deployment.AutoMerge + } notification.GitHub.Deployment.RequiredContexts = g.Deployment.RequiredContexts } @@ -305,7 +310,7 @@ func (g gitHubService) Send(notification Notification, _ Destination) error { Ref: ¬ification.GitHub.revision, Environment: ¬ification.GitHub.Deployment.Environment, RequiredContexts: ¬ification.GitHub.Deployment.RequiredContexts, - AutoMerge: ¬ification.GitHub.Deployment.AutoMerge, + AutoMerge: notification.GitHub.Deployment.AutoMerge, }, ) if err != nil { diff --git a/pkg/services/github_test.go b/pkg/services/github_test.go index 3091c839..52ddbb4a 100644 --- a/pkg/services/github_test.go +++ b/pkg/services/github_test.go @@ -107,6 +107,7 @@ func TestGetTemplater_GitHub_Custom_Resource(t *testing.T) { } func TestGetTemplater_GitHub_Deployment(t *testing.T) { + f := false n := Notification{ GitHub: &GitHubNotification{ RepoURLPath: "{{.sync.spec.git.repo}}", @@ -117,7 +118,7 @@ func TestGetTemplater_GitHub_Deployment(t *testing.T) { EnvironmentURL: "https://argoproj.github.io", LogURL: "https://argoproj.github.io/log", RequiredContexts: []string{}, - AutoMerge: false, + AutoMerge: &f, }, }, } @@ -157,7 +158,7 @@ func TestGetTemplater_GitHub_Deployment(t *testing.T) { assert.Equal(t, "https://argoproj.github.io", notification.GitHub.Deployment.EnvironmentURL) assert.Equal(t, "https://argoproj.github.io/log", notification.GitHub.Deployment.LogURL) assert.Len(t, notification.GitHub.Deployment.RequiredContexts, 0) - assert.Equal(t, false, notification.GitHub.Deployment.AutoMerge) + assert.Equal(t, &f, notification.GitHub.Deployment.AutoMerge) } func TestNewGitHubService_GitHubOptions(t *testing.T) {