Skip to content

Commit 4b614f1

Browse files
committed
WIP [2026-01-14 15:26:10]
1 parent 7c4a00a commit 4b614f1

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

.github/workflows/pr-review-command.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,123 @@ jobs:
7575
- name: Checkout repository
7676
uses: actions/checkout@v4
7777

78+
- name: Get PR details
79+
id: pr-details
80+
uses: actions/github-script@v7
81+
with:
82+
script: |
83+
const prNumber = ${{ needs.check-comment.outputs.pr_number }};
84+
85+
const { data: pr } = await github.rest.pulls.get({
86+
owner: context.repo.owner,
87+
repo: context.repo.repo,
88+
pull_number: prNumber
89+
});
90+
91+
const { data: files } = await github.rest.pulls.listFiles({
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
pull_number: prNumber
95+
});
96+
97+
core.setOutput('pr_title', pr.title);
98+
core.setOutput('pr_author', pr.user.login);
99+
core.setOutput('files_changed', files.length);
100+
101+
console.log(`PR #${prNumber}: ${pr.title}`);
102+
console.log(`Author: ${pr.user.login}`);
103+
console.log(`Files changed: ${files.length}`);
104+
105+
- name: Check if API key is available
106+
id: check-key
107+
run: |
108+
if [ -n "${{ secrets.ANTHROPIC_API_KEY }}" ]; then
109+
echo "has_key=true" >> $GITHUB_OUTPUT
110+
else
111+
echo "has_key=false" >> $GITHUB_OUTPUT
112+
fi
113+
78114
- name: Run PR Reviewer Agent
115+
if: steps.check-key.outputs.has_key == 'true'
79116
id: review
80117
uses: docker/cagent-action@1f7ec0445e138a587639fc9c046076e22d184349 # v1.0.4
81118
with:
82119
agent: agentcatalog/github-action-pr-reviewer:2.0.0
83120
mcp-gateway: true
84121
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
85122
github-token: ${{ secrets.GITHUB_TOKEN }}
123+
env:
124+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
125+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86126
continue-on-error: true
87127

128+
- name: Simulated Review (No API Key)
129+
if: steps.check-key.outputs.has_key == 'false'
130+
id: simulated-review
131+
run: |
132+
echo "## 🤖 Simulated PR Review"
133+
echo ""
134+
echo "**Note:** This is a test run without the Anthropic API key."
135+
echo ""
136+
echo "### PR Details"
137+
echo "- **Title:** ${{ steps.pr-details.outputs.pr_title }}"
138+
echo "- **Author:** @${{ steps.pr-details.outputs.pr_author }}"
139+
echo "- **Files Changed:** ${{ steps.pr-details.outputs.files_changed }}"
140+
echo ""
141+
echo "### Workflow Status"
142+
echo "✅ Workflow triggered successfully"
143+
echo "✅ PR details retrieved"
144+
echo "✅ Permissions verified"
145+
echo ""
146+
echo "**To enable AI review:** Add \`ANTHROPIC_API_KEY\` to repository secrets"
147+
148+
- name: Post review comment
149+
uses: actions/github-script@v7
150+
with:
151+
script: |
152+
const hasKey = '${{ steps.check-key.outputs.has_key }}' === 'true';
153+
const prNumber = ${{ needs.check-comment.outputs.pr_number }};
154+
155+
let body;
156+
if (hasKey) {
157+
body = `## 🤖 AI PR Review Complete
158+
159+
The automated PR review has been completed by the AI agent.
160+
161+
**Triggered by:** ${{ github.event_name === 'workflow_dispatch' ? 'Manual trigger' : github.event_name === 'pull_request' ? 'PR update' : '@' + github.event.comment.user.login }}
162+
**Workflow Run:** [View Details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
163+
`;
164+
} else {
165+
body = `## 🤖 PR Review Test (Simulated)
166+
167+
✅ **Workflow Test Successful!**
168+
169+
### PR Details
170+
- **Title:** ${{ steps.pr-details.outputs.pr_title }}
171+
- **Author:** @${{ steps.pr-details.outputs.pr_author }}
172+
- **Files Changed:** ${{ steps.pr-details.outputs.files_changed }}
173+
174+
### Status
175+
✅ Workflow triggered correctly
176+
✅ PR details retrieved successfully
177+
✅ Permissions verified
178+
179+
**Triggered by:** ${{ github.event_name === 'workflow_dispatch' ? 'Manual trigger' : github.event_name === 'pull_request' ? 'PR update' : '@' + github.event.comment.user.login }}
180+
**Workflow Run:** [View Details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
181+
182+
---
183+
184+
⚠️ **Note:** To enable full AI-powered reviews, add \`ANTHROPIC_API_KEY\` to repository secrets.
185+
`;
186+
}
187+
188+
await github.rest.issues.createComment({
189+
owner: context.repo.owner,
190+
repo: context.repo.repo,
191+
issue_number: prNumber,
192+
body: body
193+
});
194+
88195
- name: Add success reaction
89196
if: success() && github.event_name == 'issue_comment'
90197
uses: actions/github-script@v7

0 commit comments

Comments
 (0)