fix: broken automerge logic (#3591)

* fix automerge logic.

* address failing autoplan test with automerge
This commit is contained in:
Ross Strickland
2023-07-10 12:23:16 -05:00
committed by GitHub
parent dd32a792b7
commit 1c232b5f90
2 changed files with 6 additions and 9 deletions

View File

@@ -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
}

View File

@@ -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