fix: use GitHub API for diff fetching, avoid shell diff command #5
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
riley/codetether-action!5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/diff-unrecognized-option-git"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
PR #506 in spotlessbinco (and any repo using this action) fails with:
The action relied solely on
git difffor gathering PR diffs. On some GitHub Actions runner images, this can interact with environment quirks that cause the systemdiffcommand to be invoked with--gitflags it doesn't understand.Fix
Primary: GitHub API diff — Uses
Accept: application/vnd.github.v3.diffto fetch the diff directly from the GitHub API. No local tooling dependency, no shelldiffcommand involved.Secondary: git diff — Falls back to
git diffonly when the API is unavailable (e.g., private repos with restricted token scopes).Safer PROMPT construction — Reads diff content into a bash variable before embedding in the prompt string, rather than using inline `` inside a double-quoted string that also contains backtick-heavy markdown fencing. This avoids bash parsing edge-cases where
diff --githeaders in the diff content could interact with backtick escaping.Testing
git diffImpact
fix: prevent checkout price mismatches (Issue #505)Code Review
This pull request updates the diff gathering logic to prioritize the GitHub API over local git commands, reducing dependencies on runner environments. It also refactors prompt construction to avoid bash parsing issues when handling raw diff text. Feedback suggests extending the API-first logic to the
apply_fixfunction for consistency and optimizing thecurlimplementation by streaming output directly to a file to better handle large diffs and avoid memory overhead.@ -37,0 +53,4 @@fi# ── Secondary: local git diff ────────────────────────────────────if [ "${api_ok}" != "true" ]; thenStreaming the
curloutput directly to a file is more efficient than capturing it in a bash variable, especially for large diffs, as it avoids memory overhead and potential variable size limits in bash.Additionally, note that the GitHub API returns the full PR diff, whereas the fallback
git diffcommand (lines 58-60) filters for specific file extensions (e.g.,.rs,.py,.ts). This inconsistency means that when the API is used, the prompt may include files (like lockfiles or documentation) that were previously excluded. Consider if you should apply similar filtering to the API output or if this expanded context is intentional.The
apply_fixfunction still relies solely ongit diff(line 198) to gather the current state before applying changes. Since the primary goal of this PR is to avoid issues with the localdiffcommand on certain runner images, this function should be updated to use the same GitHub API-first logic implemented ingather_diff. Otherwise, theapply_fixflow will continue to fail in the environments this PR aims to support.Pull request overview
Updates the local-mode diff collection and prompt construction in the GitHub Action to avoid runner-specific failures caused by relying on local diff tooling, by preferring GitHub’s PR
.diffAPI with agit difffallback.Changes:
Accept: application/vnd.github.v3.diff), falling back togit diffwhen unavailable.💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@ -37,0 +45,4 @@2>>"${CODETETHER_LOG_FILE}" || true)"if [ -n "${api_diff}" ]; thenprintf '%s' "${api_diff}" > "${DIFF_FILE}"api_ok="true"Switching to the GitHub API
.diffendpoint changes behavior vs the previousgit diffcall: the API response includes all files in the PR, while the old implementation filtered by pathspec (e.g.*.rs,*.py,*.ts, etc.). This makes it easier for large/generated/non-code diffs (lockfiles, vendor, etc.) to consume the 3000-line budget and crowd out relevant code changes. Consider reintroducing equivalent filtering (or explicitly documenting that the API mode intentionally reviews all file types).@ -37,0 +48,4 @@api_ok="true"checkpoint "local: GitHub API diff fetched ($({ wc -l < "${DIFF_FILE}"; } 2>/dev/null || echo 0) lines)"elselog_warn "GitHub API diff returned empty — using git diff instead"The GitHub API diff is captured into the
api_diffbash variable before writing to disk. For large PRs this can consume a lot of memory (and can fail) before the later 3000-line truncation happens. Prefer streaming curl output directly toDIFF_FILE(e.g.,curl ... -o "$DIFF_FILE") and then checking the file is non-empty / has lines before settingapi_ok=true.