test workflow #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Claude PR Assistant | |
on: | |
issue_comment: | |
types: [created] | |
pull_request_review_comment: | |
types: [created] | |
issues: | |
types: [opened, assigned] | |
pull_request_review: | |
types: [submitted] | |
jobs: | |
claude-code-action: | |
if: | | |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || | |
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || | |
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || | |
(github.event_name == 'pull_request' && contains(github.event.review.body, '@claude')) || | |
(github.event_name == 'issues' && contains(github.event.issue.body, '@claude')) | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: read | |
issues: read | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Install JSZip | |
run: npm install jszip | |
- name: Get job log and extract error | |
id: get-error-log | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const runId = context.runId; | |
const pull_number = context.payload.pull_request?.number; | |
if (!pull_number) { | |
core.setFailed("No pull request number found."); | |
return; | |
} | |
// Get latest PR comments | |
const { data: comments } = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: pull_number, | |
per_page: 10, | |
}); | |
const jobIdRegex = /Job ID: (\d+)/; | |
const latestComment = comments.reverse().find(c => jobIdRegex.test(c.body)); | |
const match = latestComment?.body?.match(jobIdRegex); | |
if (!match) { | |
core.setFailed("No job ID found in latest comment."); | |
return; | |
} | |
const jobId = match[1]; | |
console.log(`Found Job ID: ${jobId}`); | |
// Get log archive URL | |
const { data: logZip } = await github.request( | |
`GET /repos/${context.repo.owner}/${context.repo.repo}/actions/jobs/${jobId}/logs` | |
); | |
const response = await fetch(logZip.url); | |
const buffer = await response.arrayBuffer(); | |
const JSZip = require("jszip"); | |
const zip = await JSZip.loadAsync(Buffer.from(buffer)); | |
let errorLines = []; | |
for (const filename of Object.keys(zip.files)) { | |
const file = zip.files[filename]; | |
if (!file.dir && filename.endsWith('.txt')) { | |
const content = await file.async('string'); | |
const lines = content.split('\n'); | |
for (const line of lines) { | |
if (line.toLowerCase().includes('error') || line.includes('✗')) { | |
errorLines.push(line.trim()); | |
} | |
} | |
} | |
} | |
const errors = errorLines.join('\n').slice(0, 10000); // Limit output to 10,000 chars | |
core.setOutput("errors", errors || "No errors found"); | |
#env: | |
# NODE_OPTIONS: "--no-experimental-fetch" | |
- name: Post captured errors | |
run: | | |
echo "Captured errors:" | |
echo "${{ steps.get-error-log.outputs.errors }}" | |
# - name: Run Claude PR Action | |
# uses: anthropics/claude-code-action@beta | |
# with: | |
# anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} | |
# timeout_minutes: "60" | |
# model: "claude-opus-4-20250514" |