Skip to content

Commit

Permalink
fix: broken automerge logic (#3591)
Browse files Browse the repository at this point in the history
* fix automerge logic.

* address failing autoplan test with automerge
  • Loading branch information
pseudomorph committed Jul 10, 2023
1 parent dd32a79 commit 1c232b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 2 additions & 6 deletions server/events/automerger.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ func (c *AutoMerger) automerge(ctx *command.Context, pullStatus models.PullStatu

// automergeEnabled returns true if automerging is enabled in this context.
func (c *AutoMerger) automergeEnabled(projectCmds []command.ProjectContext) bool {
// only automerge if all projects have automerge set; or if global automerge is set and there are no projects.
// Use project automerge settings if projects exist; otherwise, use global automerge settings.
automerge := c.GlobalAutomerge
if len(projectCmds) > 0 {
for _, prjCmd := range projectCmds {
if !prjCmd.AutomergeEnabled {
automerge = false
}
}
automerge = projectCmds[0].AutomergeEnabled
}
return automerge
}
Expand Down
7 changes: 4 additions & 3 deletions server/events/command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,16 +695,17 @@ func TestRunAutoplanCommandWithError_DeletePlans(t *testing.T) {
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
autoMerger.GlobalAutomerge = true
defer func() { autoMerger.GlobalAutomerge = false }()

When(projectCommandBuilder.BuildAutoplanCommands(Any[*command.Context]())).
ThenReturn([]command.ProjectContext{
{
CommandName: command.Plan,
CommandName: command.Plan,
AutomergeEnabled: true, // Setting this manually, since this tests bypasses automerge param reconciliation logic and otherwise defaults to false.
},
{
CommandName: command.Plan,
CommandName: command.Plan,
AutomergeEnabled: true, // Setting this manually, since this tests bypasses automerge param reconciliation logic and otherwise defaults to false.
},
}, nil)
callCount := 0
Expand Down

0 comments on commit 1c232b5

Please sign in to comment.