Skip to content

Commit

Permalink
auto merge if apply has no changes
Browse files Browse the repository at this point in the history
Signed-off-by: davidwin93 <[email protected]>
  • Loading branch information
davidwin93 committed Oct 19, 2023
1 parent 9afdb2d commit 6495533
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/vcs/github/run_events_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ func (w *RunEventsWorker) postRunStatusComment(ctx context.Context, run *tfe.Run
// The applying phase of a run has completed.
w.mergePRIfPossible(ctx, rmd)
}
if run.Status == tfe.RunPlannedAndFinished {
if len(run.TargetAddrs) > 0 {
return
}
if rmd.GetAction() == "apply" {
w.mergePRIfPossible(ctx, rmd)
}
}
}
func (w *RunEventsWorker) mergePRIfPossible(ctx context.Context, rmd runstream.RunMetadata) {
if !rmd.GetAutoMerge() {
Expand Down
6 changes: 5 additions & 1 deletion pkg/vcs/gitlab/mr_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ func (p *RunStatusUpdater) updateCommitStatusForRun(ctx context.Context, run *tf
// This is a final state.
p.updateStatus(ctx, gogitlab.Success, rmd.GetAction(), rmd)
if run.HasChanges {
// TODO: is pending enough to block merging before apply?
p.updateStatus(ctx, gogitlab.Pending, "apply", rmd)
} else {
// if the apply returns no changes we can still go ahead and merge if auto-merge is enabled
if rmd.GetAction() == "apply" {
p.mergeMRIfPossible(ctx, rmd)
}
}

case tfe.RunPolicySoftFailed:
Expand Down

0 comments on commit 6495533

Please sign in to comment.