Skip to content

feat: clock

feat: clock #7

name: Claude Code Support
on:
pull_request:
types: [labeled]
jobs:
claude-support:
if: contains(github.event.label.name, 'claude-code-support')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
- name: Install dependencies
run: npm install
- name: Install Claude Code SDK
run: npm install -g @anthropic-ai/claude-code
- name: Fetch last GitHub Actions bot comment
id: fetch_bot_comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request?.number;
if (!prNumber) {
core.setFailed('PR number not found in context.');
return;
}
const issueComments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
});
const reviewComments = await github.paginate(github.rest.pulls.listReviewComments, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
per_page: 100,
});
const allComments = [
...issueComments.map(c => ({ type: 'issue', created_at: c.created_at, body: c.body, user: c.user, id: c.id })),
...reviewComments.map(c => ({ type: 'review', created_at: c.created_at, body: c.body, user: c.user, id: c.id })),
];
allComments.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
const botComments = allComments.filter(c => c.user?.login === 'github-actions[bot]');
if (botComments.length === 0) {
core.notice('No comments by github-actions[bot] found.');
return '';
}
const last = botComments[botComments.length - 1];
core.info(`Found ${botComments.length} comments by github-actions[bot]. Last comment id: ${last.id}`);
return last.body ?? '';
- name: Run Claude with last bot comment
env:
CLAUDE_PROMPT: ${{ steps.fetch_bot_comment.outputs.result }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
CLAUDE_CR_PROMPT=$(cat .ai/prompts/code-review-fix.md)
claude --append-system-prompt "$CLAUDE_CR_PROMPT" \
--print "$CLAUDE_PROMPT" \
--permission-mode "acceptEdits"
- name: Detect changes
id: detect_changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.detect_changes.outputs.changed == 'true'
uses: EndBug/add-and-commit@v9
with:
add: "-A"
default_author: github_actions
message: "chore: apply Claude suggestions"