-
Notifications
You must be signed in to change notification settings - Fork 41
159 lines (145 loc) · 5.47 KB
/
pr-ai-review.yml
File metadata and controls
159 lines (145 loc) · 5.47 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: AgentCore Harness Reviewing
on:
pull_request_target:
types: [opened, reopened]
workflow_dispatch:
inputs:
pr_url:
description: 'GitHub PR URL to review (e.g. https://github.com/org/repo/pull/123)'
required: true
type: string
permissions:
id-token: write
pull-requests: write
contents: read
jobs:
authorize:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request_target'
outputs:
authorized: ${{ steps.auth.outputs.authorized }}
steps:
- name: Check authorization
id: auth
if: github.event_name == 'pull_request_target'
uses: actions/github-script@v9
with:
script: |
const user = context.payload.pull_request.user.login;
try {
// Try team membership first (works for org repos)
await github.rest.teams.getMembershipForUserInOrg({
org: context.repo.owner,
team_slug: 'agentcore-cli-devs',
username: user,
});
console.log(`${user} is a member of agentcore-cli-devs`);
core.setOutput('authorized', 'true');
} catch (teamError) {
// Fall back to collaborator write access (works for personal repos)
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: user,
});
const hasWriteAccess = ['write', 'admin'].includes(data.permission);
if (hasWriteAccess) {
console.log(`${user} has write access (${data.permission})`);
core.setOutput('authorized', 'true');
} else {
console.log(`${user} does not have write access (${data.permission}) — skipping review`);
core.setOutput('authorized', 'false');
}
} catch (collabError) {
console.log(`${user} authorization check failed (${collabError.status}) — skipping review`);
core.setOutput('authorized', 'false');
}
}
- name: Auto-authorize workflow_dispatch
id: dispatch-auth
if: github.event_name == 'workflow_dispatch'
run: echo "authorized=true" >> "$GITHUB_OUTPUT"
ai-review:
needs: authorize
if: needs.authorize.outputs.authorized == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Determine PR URL
id: pr-url
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "url=${{ inputs.pr_url }}" >> "$GITHUB_OUTPUT"
else
echo "url=${{ github.event.pull_request.html_url }}" >> "$GITHUB_OUTPUT"
fi
- name: Extract PR number
id: pr-number
run: |
PR_URL="${{ steps.pr-url.outputs.url }}"
PR_NUM="${PR_URL##*/}"
echo "number=$PR_NUM" >> "$GITHUB_OUTPUT"
- name: Add agentcore-harness-reviewing label
uses: actions/github-script@v9
with:
script: |
const prNumber = parseInt('${{ steps.pr-number.outputs.number }}');
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'agentcore-harness-reviewing',
});
} catch (e) {
if (e.status === 404) {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'agentcore-harness-reviewing',
color: '7B61FF',
description: 'AgentCore Harness review in progress',
});
}
}
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['agentcore-harness-reviewing'],
});
- name: Checkout
uses: actions/checkout@v6
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.HARNESS_AWS_ROLE_ARN }}
aws-region: us-east-1
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install uv and dependencies
uses: astral-sh/setup-uv@v7
- name: Install boto3
run: uv pip install --system boto3
- name: Run AI review
env:
PR_URL: ${{ steps.pr-url.outputs.url }}
HARNESS_ARN: ${{ secrets.HARNESS_ARN }}
run: python .github/harness/harness_review.py
- name: Remove agentcore-harness-reviewing label
if: always()
uses: actions/github-script@v9
with:
script: |
const prNumber = parseInt('${{ steps.pr-number.outputs.number }}');
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: 'agentcore-harness-reviewing',
});
} catch (error) {
console.log('Label removal failed (may not exist):', error.message);
}