Skip to content

Commit

Permalink
Fix default and docs
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Splain <[email protected]>
  • Loading branch information
mikesplain committed Aug 10, 2023
1 parent d9a0262 commit 898778a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/services/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
11 changes: 8 additions & 3 deletions pkg/services/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/github.go#L196-L197

Added lines #L196 - L197 were not covered by tests
} else {
notification.GitHub.Deployment.AutoMerge = g.Deployment.AutoMerge
}
notification.GitHub.Deployment.RequiredContexts = g.Deployment.RequiredContexts
}

Expand Down Expand Up @@ -305,7 +310,7 @@ func (g gitHubService) Send(notification Notification, _ Destination) error {
Ref: &notification.GitHub.revision,
Environment: &notification.GitHub.Deployment.Environment,
RequiredContexts: &notification.GitHub.Deployment.RequiredContexts,
AutoMerge: &notification.GitHub.Deployment.AutoMerge,
AutoMerge: notification.GitHub.Deployment.AutoMerge,

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/github.go#L313

Added line #L313 was not covered by tests
},
)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/services/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Expand All @@ -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,
},
},
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 898778a

Please sign in to comment.