Send pull request diffs from GitHub Actions
Send authorized pull request snapshots to Xajbar without checking out or executing pull request code.
Create a Pull request diff ingest token in the review workspace. Give it a label that identifies the repository, then save it as the GitHub Actions secret XAJBAR_REVIEW_TOKEN in that repository. Use this workflow only where the repository owner has approved sending diffs to Xajbar.
Add the following file at .github/workflows/xajbar-review.yml on your trusted default branch. Change main if you use another protected branch.
name: Xajbar PR evidence review
on:
pull_request_target:
branches: [main]
types: [opened, reopened, synchronize]
permissions:
pull-requests: read
jobs:
submit:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
timeout-minutes: 5
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
XAJBAR_REVIEW_TOKEN: ${{ secrets.XAJBAR_REVIEW_TOKEN }}
steps:
- name: Fetch and submit the authorized diff
shell: bash
run: |
set -euo pipefail
diff=$(mktemp)
trap 'rm -f "$diff"' EXIT
gh pr diff "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" > "$diff"
python3 - "$diff" <<'PY'
import hashlib
import json
import os
import sys
import urllib.error
import urllib.request
import uuid
with open(sys.argv[1], encoding="utf-8") as file:
evidence = file.read(80_001)
if not evidence.strip():
print("No PR diff to submit.")
sys.exit(0)
if len(evidence.encode("utf-16-le")) // 2 > 80_000:
sys.exit("PR diff exceeds the review limit. Review a scoped excerpt in Xajbar.")
digest = hashlib.sha256(evidence.encode()).hexdigest()
scope = os.environ["GITHUB_REPOSITORY"] + ":" + os.environ["PR_NUMBER"]
snapshot_id = str(uuid.uuid5(uuid.NAMESPACE_URL, f"xajbar:pull-request:{scope}:{digest}"))
request = urllib.request.Request(
"https://xajbar.imbios.dev/api/review-ingest",
data=json.dumps({
"id": snapshot_id,
"evidence": evidence,
"pullRequest": int(os.environ["PR_NUMBER"]),
}, ensure_ascii=False).encode(),
headers={
"Authorization": "Bearer " + os.environ["XAJBAR_REVIEW_TOKEN"],
"Content-Type": "application/json",
},
method="POST",
)
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args, **kwargs):
return None
try:
with urllib.request.build_opener(NoRedirect()).open(request, timeout=30) as response:
report = json.load(response)
except urllib.error.HTTPError as error:
sys.exit(f"Xajbar rejected the snapshot (HTTP {error.code}).")
print(f"Xajbar saved review {report['id']} with {report['findings']} findings.")
PYThe job reads the diff through GitHub's API and submits it as text. Keep the job free of checkout steps, untrusted dependencies, and shell commands built from pull request fields. Fork pull requests are skipped. If a diff contains material outside your approved sharing scope, use the workspace to submit a redacted excerpt.
A successful workflow run confirms that Xajbar saved the report. Open Review history to triage findings and verification steps. A repeated submission of the same diff for the same pull request returns the existing report. Comparisons use the repository label and pull request number. Give each repository a distinct label. Reports from older workflows that omit the number remain in history. A finding absent from a later diff still needs verification before you treat it as fixed.
GitHub Actions event reference · GitHub CLI diff reference
GitHub App pilot
The Xajbar operator can connect a repository after its owner approves sharing diffs. This connection requires a GitHub App installation and an active Pull request diff source. Contact hi@imbios.dev for pilot setup.
- Register the GitHub App with read access to Pull requests and subscribe to Pull request events. Set the webhook URL to
https://xajbar.imbios.dev/api/review-ingest/githuband configure a webhook secret. Install the app on the selected repository. - In the production API secret store, set
GITHUB_REVIEW_APP_ID,GITHUB_REVIEW_PRIVATE_KEY, andGITHUB_REVIEW_WEBHOOK_SECRET. The private key can be supplied as a PEM string with escaped newlines. - In Continuous coverage, expand GitHub App source ID under the approved Pull request diff source. Set
GITHUB_REVIEW_BINDINGSto a JSON array with numericinstallationId, numericrepositoryId, and that UUID assourceId. Keep each repository and source unique in the bindings. - Open or update a same-repository pull request. Confirm a successful delivery in GitHub and a report for the correct asset and pull request in Review history.
Xajbar reads the latest changed-file patches at delivery time using only pull request read access. Repeated deliveries with the same patches reuse the saved report. Xajbar skips forks, pull requests with more than 100 changed files, and patches that are incomplete or exceed the input limit. GitHub records failed deliveries for inspection and redelivery. Replace the source when its token expires. Revoking the source stops new intake and keeps existing reports.