-
Notifications
You must be signed in to change notification settings - Fork 37
135 lines (120 loc) · 5.22 KB
/
reviewer-bot.yml
File metadata and controls
135 lines (120 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Reviewer Bot
on:
# Trigger when issues are opened, labeled, or closed
issues:
types: [opened, labeled, closed]
# Trigger when PRs are opened, labeled, or closed
# Using pull_request_target to handle PRs from forks with write permissions
pull_request_target:
types: [opened, labeled, closed]
# Trigger on comments for bot commands
issue_comment:
types: [created]
# Trigger on PR review submissions
pull_request_review:
types: [submitted]
# Nightly check for overdue reviews (runs at 9 AM UTC daily)
schedule:
- cron: '0 9 * * *'
# Allow manual triggering (useful for testing/debugging)
workflow_dispatch:
inputs:
action:
description: 'Action to perform'
required: true
default: 'sync-members'
type: choice
options:
- sync-members
- show-state
- check-overdue
permissions:
issues: write
pull-requests: write
contents: write
env:
# Issue number where bot state is stored (create this issue first!)
# The issue should be pinned and titled something like "📊 Reviewer Bot State"
STATE_ISSUE_NUMBER: "314"
jobs:
reviewer-bot:
runs-on: ubuntu-latest
# Skip if:
# - Comment is from a bot (prevent infinite loops)
# - The issue/PR being acted on is the state issue itself (314)
# Always run for schedule events
if: >
github.event_name == 'schedule' ||
github.event_name == 'workflow_dispatch' ||
((github.event_name != 'issue_comment' || github.event.comment.user.type != 'Bot') &&
((github.event.issue.number || github.event.pull_request.number || 0) != 314))
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Run reviewer bot
id: bot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STATE_ISSUE_NUMBER: ${{ env.STATE_ISSUE_NUMBER }}
# Pass event context to the script
EVENT_NAME: ${{ github.event_name }}
EVENT_ACTION: ${{ github.event.action }}
# Issue/PR context
ISSUE_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}
ISSUE_TITLE: ${{ github.event.issue.title || github.event.pull_request.title }}
ISSUE_AUTHOR: ${{ github.event.issue.user.login || github.event.pull_request.user.login }}
ISSUE_HTML_URL: ${{ github.event.issue.html_url || github.event.pull_request.html_url }}
IS_PULL_REQUEST: ${{ github.event.pull_request != null || (github.event.issue.pull_request != null) }}
# Label context (for labeled events)
LABEL_NAME: ${{ github.event.label.name }}
# Comment context (for issue_comment events)
COMMENT_BODY: ${{ github.event.comment.body }}
COMMENT_AUTHOR: ${{ github.event.comment.user.login }}
COMMENT_ID: ${{ github.event.comment.id }}
# Review context (for pull_request_review events)
REVIEW_STATE: ${{ github.event.review.state }}
REVIEW_AUTHOR: ${{ github.event.review.user.login }}
PR_IS_CROSS_REPOSITORY: ${{ github.event.pull_request != null && github.event.pull_request.head.repo.full_name != github.repository }}
# For manual dispatch
MANUAL_ACTION: ${{ github.event.inputs.action }}
# Repository info
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
WORKFLOW_RUN_ID: ${{ github.run_id }}
WORKFLOW_NAME: ${{ github.workflow }}
WORKFLOW_JOB_NAME: ${{ github.job }}
# Labels on the issue/PR (as JSON)
ISSUE_LABELS: ${{ toJson(github.event.issue.labels.*.name || github.event.pull_request.labels.*.name) }}
run: |
uv run python scripts/reviewer_bot.py
- name: Write reconcile context artifact
if: ${{ success() && github.event_name == 'pull_request_review' && github.event.action == 'submitted' }}
env:
RECONCILE_CONTEXT_PATH: ${{ runner.temp }}/reviewer-bot/reconcile-context.json
RECONCILE_EVENT_NAME: ${{ github.event_name }}
RECONCILE_EVENT_ACTION: ${{ github.event.action }}
RECONCILE_PR_NUMBER: ${{ github.event.pull_request.number }}
RECONCILE_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
RECONCILE_SOURCE_RUN_ID: ${{ github.run_id }}
run: |
mkdir -p "$(dirname "${RECONCILE_CONTEXT_PATH}")"
cat > "${RECONCILE_CONTEXT_PATH}" <<EOF
{
"schema_version": 1,
"event_name": "${RECONCILE_EVENT_NAME}",
"event_action": "${RECONCILE_EVENT_ACTION}",
"pr_number": ${RECONCILE_PR_NUMBER},
"head_sha": "${RECONCILE_HEAD_SHA}",
"source_run_id": ${RECONCILE_SOURCE_RUN_ID}
}
EOF
- name: Upload reconcile context artifact
if: ${{ success() && github.event_name == 'pull_request_review' && github.event.action == 'submitted' }}
uses: actions/upload-artifact@v4
with:
name: reviewer-bot-reconcile-context-${{ github.run_id }}
path: ${{ runner.temp }}/reviewer-bot/reconcile-context.json
retention-days: 1
if-no-files-found: error