Skip to content

[Repo Assist] refactor(proxy): extract writeDIFCForbidden helper#3067

Merged
lpcox merged 1 commit intomainfrom
repo-assist/refactor-difc-forbidden-helper-2026-04-02-b6b6117ef22af8f3
Apr 3, 2026
Merged

[Repo Assist] refactor(proxy): extract writeDIFCForbidden helper#3067
lpcox merged 1 commit intomainfrom
repo-assist/refactor-difc-forbidden-helper-2026-04-02-b6b6117ef22af8f3

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 2, 2026

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Extracts a writeDIFCForbidden package-level helper in internal/proxy/handler.go, replacing two inline httputil.WriteJSONResponse 403 calls that used an identical map[string]string{"message": ...} body shape.

Problem

As identified in #3053, handler.go had two near-identical inline 403 response blocks for DIFC policy violations (Phase 2 write-blocked and Phase 5 strict-mode block). If the response shape for DIFC violations changes (e.g. adding a code field), both call sites would need to be updated separately.

Change

Added writeDIFCForbidden(w http.ResponseWriter, message string) — a small private helper that centralises the DIFC 403 response — and replaced the two inline call sites with it.

// Before (duplicated in two places):
httputil.WriteJSONResponse(w, http.StatusForbidden, map[string]string{
    "message": fmt.Sprintf("DIFC policy violation: %s", reason),
})

// After:
writeDIFCForbidden(w, fmt.Sprintf("DIFC policy violation: %s", reason))

No behaviour change. The third 403 response in handler.go (line ~71, GraphQL shape with errors + data fields) uses a different body structure and is intentionally left as-is.

Test Status

⚠️ Infrastructure limitation: The CI build environment cannot download Go modules (network proxy access is blocked), so make agent-finished could not be run. The changes are:

  • Syntactically valid (gofmt clean)
  • No new imports added
  • Pure refactor — zero behaviour change

Closes #3053

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

Replace two inline httputil.WriteJSONResponse 403 calls in handler.go
with a package-level writeDIFCForbidden helper. This reduces duplication
and makes future changes to the DIFC violation response shape easier
(only one place to update).

Closes #3053

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review April 3, 2026 03:58
Copilot AI review requested due to automatic review settings April 3, 2026 03:58
@lpcox lpcox merged commit 0c81e47 into main Apr 3, 2026
4 checks passed
@lpcox lpcox deleted the repo-assist/refactor-difc-forbidden-helper-2026-04-02-b6b6117ef22af8f3 branch April 3, 2026 03:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors internal/proxy/handler.go to reduce duplicate DIFC 403 response handling by extracting a small helper function.

Changes:

  • Added a private writeDIFCForbidden(w, message) helper to centralize DIFC policy violation 403 JSON responses.
  • Replaced two duplicated inline httputil.WriteJSONResponse(..., http.StatusForbidden, map[string]string{"message": ...}) blocks with calls to the new helper.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Pattern: Repeated WriteJSONResponse 403 bodies in proxy/handler.go

2 participants