Skip to content

ci(doc-drift): use GitHub App token and harden workflow#101

Merged
oshorefueled merged 3 commits into
mainfrom
docs/review-workflow
Jul 14, 2026
Merged

ci(doc-drift): use GitHub App token and harden workflow#101
oshorefueled merged 3 commits into
mainfrom
docs/review-workflow

Conversation

@oshorefueled

@oshorefueled oshorefueled commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

The /check-docs doc drift workflow failed with 403 Resource not accessible by integration because issue_comment-triggered runs on a public repo downgrade GITHUB_TOKEN to read-only, even when the permissions: block requests issues: write. This PR swaps all write paths to a GitHub App installation token so comment posting works regardless of trigger event or repo visibility.

Also broadens the authorization guard to allow OWNER and MEMBER associations (admins were being rejected as MEMBER), skips bot accounts at the trigger level, and inlines the agent message builder so the workflow no longer fetches and executes tsx via npx at runtime.

Branch Target

  • This PR targets release-docs because it updates docs for the latest released CLI and should be published now.
  • This PR targets main because it describes unreleased or in-development behavior.

Verification

  • I verified the docs are accurate for the branch I am targeting.

Prerequisites before first run:

  • Create a GitHub App with Issues: write, Pull requests: write, Contents: read repository permissions, installed on TRocket-Labs/vectorlint.
  • Add APP_ID and APP_PRIVATE_KEY repository secrets.

To verify:

  • Comment /check-docs on a PR → workflow runs, posts 👀 reaction and drift report.
  • Comment as a non-member → rejection comment posts successfully.
  • Comment from a bot account → workflow does not trigger.

Summary by CodeRabbit

  • New Features
    • Doc-drift checks now run only when a pull request comment begins with /check-docs.
    • Repository members can trigger authorized documentation checks.
  • Bug Fixes
    • Improved authentication for documentation checks using short-lived access tokens.
    • Updated workflow messaging and reporting behavior for clearer status and failure notifications.
  • Chores
    • Simplified the documentation-check workflow by generating instructions directly during execution.

- Replace GITHUB_TOKEN with a per-job GitHub App installation token so
  issue_comment-triggered comment writes survive the public-repo token
  downgrade that returned 403 on the authorization step
- Allow OWNER and MEMBER author associations to trigger /check-docs so
  repo admins are no longer rejected as unauthorized commenters
- Skip any commenter whose login contains [bot] at the job-if level so
  bot accounts cannot trigger the workflow at all
- Replace the npx tsx invocation of build-doc-drift-message.ts with an
  inline bash heredoc so the workflow no longer fetches and executes a
  runtime-downloaded TypeScript tool on each run
- Produce byte-identical prompt output to the original script
- Remove the now-unused GITHUB_WORKSPACE env override on the step
- Replace the act-only test workflow's tsx invocation with the same
  inline bash heredoc used in the production workflow
- Delete .github/scripts/build-doc-drift-message.ts, now that neither
  workflow references it, so no runtime-fetched tool is executed
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The doc-drift workflow now filters bot comments, permits owners and members, uses a GitHub App token for GitHub operations, and generates agent instructions inline. The standalone message-builder script was removed, and the workflow test was updated accordingly.

Changes

Doc-drift workflow

Layer / File(s) Summary
Comment authorization and token setup
.github/workflows/doc-drift.yml
Bot comments are excluded, owners and members are authorized, and a GitHub App token is used for authorization, reactions, and PR SHA retrieval.
Diff processing and report publication
.github/workflows/doc-drift.yml, tests/workflows/docs-drift-test.yml
The workflow fetches diffs and posts comments with the app token, while generating /tmp/pi-message.txt inline instead of invoking the removed TypeScript script.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHub as GitHub PR comment
  participant Workflow as doc-drift workflow
  participant GitHubAPI as GitHub API
  participant Agent as doc-drift agent
  GitHub->>Workflow: /check-docs comment
  Workflow->>GitHubAPI: Generate app token and fetch PR diff
  Workflow->>Agent: Provide inline instructions and diff path
  Agent-->>Workflow: Produce report files
  Workflow->>GitHubAPI: Post report or failure comment
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: switching the doc-drift workflow to a GitHub App token and hardening it.
Description check ✅ Passed The description follows the template with Summary, Branch Target, and Verification, and includes the required selections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/review-workflow

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
.github/workflows/doc-drift.yml (2)

11-15: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Prefer user.type for bot filtering.

While checking for [bot] in the login is a common heuristic, GitHub provides a direct type field on user objects which is more robust and prevents false positives if a normal user login happens to contain that substring.

Consider using github.event.comment.user.type != 'Bot' instead.

💡 Proposed change
     # Only run on PR comments that start with /check-docs (skip bots)
     if: |
       github.event.issue.pull_request != null &&
       startsWith(github.event.comment.body, '/check-docs') &&
-      !contains(github.event.comment.user.login, '[bot]')
+      github.event.comment.user.type != 'Bot'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/doc-drift.yml around lines 11 - 15, Update the workflow
condition guarding the /check-docs comment handler to filter bots using
github.event.comment.user.type != 'Bot' instead of checking whether the login
contains '[bot]'. Preserve the existing pull-request and command-prefix checks.

167-170: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Prevent pipefail from crashing the script if no reports are found.

Although the doc-drift agent is contracted to always output a report (even if no issues are found), if the agent unexpectedly produces no output, the intended graceful fallback (if [ -z "$REPORT_FILES" ]) will never execute. Because GitHub Actions runs bash with set -o pipefail, ls returning a non-zero exit code when no files match will immediately crash the step, bypassing the targeted comment and triggering the generic failure comment instead.

Appending || true to the pipeline ensures the script continues and posts the specific fallback message.

🛠️ Proposed fix
         env:
           GH_TOKEN: ${{ steps.app-token.outputs.token }}
         run: |
-          REPORT_FILES=$(ls "$GITHUB_WORKSPACE"/pr/.doc-drift-*.md 2>/dev/null | sort -V)
+          REPORT_FILES=$(ls "$GITHUB_WORKSPACE"/pr/.doc-drift-*.md 2>/dev/null | sort -V || true)
           if [ -z "$REPORT_FILES" ]; then
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/doc-drift.yml around lines 167 - 170, Update the
REPORT_FILES assignment in the workflow step to tolerate the no-match case under
pipefail by appending a successful fallback to the ls/sort pipeline. Preserve
the existing empty-value check and graceful fallback behavior that follows.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In @.github/workflows/doc-drift.yml:
- Around line 11-15: Update the workflow condition guarding the /check-docs
comment handler to filter bots using github.event.comment.user.type != 'Bot'
instead of checking whether the login contains '[bot]'. Preserve the existing
pull-request and command-prefix checks.
- Around line 167-170: Update the REPORT_FILES assignment in the workflow step
to tolerate the no-match case under pipefail by appending a successful fallback
to the ls/sort pipeline. Preserve the existing empty-value check and graceful
fallback behavior that follows.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1291b118-3b50-42ef-ade7-a865e86dd4c2

📥 Commits

Reviewing files that changed from the base of the PR and between 13d072c and 7bb6c41.

📒 Files selected for processing (3)
  • .github/scripts/build-doc-drift-message.ts
  • .github/workflows/doc-drift.yml
  • tests/workflows/docs-drift-test.yml
💤 Files with no reviewable changes (1)
  • .github/scripts/build-doc-drift-message.ts

@oshorefueled
oshorefueled merged commit ec39c67 into main Jul 14, 2026
3 checks passed
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.

1 participant