Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

ai-review.yml

105 lines3.9 KB

1name: AI review
2​
3# In-process Grok review bot. Checks out this repo's default branch for the
4# script, then fetches the PR head into a second worktree for read/edit.
5# Never pull_request_target. Never pnpm install in the PR tree.
6​
7on:
8 pull_request:
9 types: [opened, synchronize, ready_for_review, labeled]
10 workflow_dispatch:
11 inputs:
12 pr_number:
13 description: Pull request number
14 required: true
15 type: string
16 issue_comment:
17 types: [created]
18​
19concurrency:
20 group: ai-review-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
21 cancel-in-progress: true
22​
23permissions: {}
24​
25jobs:
26 review:
27 name: Review
28 if: >
29 (github.event_name == 'pull_request'
30 && github.event.action != 'labeled'
31 && github.event.pull_request.draft == false
32 && github.event.pull_request.user.login != 'AlemTuzlak'
33 && github.event.pull_request.user.login != 'tombeckenham'
34 && github.event.pull_request.user.login != 'jherr')
35 || (github.event_name == 'pull_request'
36 && github.event.action == 'labeled'
37 && github.event.label.name == 'ai-review'
38 && (github.event.sender.login == 'AlemTuzlak'
39 || github.event.sender.login == 'tombeckenham'
40 || github.event.sender.login == 'jherr'))
41 || github.event_name == 'workflow_dispatch'
42 || (github.event_name == 'issue_comment'
43 && github.event.issue.pull_request
44 && startsWith(github.event.comment.body, '/ai-review'))
45 runs-on: ubuntu-latest
46 timeout-minutes: 30
47 permissions:
48 contents: read
49 steps:
50 - name: Checkout
51 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
52 with:
53 fetch-depth: 0
54 persist-credentials: false
55 - name: Setup Tools
56 uses: TanStack/config/.github/setup@190f659075ff0845850e330883eb26d7ffd0671f # main
57 - name: Build packages
58 run: pnpm exec nx run @tanstack/ai-grok-build:build
59 - name: Add PR head worktree
60 env:
61 AI_REVIEW_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }}
62 XAI_API_KEY: ${{ secrets.XAI_API_KEY }}
63 GH_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }}
64 EVENT_NAME: ${{ github.event_name }}
65 PR_NUMBER_PULL: ${{ github.event.pull_request.number }}
66 PR_NUMBER_ISSUE: ${{ github.event.issue.number }}
67 PR_NUMBER_DISPATCH: ${{ github.event.inputs.pr_number }}
68 shell: bash
69 run: |
70 if [ -z "${AI_REVIEW_TOKEN}" ] || [ -z "${XAI_API_KEY}" ]; then
71 echo "missing AI_REVIEW_TOKEN or XAI_API_KEY"
72 exit 1
73 fi
74 case "${EVENT_NAME}" in
75 pull_request)
76 PR_NUMBER="${PR_NUMBER_PULL}"
77 ;;
78 issue_comment)
79 PR_NUMBER="${PR_NUMBER_ISSUE}"
80 ;;
81 workflow_dispatch)
82 PR_NUMBER="${PR_NUMBER_DISPATCH}"
83 ;;
84 *)
85 echo "unsupported event ${EVENT_NAME}"
86 exit 1
87 ;;
88 esac
89 if ! [[ "${PR_NUMBER}" =~ ^[0-9]+$ ]]; then
90 echo "invalid PR number"
91 exit 1
92 fi
93 git fetch origin "pull/${PR_NUMBER}/head:ai-review-pr-head"
94 git worktree add "${GITHUB_WORKSPACE}/.pr-head" ai-review-pr-head
95 SHA="$(git -C "${GITHUB_WORKSPACE}/.pr-head" rev-parse HEAD)"
96 LOGIN="$(gh api "repos/${GITHUB_REPOSITORY}/commits/${SHA}" --jq '.author.login // empty' || true)"
97 MACHINE="$(gh api user --jq .login)"
98 echo "AI_REVIEW_HEAD_COMMIT_AUTHOR=${LOGIN}" >> "${GITHUB_ENV}"
99 echo "AI_REVIEW_MACHINE_USER=${MACHINE}" >> "${GITHUB_ENV}"
100 - name: Run review
101 run: pnpm ai-review
102 env:
103 AI_REVIEW_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }}
104 XAI_API_KEY: ${{ secrets.XAI_API_KEY }}
105 AI_REVIEW_WORKTREE: ${{ github.workspace }}/.pr-head