Files
openobserve/.github/workflows/ai-code-review.yml
T
Shrinath Rao 503a7054fb feat(ci): rebrand automated PR review as "OpenObserve Code Reviewer" (#13871)
## What & why

Repackages our existing automated PR reviewer under a branded identity —
**OpenObserve Code Reviewer** — and gives its comment a colorful,
attention-grabbing format. This is **purely aesthetic + repackaging**.

> [!IMPORTANT]
> The review **engine is frozen**. The 5 specialist agents, coordinator
judgment/rubric, risk tiering, XML finding contract, re-review
PATCH-in-place logic, total-outage guard, DeepSeek/opencode wiring,
read-only security model, and OTel tracing are all **unchanged**. Only
*who signs the comment* and *how it looks* change.

## The two things that move

**1. Identity (fail-safe).** The workflow mints a GitHub App
installation token via `actions/create-github-app-token`, **gated on the
`OO_REVIEWER_APP_ID` variable**. If the app isn't configured, it skips
and falls back to `github.token` (posts as `github-actions[bot]`,
exactly as today). So this PR is **safe to merge before the app exists**
and auto-activates once the secrets are provisioned.

**2. Presentation.** The coordinator now emits:
- Decision as a native GitHub **callout box** — 🟢 `[!TIP]` approved · 🔵
`[!NOTE]` approved-with-comments · 🟡 `[!WARNING]` minor · 🔴 `[!CAUTION]`
significant.
- Rebranded heading `## 🔎 OpenObserve Code Review`.
- Per-category glyphs 🔒 ⚡ 🧩 📝 📦 on each finding line.

`sanitizeReviewBody` normalizes the heading (tolerates a missing emoji /
legacy heading, idempotent on re-review) and the deterministic fallback
renderer gets the same cosmetic treatment.

## To activate the brand (one-time, org admin)

Register a GitHub App "OpenObserve Code Reviewer", install on this repo,
then set:
- Variable `OO_REVIEWER_APP_ID` (numeric App ID — this is the gate)
- Secret `OO_REVIEWER_APP_PRIVATE_KEY` (the app's `.pem`)

Remove the variable to instantly roll back to `github-actions[bot]`.

## Verification
- JS parses; both workflows valid YAML.
- Engine files byte-identical with the o2-enterprise counterpart PR.
- 6/6 sanitizer heading cases pass (fresh, no-emoji, legacy, preamble,
idempotent, trailing-words).
- This PR's own review comment will preview the new format.

Paired with the identical o2-enterprise PR (same branch name).
2026-08-19 12:07:03 +00:00

162 lines
7.1 KiB
YAML

name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_dispatch:
inputs:
pr_number:
description: "PR number to review"
required: true
type: string
force_full:
description: "Force full review tier (ignore risk assessment)"
required: false
type: boolean
default: false
jobs:
review:
runs-on: ubuntu-latest
timeout-minutes: 25
# Concurrency is per-job (not workflow-level) so it can see `matrix`: keyed per-PR AND
# per-provider, so provider legs get independent groups and don't cancel each other.
concurrency:
group: ai-review-${{ matrix.provider.name }}-${{ github.event.pull_request.number || github.event.inputs.pr_number }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
issues: write
actions: read
strategy:
# One provider's failure shouldn't sink the others.
fail-fast: false
matrix:
# DeepSeek-V4-Pro is the sole reviewer (the GLM-5.2 head-to-head has ended).
# Adding a provider? Also add its `marker` to ALL_REVIEW_MARKERS in run-review.mjs,
# or the other legs will claim and overwrite this one's comment.
provider:
- name: deepseek
label: DeepSeek-V4-Pro
provider_id: deepseek-review
model_id: deepseek-v4-pro
model_variant: ""
api_key_env: DEEPSEEK_API_KEY
marker: "<!-- ai-code-review-deepseek -->"
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 1
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
cache-dependency-path: scripts/ai-review/package-lock.json
- name: Install AI review dependencies
working-directory: scripts/ai-review
run: npm ci
- name: Install opencode
env:
# Pinned so an upstream opencode release can't silently change review behavior
# (agent/tool semantics, prompt handling) underneath this workflow. Bump
# deliberately after testing against scripts/ai-review locally.
OPENCODE_VERSION: "1.17.13"
run: |
curl -fsSL https://opencode.ai/install | bash -s -- --version "$OPENCODE_VERSION"
echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
- name: Set trace ID
run: echo "O2_TRACE_ID=$(openssl rand -hex 16)" >> "$GITHUB_ENV"
- name: Set PR number
id: pr
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "pr_number=${{ github.event.inputs.pr_number }}" >> "$GITHUB_OUTPUT"
else
echo "pr_number=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
fi
- name: Check for skip marker
id: skip
env:
GH_TOKEN: ${{ github.token }}
run: |
PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "skip_review=false" >> "$GITHUB_OUTPUT"
echo "force_full=${{ github.event.inputs.force_full || 'false' }}" >> "$GITHUB_OUTPUT"
exit 0
fi
# Check PR body and comments for skip markers
PR_BODY=$(gh pr view "$PR_NUMBER" --json body --jq '.body' 2>/dev/null || echo "")
COMMENTS=$(gh api "repos/${{ github.repository }}/issues/$PR_NUMBER/comments" --jq '.[].body' 2>/dev/null || echo "")
if echo "$PR_BODY$COMMENTS" | grep -qiE '\[skip (ai )?review\]|\[skip ci\]|break glass'; then
echo "Skip marker found. Skipping AI review."
echo "skip_review=true" >> "$GITHUB_OUTPUT"
else
echo "skip_review=false" >> "$GITHUB_OUTPUT"
fi
echo "force_full=false" >> "$GITHUB_OUTPUT"
# Mint a GitHub App installation token so the review comment is authored by the
# "OpenObserve Code Reviewer" app (branded name + avatar) instead of github-actions[bot].
# Gated on the OO_REVIEWER_APP_ID repo/org variable: if the app isn't configured the step is
# skipped. `continue-on-error` makes it fail-safe even when the variable IS set but the app
# isn't installed yet (or the key is wrong): minting fails, the token output is empty, and
# the run step's `|| github.token` fallback posts as github-actions[bot] instead of breaking
# CI. So this is safe at every rollout stage; it auto-activates once the app is installed and
# OO_REVIEWER_APP_ID + OO_REVIEWER_APP_PRIVATE_KEY are provisioned.
- name: Generate OpenObserve Code Reviewer app token
id: app_token
if: ${{ steps.skip.outputs.skip_review == 'false' && vars.OO_REVIEWER_APP_ID != '' }}
continue-on-error: true
# Pinned to a full commit SHA (not a mutable tag) because this action receives the app's
# signing private key — a repointed/compromised release could exfiltrate it. Same pin
# discipline as OPENCODE_VERSION above. Bump deliberately after review.
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2.2.2
with:
app-id: ${{ vars.OO_REVIEWER_APP_ID }}
private-key: ${{ secrets.OO_REVIEWER_APP_PRIVATE_KEY }}
- name: Run AI Code Review
if: steps.skip.outputs.skip_review == 'false'
env:
# App token when the app is configured (comment posts as OpenObserve Code Reviewer),
# else github.token (posts as github-actions[bot]). Same engine either way.
GH_TOKEN: ${{ steps.app_token.outputs.token || github.token }}
PR_NUMBER: ${{ steps.pr.outputs.pr_number }}
FORCE_FULL: ${{ steps.skip.outputs.force_full }}
# Provider selection for this matrix leg (see run-review.mjs for how these are used).
REVIEW_PROVIDER_ID: ${{ matrix.provider.provider_id }}
REVIEW_MODEL_ID: ${{ matrix.provider.model_id }}
REVIEW_MODEL_VARIANT: ${{ matrix.provider.model_variant }}
REVIEW_API_KEY_ENV: ${{ matrix.provider.api_key_env }}
REVIEW_LABEL: ${{ matrix.provider.label }}
REVIEW_MARKER: ${{ matrix.provider.marker }}
# run-review.mjs reads only the key named by REVIEW_API_KEY_ENV.
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
O2_TRACE_INGEST_URL: ${{ secrets.O2_TRACE_INGEST_URL }}
O2_TRACE_ORG: ${{ secrets.O2_TRACE_ORG }}
O2_TRACE_USERNAME: ${{ secrets.O2_TRACE_USERNAME }}
O2_TRACE_PASSWORD: ${{ secrets.O2_TRACE_PASSWORD }}
O2_TRACE_AUTH: ${{ secrets.O2_TRACE_AUTH }}
O2_TRACE_STREAM: ${{ secrets.O2_TRACE_STREAM }}
O2_TRACE_EXPORT_TIMEOUT_MS: ${{ vars.O2_TRACE_EXPORT_TIMEOUT_MS }}
O2_TRACE_EXPORT_BATCH_SIZE: ${{ vars.O2_TRACE_EXPORT_BATCH_SIZE }}
run: node scripts/ai-review/run-review.mjs
- name: Log skip
if: steps.skip.outputs.skip_review == 'true'
run: echo "AI Code Review skipped due to skip marker or break glass"