Skip to content

fix: block merge on workspace block#67

Open
horakihor wants to merge 2 commits into
mainfrom
block-cli-for-merge
Open

fix: block merge on workspace block#67
horakihor wants to merge 2 commits into
mainfrom
block-cli-for-merge

Conversation

@horakihor

Copy link
Copy Markdown
Collaborator

Summary

When tfbuddy detects that a workspace's relevant paths were modified on the
target branch since the source branch diverged, it refuses to start a TFC run
for that workspace and posts a :no_entry: MR comment. However, it never
publishes a failing GitLab commit status
, so GitLab's required-status check
has nothing to fail on and the MR can still be merged.

This change publishes failing commit statuses for TFC/plan/<ws> and
TFC/apply/<ws> (both, to match the pre-emptive pattern in
mr_status_updater.go) so the merge gate fires.

Changes

  • pkg/vcs/interfaces.go — add SetMergeRequestStatus(ctx, project, sha, name, state, description, targetURL) error to GitClient. Primitive args keep the trigger code VCS-agnostic.
  • pkg/vcs/gitlab/client.go — implements the method: builds gogitlab.SetCommitStatusOptions and delegates to existing SetCommitStatus. Skips the 30s pipeline-lookup backoff used by run-status updates; a commit-level status is sufficient to gate the merge for blocked workspaces.
  • pkg/vcs/github/client.gonil stub consistent with the existing SetCommitStatus TODO.
  • pkg/tfc_trigger/tfc_trigger.godispatchWorkspaces now calls publishBlockedStatus(ctx, ws.Name) on the blocked branch, which sets TFC/plan/<ws>=failed and TFC/apply/<ws>=failed. Both are set so the merge gate fires regardless of which is the required status.
  • pkg/mocks/mock_vcs.go — regenerated via go generate ./pkg/vcs/....
  • pkg/tfc_trigger/tfc_trigger_test.goTestTFCEvents_WorkspaceApplyModifiedBothSrcDstBranches now asserts both SetMergeRequestStatus calls.

Rebase behavior

No explicit cleanup needed. A new commit means a new SHA; tfbuddy re-evaluates
on the push webhook:

  • Still blocked → publishes new failed statuses on the new SHA.
  • No longer blocked → the normal TFC run path replaces them via the existing pipeline (mr_status_updater.go).

horakihor added 2 commits June 2, 2026 19:30
Signed-off-by: Ihor Horak <ihor.horak@zapier.com>
Signed-off-by: Ihor Horak <ihor.horak@zapier.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ensures merge requests are properly gated when TFBuddy blocks a workspace due to target-branch drift by publishing failing commit statuses (so required-status checks can actually fail).

Changes:

  • Extend the VCS GitClient interface with SetMergeRequestStatus for publishing commit statuses without a TFC run.
  • Implement SetMergeRequestStatus for GitLab and invoke it when a workspace is blocked (publishing failed statuses for both TFC/plan/<ws> and TFC/apply/<ws>).
  • Regenerate mocks and update trigger tests to assert the new status publications.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/vcs/interfaces.go Adds SetMergeRequestStatus to the VCS client interface for merge gating.
pkg/vcs/gitlab/client.go Implements SetMergeRequestStatus by creating commit statuses without pipeline attachment.
pkg/vcs/github/client.go Adds a stub SetMergeRequestStatus implementation (currently TODO).
pkg/tfc_trigger/tfc_trigger.go Publishes failing plan/apply commit statuses when a workspace is blocked.
pkg/tfc_trigger/tfc_trigger_test.go Asserts SetMergeRequestStatus calls for blocked workspaces.
pkg/mocks/mock_vcs.go Regenerates GoMock bindings for the updated interface.
Files not reviewed (1)
  • pkg/mocks/mock_vcs.go: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/vcs/github/client.go
Comment on lines +352 to +355
func (c *Client) SetMergeRequestStatus(ctx context.Context, projectWithNS, commitSHA, name, state, description, targetURL string) error {
//TODO implement me
return nil
}
Comment on lines +468 to +475
func (t *TFCTrigger) publishBlockedStatus(ctx context.Context, workspace string) {
const description = "Blocked: target branch modified workspace paths since divergence."
for _, action := range []string{"plan", "apply"} {
name := fmt.Sprintf("TFC/%s/%s", action, workspace)
if err := t.gl.SetMergeRequestStatus(ctx, t.GetProjectNameWithNamespace(), t.GetCommitSHA(), name, "failed", description, ""); err != nil {
log.Error().Err(err).Str("ws", workspace).Str("action", action).Msg("could not publish blocked commit status")
}
}
Comment thread pkg/vcs/gitlab/client.go
Comment on lines +117 to +121
func (c *GitlabClient) SetMergeRequestStatus(ctx context.Context, projectWithNS, commitSHA, name, state, description, targetURL string) error {
_, span := otel.Tracer("TFC").Start(ctx, "SetMergeRequestStatus")
defer span.End()

opts := &gogitlab.SetCommitStatusOptions{
Comment thread pkg/vcs/interfaces.go
Comment on lines +19 to +20
// SetMergeRequestStatus publishes a commit status without a TFC run, used
// to gate the merge when tfbuddy refuses to run a workspace.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pkg/mocks/mock_vcs.go: Language not supported

Comment thread pkg/vcs/github/client.go
Comment on lines +352 to +355
func (c *Client) SetMergeRequestStatus(ctx context.Context, projectWithNS, commitSHA, name, state, description, targetURL string) error {
//TODO implement me
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants