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 }}
XAJBAR_FAIL_ON_HIGH: ${{ vars.XAJBAR_FAIL_ON_HIGH }}
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.com/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}).")
try:
report_id = uuid.UUID(report["id"])
checks = report["checks"]
counts = report["severityCounts"]
high, medium, low = (counts[key] for key in ("high", "medium", "low"))
total = report["findings"]
if any(type(n) is not int or n < 0 for n in (checks, total, high, medium, low)):
raise ValueError()
if high + medium + low != total:
raise ValueError()
except (AttributeError, KeyError, TypeError, ValueError):
sys.exit("Xajbar returned an invalid review summary. Check the saved report in Xajbar.")
with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as summary:
summary.write(
"### Xajbar PR evidence review\n\n"
f"- Report ID: `{report_id}`\n"
f"- Checks in scope: {checks}\n"
f"- Findings: {high} high, {medium} medium, {low} low\n\n"
f"[Open saved report](https://xajbar.com/dashboard/reviews/{report_id})\n"
)
if checks == 0:
summary.write("\nNo checks applied to the submitted diff.\n")
if os.environ.get("XAJBAR_FAIL_ON_HIGH") == "true" and high > 0:
sys.exit("Xajbar reported high-severity findings. Review the workflow summary.")
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.
The workflow summary shows the saved report ID, the check count, and finding counts by severity. Select Open saved report to read verification steps and triage findings in the Xajbar account that issued the ingest token. To fail the workflow when it reports any high-severity findings, set the repository Actions variable XAJBAR_FAIL_ON_HIGH to true. Xajbar still saves the report. This workflow uses the base-branch context, so use its result for triage and review.
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 · Job summaries · 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.com/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.
By default, Xajbar reads the latest changed-file patches at delivery time using 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.
Register a GitHub App · Handle failed webhook deliveries
Verified merge tracking
Xajbar records the merge date when a signature-verified GitHub App delivery reports that a same-repository pull request was merged. The delivery must match the approved installation and numeric repository ID and use an active Pull request diff source. The merge event records metadata without requesting a diff or creating a report. Closed pull requests that were declined and fork pull requests are skipped.
The merge date appears on connected GitHub App snapshots, including scheduled reviews and directly linked reports. The connection is scoped to the Xajbar account and the approved source UUID, repository ID, and pull request number. A merge delivery can arrive before the report is saved. Revoking the source stops new deliveries from updating its reports and preserves dates already recorded. Replacement sources track merges under their own connection.
Tracking applies to GitHub App snapshots saved with this feature. Existing reports, GitHub Actions token submissions, and manual reviews have no verified merge status. Xajbar does not look up past merges.
Optional advisory GitHub Checks
After the repository owner approves publication, add "publishChecks": true to that repository's binding in GITHUB_REVIEW_BINDINGS. Checks are disabled unless the binding opts in. Set GITHUB_REVIEW_APP_ID to the numeric App ID so Xajbar can look up checks from its own app. The installation needs Contents read access for comparisons and Checks write access for publication. Check-enabled deliveries request just these permissions in a token restricted to the bound repository. Other webhook bindings and daily schedules continue to request Pull requests read access only.
Xajbar reviews the changed-file patches from GitHub's comparison of the full base and head commit SHAs in the signed same-repository delivery. It skips comparisons that exceed 100 changed files or 100 commits on the head side, include files without text patches, exceed the input limit, or return incomplete or ambiguous evidence. Daily reviews do not publish checks.
After the report is saved, Xajbar posts a completed, neutral Xajbar advisory review check on the reviewed head commit. It publishes rule and finding counts, the scope of the review, and a link to the report, which requires the report owner's Xajbar account. Keep this check out of branch protection and ruleset requirements. GitHub can treat a neutral conclusion as satisfying a required status check.
Repeated deliveries for the same source, pull request, and commit pair reuse the existing check. A replacement source publishes its own report link. If publication times out or GitHub returns an error, wait at least one minute before redelivering so Xajbar can look up the prior attempt. A check lookup whose first page cannot establish whether a matching run exists fails closed.
Optional line annotations
Get separate approval from the repository owner before adding "publishAnnotations": true to a binding. It requires "publishChecks": true in the same binding and uses the same permissions. Checks publish the summary by default. With annotations enabled, GitHub users who can view the check may also see repository-relative paths, line numbers, and static rule titles and remediation in the Checks and Files changed tabs.
Xajbar verifies each saved finding against an added line in the exact comparison and publishes a single warning per verified rule and location. Context, deleted lines, and findings with an unverified or ambiguous location are omitted. The outgoing annotations use file order from the comparison, then ascending head line number, up to 50 per check. The report keeps all findings and uses redacted file references. Annotation payloads exclude patch text and model output.
Changing this setting applies to new check runs only. Redelivery reuses any matching check with its original output. The check conclusion remains neutral, and read-only bindings and daily reviews continue to save reports only.
Daily pull request reviews
To review an approved open PR daily, set GITHUB_REVIEW_DAILY_SCHEDULE on the API service and redeploy it. Each entry needs a source UUID already present in GITHUB_REVIEW_BINDINGS, the repository name, a pull request number, and an hour in UTC.
[
{
"sourceId": "9f870d8b-b07c-4b2a-9afa-035ecba58f23",
"repository": "example/service",
"pullRequest": 42,
"utcHour": 2
}
]When the service runs at or after the configured hour, it reviews the PR once for that UTC date. The daily snapshot appears in Review history even when the patches are unchanged. The same checks and size limits apply to webhook and scheduled reviews. Closed PRs, fork PRs, and revoked or expired sources are skipped. A failed attempt becomes eligible for retry after ten minutes.
Remove an entry and redeploy the API to stop its schedule. You can revoke its source in the dashboard to stop new reviews immediately.