/ opengrammar / .github / workflows / auto-review.yml
Swadhin Biswas feat(ci): update reviewer identity to Swadhin Biswas Β· 3/7/2026
e865633
110 lines Β· 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: SARAS AI Code Reviewer

on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  review:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
      issues: write
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Bun
        uses: oven-sh/setup-bun@v1
        with:
          bun-version: latest

      - name: Technical Analysis
        id: analysis
        run: |
          echo "πŸ” SARAS AI is analyzing the architecture..."
          echo "" > errors.log
          
          cd opengrammar/shared && bun install >> /dev/null 2>&1
          cd ../backend && bun install >> /dev/null 2>&1
          bun x tsc --noEmit > ../../backend_errors.log 2>&1 || echo "BACKEND_FAILED" >> ../../errors.log
          
          cd ../extension && bun install >> /dev/null 2>&1
          bun x tsc --noEmit > ../../extension_errors.log 2>&1 || echo "EXTENSION_FAILED" >> ../../errors.log
          
          cd ../..
          if grep -q "FAILED" errors.log; then
            echo "status=failed" >> $GITHUB_OUTPUT
          else
            echo "status=success" >> $GITHUB_OUTPUT
          fi

      - name: Process Review as Swadhin Biswas
        uses: actions/github-script@v7
        with:
          # Using your PAT makes the review come from "Swadhin Biswas"
          github-token: ${{ secrets.SARAS_TOKEN || secrets.GITHUB_TOKEN }}
          script: |
            const fs = require('fs');
            const status = '${{ steps.analysis.outputs.status }}';
            const isSuccess = status === 'success';
            
            const owner = 'swadhinbiswas';
            const repo = 'opengrammar';
            const pull_number = context.payload.pull_request.number;
            
            let report = '';
            if (isSuccess) {
              report = `### βœ… Code Review Approved
              
              I have verified the changes for the SARAS Digital Intelligence system.
              
              - **Architecture:** Optimized for Bun runtime.
              - **Type Safety:** 100% verified via TSC.
              - **Status:** Production-ready.
              
              **Reviewer Profile:** swadhinbiswas <[email protected]>`;
              
              try {
                await github.rest.pulls.createReview({
                  owner,
                  repo,
                  pull_number,
                  event: 'APPROVE',
                  body: report
                });
              } catch (e) {
                // Fallback to comment if token isn't providing full review access
                await github.rest.issues.createComment({
                  owner,
                  repo,
                  issue_number: pull_number,
                  body: report
                });
              }
            } else {
              let backendErrors = fs.existsSync('backend_errors.log') ? fs.readFileSync('backend_errors.log', 'utf8') : '';
              let extensionErrors = fs.existsSync('extension_errors.log') ? fs.readFileSync('extension_errors.log', 'utf8') : '';
              
              backendErrors = backendErrors.split('\n').slice(0, 10).join('\n');
              extensionErrors = extensionErrors.split('\n').slice(0, 10).join('\n');
              
              report = `### ❌ Changes Requested
              
              Technical inconsistencies detected:
              
              ${backendErrors ? '#### πŸ–₯️ Backend Errors:\n```\n' + backendErrors + '\n```' : ''}
              ${extensionErrors ? '#### 🧩 Extension Errors:\n```\n' + extensionErrors + '\n```' : ''}
              
              **Reviewer Profile:** swadhinbiswas <[email protected]>`;
              
              await github.rest.issues.createComment({
                owner,
                repo,
                issue_number: pull_number,
                body: report
              });
              
              process.exit(1);
            }