name: opencode on: # Trigger on issue/PR comments for manual requests issue_comment: types: [created] # Trigger on PR events for automatic reviews pull_request: types: [opened, synchronize, ready_for_review] # Trigger on PR review requests for re-reviews pull_request_review: types: [submitted] jobs: # Handle opencode execution via comments opencode: if: | github.event_name == 'issue_comment' && ( contains(github.event.comment.body, ' /oc') || startsWith(github.event.comment.body, '/oc') || contains(github.event.comment.body, ' /opencode') || startsWith(github.event.comment.body, '/opencode') ) runs-on: ubuntu-latest permissions: contents: write pull-requests: write issues: write id-token: write steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - name: Run opencode uses: sst/opencode/github@latest env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} with: model: anthropic/claude-sonnet-4-20250514 # Automatically create review comment when PR is opened auto-review-trigger: if: | github.event_name == 'pull_request' && ( github.event.action == 'opened' || github.event.action == 'ready_for_review' ) && !github.event.pull_request.draft runs-on: ubuntu-latest permissions: pull-requests: write steps: - name: Create auto-review comment uses: actions/github-script@v7 with: script: | const { owner, repo } = context.repo; const issue_number = context.payload.pull_request.number; await github.rest.issues.createComment({ owner, repo, issue_number, body: '/opencode @review Please review this PR. Check for code quality, potential bugs, security issues, and adherence to best practices. Provide constructive feedback and suggestions for improvement.' }); # Automatically trigger re-review when requested re-review-trigger: if: | github.event_name == 'pull_request_review' && github.event.review.state == 'commented' && ( contains(github.event.review.body, 're-review') || contains(github.event.review.body, 'check again') || contains(github.event.review.body, 'review again') ) runs-on: ubuntu-latest permissions: pull-requests: write steps: - name: Create re-review comment uses: actions/github-script@v7 with: script: | const { owner, repo } = context.repo; const issue_number = context.payload.pull_request.number; await github.rest.issues.createComment({ owner, repo, issue_number, body: '/opencode @review Please re-review this PR based on the latest changes. Focus on the recent updates and provide feedback on improvements made since the last review.' });