Repository navigation
ci(guardian): post reviews as the codegraph-brain GitHub App when configured #735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
71b6f4f
7f55f0c
a6e3bbe
fc9daf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,9 @@ jobs: | |
| github.event.issue.pull_request != null && | ||
| github.event.comment.body == '/guardian review' | ||
| runs-on: ubuntu-latest | ||
| # Below the app token's one-hour lifetime (#734): a review cannot outlive | ||
| # the token it posts with. | ||
| timeout-minutes: 45 | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
@@ -98,6 +101,25 @@ jobs: | |
| git show origin/data/guardian-metrics:guardian_metrics.jsonl \ | ||
| > guardian_metrics.jsonl 2>/dev/null || true | ||
|
|
||
| # Post as the codegraph-brain GitHub App when it is configured (#734): | ||
| # set vars.GUARDIAN_APP_CLIENT_ID and secrets.GUARDIAN_APP_PRIVATE_KEY. | ||
| # With the variable unset this step is skipped and posting uses | ||
| # GITHUB_TOKEN, as before. With it set, a missing key, a wrong key or an | ||
| # app not installed here fails the job before any LLM call: no silent | ||
| # fallback to another identity. The app's key reaches every repository | ||
| # the app is installed on, so the token is narrowed to this one and to | ||
| # pull-requests: write, and only the two posting steps read it. It lives | ||
| # one hour; the job's timeout-minutes keeps the review inside that. | ||
| - name: Mint GitHub App token | ||
| id: app-token | ||
| if: vars.GUARDIAN_APP_CLIENT_ID != '' | ||
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 | ||
| with: | ||
| client-id: ${{ vars.GUARDIAN_APP_CLIENT_ID }} | ||
| private-key: ${{ secrets.GUARDIAN_APP_PRIVATE_KEY }} | ||
| repositories: ${{ github.event.repository.name }} | ||
| permission-pull-requests: write | ||
|
|
||
| - name: Run Guardian Review | ||
| id: guardian | ||
| env: | ||
|
|
@@ -109,7 +131,7 @@ jobs: | |
| # Thinking depth for an anthropic finder or skeptic; unset = the | ||
| # provider's default ("low"). #246 J measured the finder at "medium". | ||
| GUARDIAN_ANTHROPIC_EFFORT: ${{ vars.GUARDIAN_ANTHROPIC_EFFORT }} | ||
| GH_TOKEN: ${{ github.token }} | ||
| GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }} | ||
| GITHUB_REPOSITORY: ${{ github.repository }} | ||
| GUARDIAN_FEATURES: ${{ vars.GUARDIAN_FEATURES }} | ||
| GUARDIAN_SKEPTIC: ${{ vars.GUARDIAN_SKEPTIC }} | ||
|
|
@@ -147,6 +169,7 @@ jobs: | |
| if: steps.guardian.outputs.posted_inline != 'true' | ||
| uses: peter-evans/create-or-update-comment@a111a2c3bacd7be7898ee22d0d71d9aec2bb972c # v4 | ||
| with: | ||
| token: ${{ steps.app-token.outputs.token || github.token }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 [Logic Bug] — Token expiry can silently drop the fallback comment for long reviews The app token is minted before the review and lasts one hour, so a review that runs past that window would leave both the inline post and the fallback comment failing with an authentication error and no report posted. Fix: Mint the token immediately before each posting step, or have the fallback step fall back to github.token when the app token request fails.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in fc9daf5: the review job has |
||
| issue-number: ${{ env.PR_NUMBER }} | ||
| body-path: guardian_report.md | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 [Library Contract] — App token narrowed to pull-requests only may break the review step's GitHub reads
The minted app token requests only permission-pull-requests: write, so any contents read the review step performs through GH_TOKEN (for example gh api on repository files) would fail once the app token is in use, while github.token worked before.
Fix: Confirm every gh call in the Run Guardian Review step needs only pull-request access, or add permission-contents: read to the create-github-app-token step and extend the permissions test accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change needed. The only GitHub call the review step makes with GH_TOKEN is
POST repos/{repo}/pulls/{pr}/reviews(src/cgis/guardian/github_poster.py:128). The diff and the files come from local git in pr/. GitHub's permission table lists that endpoint under Pull requests: write, and the fallbackissues.createCommenton a PR is covered by the same permission. The independent review of this PR checked both against the docs.