Skip to content

Comments

[code-simplifier] refactor: extract execGHAPI helper in checks_command (#18164)#18197

Merged
pelikhan merged 1 commit intomainfrom
simplify-checks-command-gh-api-helper-32cfec648b6a4ddc
Feb 24, 2026
Merged

[code-simplifier] refactor: extract execGHAPI helper in checks_command (#18164)#18197
pelikhan merged 1 commit intomainfrom
simplify-checks-command-gh-api-helper-32cfec648b6a4ddc

Conversation

@github-actions
Copy link
Contributor

Code Simplification - 2026-02-24

This PR simplifies recently modified code from PR #18164 to improve clarity and reduce duplication while preserving all functionality.

Files Simplified

  • pkg/cli/checks_command.go — extracted execGHAPI helper to eliminate triplicated gh API call + error handling code

Improvements Made

Eliminated duplicated error handling pattern

fetchPRHeadSHA, fetchCheckRuns, and fetchCommitStatuses all contained identical boilerplate for:

  • appending --repo flag when set
  • calling workflow.ExecGH(...)
  • type-asserting *exec.ExitError to extract stderr
  • calling classifyGHAPIError

The new execGHAPI(repoOverride, context, args...) helper centralises this pattern. Each caller now simply:

  1. Calls execGHAPI with its endpoint URL
  2. Checks the error
  3. Parses the JSON response

This makes the intent of each fetch function immediately clear and eliminates ~18 lines of duplicated error-handling code.

Changes Based On

Recent code from:

Testing

  • gofmt passes — no formatting changes needed
  • ✅ No functional changes — all callers receive identical errors (same call sites to classifyGHAPIError)
  • ✅ Existing test coverage in pkg/cli/checks_command_test.go validates behavior

Review Focus

Please verify:

  • execGHAPI correctly handles the --repo append and error classification
  • All three callers (fetchPRHeadSHA, fetchCheckRuns, fetchCommitStatuses) behave identically to before
  • No unintended side effects from the variadic args append pattern

Automated by Code Simplifier Agent — analyzing code from the last 24 hours

Generated by Code Simplifier

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org
  • expires on Feb 25, 2026, 7:07 PM UTC

…licated error handling

The three gh API fetch functions (fetchPRHeadSHA, fetchCheckRuns,
fetchCommitStatuses) all shared identical patterns for building args,
calling workflow.ExecGH, handling exec.ExitError, and classifying API
errors. Extract a single execGHAPI helper that centralises this logic.

Each caller is now reduced to: build the URL, call execGHAPI, parse the
JSON response — making the intent of each function immediately clear.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
Copy link
Contributor

/q update code simplifier with network go domain.

@pelikhan pelikhan merged commit 76bbc11 into main Feb 24, 2026
@pelikhan pelikhan deleted the simplify-checks-command-gh-api-helper-32cfec648b6a4ddc branch February 24, 2026 20:25
@github-actions
Copy link
Contributor Author

Issue created: #18207

🎩 Equipped by Q

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.

1 participant