darrenhinde 7 months ago
parent
commit
2339935930
1 changed files with 18 additions and 56 deletions
  1. 18 56
      .github/workflows/opencode.yml

+ 18 - 56
.github/workflows/opencode.yml

@@ -1,31 +1,25 @@
 name: opencode
 name: opencode
 
 
 on:
 on:
-  # Trigger on issue/PR comments for manual requests
   issue_comment:
   issue_comment:
     types: [created]
     types: [created]
-  
-  # Trigger on PR events for automatic reviews
   pull_request:
   pull_request:
-    types: [opened, synchronize, ready_for_review]
-    
-  # Trigger on PR review requests for re-reviews
-  pull_request_review:
-    types: [submitted]
+    types: [opened, ready_for_review]
+
+env:
+  REVIEW_PROMPT: "Please review this PR for code quality, bugs, and best practices."
 
 
 jobs:
 jobs:
-  # Handle opencode execution via comments
   opencode:
   opencode:
     if: |
     if: |
       github.event_name == 'issue_comment' && (
       github.event_name == 'issue_comment' && (
-        contains(github.event.comment.body, ' /oc') ||
+        contains(github.event.comment.body, '/oc ') ||
         startsWith(github.event.comment.body, '/oc') ||
         startsWith(github.event.comment.body, '/oc') ||
-        contains(github.event.comment.body, ' /opencode') ||
+        contains(github.event.comment.body, '/opencode ') ||
         startsWith(github.event.comment.body, '/opencode')
         startsWith(github.event.comment.body, '/opencode')
       )
       )
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     permissions:
     permissions:
-      contents: write
       pull-requests: write
       pull-requests: write
       issues: write
       issues: write
       id-token: write
       id-token: write
@@ -33,63 +27,31 @@ jobs:
       - name: Checkout repository
       - name: Checkout repository
         uses: actions/checkout@v4
         uses: actions/checkout@v4
         with:
         with:
-          fetch-depth: 0
+          fetch-depth: 1
 
 
       - name: Run opencode
       - name: Run opencode
-        uses: sst/opencode/github@latest
+        uses: sst/opencode/github@v0.5.27
         env:
         env:
           ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
           ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
         with:
         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.'
-            });
+          model: claude-3-5-sonnet-20241022
 
 
-  # Automatically trigger re-review when requested
-  re-review-trigger:
+  auto-review:
     if: |
     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')
-      )
+      github.event_name == 'pull_request' &&
+      (github.event.action == 'opened' || github.event.action == 'ready_for_review') &&
+      !github.event.pull_request.draft
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     permissions:
     permissions:
       pull-requests: write
       pull-requests: write
     steps:
     steps:
-      - name: Create re-review comment
+      - name: Request review
         uses: actions/github-script@v7
         uses: actions/github-script@v7
         with:
         with:
           script: |
           script: |
-            const { owner, repo } = context.repo;
-            const issue_number = context.payload.pull_request.number;
-            
             await github.rest.issues.createComment({
             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.'
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              issue_number: context.payload.pull_request.number,
+              body: `/oc ${process.env.REVIEW_PROMPT}`
             });
             });