Skip to content

chore: setup repository for npm publishing #7

chore: setup repository for npm publishing

chore: setup repository for npm publishing #7

Workflow file for this run

# ---
# id: opencode/opencode-pr
# category: opencode
# type: set
# name: OpenCode AI PR Review
# description: Automated AI-powered code review for pull requests using OpenCode
# secrets:
# - name: KIMI_API_KEY
# description: API key for OpenCode AI service
# required: true
# inputs: []
# triggers: [pull_request]
# variants:
# - name: standard
# description: Uses standard GitHub Actions with direct API calls
# - name: nix
# description: Uses Nix for reproducible environment
# ---
name: OpenCode AI PR Review
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
review:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get PR diff
id: diff
run: |
git diff origin/${{ github.base_ref }}...HEAD > pr_diff.txt
echo "diff_path=pr_diff.txt" >> $GITHUB_OUTPUT
- name: Get previous review comments
id: previous-comments
uses: actions/github-script@v7
with:
script: |
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const opencodeComments = comments.data.filter(c =>
c.user.login === 'github-actions[bot]' &&
c.body.includes('OpenCode AI Review')
);
return opencodeComments.map(c => c.body).join('\n---\n');
- name: Run OpenCode AI Review
env:
KIMI_API_KEY: ${{ secrets.KIMI_API_KEY }}
PR_DIFF: ${{ steps.diff.outputs.diff_path }}
PREVIOUS_COMMENTS: ${{ steps.previous-comments.outputs.result }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_DESCRIPTION: ${{ github.event.pull_request.body }}
run: |
# Read the diff file
DIFF_CONTENT=$(cat "$PR_DIFF")
# Create the review prompt
PROMPT=$(cat <<EOF
You are an expert code reviewer. Review the following pull request:
Title: $PR_TITLE
Description: $PR_DESCRIPTION
Previous Review Context:
$PREVIOUS_COMMENTS

Check failure on line 78 in .github/workflows/opencode-pr.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/opencode-pr.yml

Invalid workflow file

You have an error in your yaml syntax on line 78
Code Changes:
\`\`\`diff
$DIFF_CONTENT
\`\`\`
Provide a structured review with:
1. Overall assessment (merge-ready, needs changes, etc.)
2. Critical issues (if any)
3. High-priority improvements
4. Medium-priority suggestions
5. Low-priority nitpicks
6. Confidence score (0-100)
Format as markdown with clear headers.
EOF
)
# Call OpenCode AI API
curl -X POST https://api.opencode.ai/v1/chat/completions \
-H "Authorization: Bearer $KIMI_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"kimi-latest\",
\"messages\": [{\"role\": \"user\", \"content\": $(echo "$PROMPT" | jq -Rs .)}]
}" > review_response.json
# Extract and post review
REVIEW_TEXT=$(cat review_response.json | jq -r '.choices[0].message.content')
echo "$REVIEW_TEXT" > review_output.txt
cat review_output.txt
- name: Post review comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const reviewText = fs.readFileSync('review_output.txt', 'utf8');
const formattedReview = `## OpenCode AI Review 🤖\n\n${reviewText}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: formattedReview
});