coderev-cli 1.0.21 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/cli.js +59 -0
- package/templates/github-action.yml +143 -0
package/README.md
CHANGED
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -640,6 +640,7 @@ program
|
|
|
640
640
|
.command('init')
|
|
641
641
|
.description('Create a default coderev config file')
|
|
642
642
|
.option('--gitlab-ci', 'Generate a .gitlab-ci.yml template for GitLab CI/CD review')
|
|
643
|
+
.option('--github-action', 'Generate a GitHub Actions workflow for PR review')
|
|
643
644
|
.action((options) => {
|
|
644
645
|
const fs = require('fs');
|
|
645
646
|
const path = require('path');
|
|
@@ -766,6 +767,64 @@ coderev-review:
|
|
|
766
767
|
console.log(chalk.blue(' 3. (Optional) Add GITLAB_TOKEN with api scope for MR comments'));
|
|
767
768
|
console.log(chalk.blue(' 4. Push to GitLab — coderev runs on every MR!'));
|
|
768
769
|
}
|
|
770
|
+
|
|
771
|
+
// --github-action: generate GitHub Actions workflow
|
|
772
|
+
if (options.githubAction) {
|
|
773
|
+
const gaDir = path.join(process.cwd(), '.github', 'workflows');
|
|
774
|
+
const gaPath = path.join(gaDir, 'coderev.yml');
|
|
775
|
+
if (fs.existsSync(gaPath)) {
|
|
776
|
+
console.log(chalk.yellow(`⚠ ${gaPath} already exists. Skipping.`));
|
|
777
|
+
} else {
|
|
778
|
+
const templatePath = path.join(__dirname, '..', 'templates', 'github-action.yml');
|
|
779
|
+
if (fs.existsSync(templatePath)) {
|
|
780
|
+
fs.mkdirSync(gaDir, { recursive: true });
|
|
781
|
+
fs.copyFileSync(templatePath, gaPath);
|
|
782
|
+
console.log(chalk.green(`✔ GitHub Actions workflow created at ${gaPath}`));
|
|
783
|
+
} else {
|
|
784
|
+
// Fallback: write minimal workflow
|
|
785
|
+
const gaContent = `name: coderev AI Code Review
|
|
786
|
+
|
|
787
|
+
on:
|
|
788
|
+
pull_request:
|
|
789
|
+
types: [opened, synchronize, reopened]
|
|
790
|
+
|
|
791
|
+
permissions:
|
|
792
|
+
contents: read
|
|
793
|
+
pull-requests: write
|
|
794
|
+
|
|
795
|
+
jobs:
|
|
796
|
+
coderev:
|
|
797
|
+
runs-on: ubuntu-latest
|
|
798
|
+
timeout-minutes: 10
|
|
799
|
+
steps:
|
|
800
|
+
- uses: actions/checkout@v4
|
|
801
|
+
with:
|
|
802
|
+
fetch-depth: 0
|
|
803
|
+
- uses: actions/setup-node@v4
|
|
804
|
+
with:
|
|
805
|
+
node-version: 20
|
|
806
|
+
- run: npm install -g coderev-cli
|
|
807
|
+
- run: |
|
|
808
|
+
git diff \${{ github.event.pull_request.base.sha }}...\${{ github.event.pull_request.head.sha }} > /tmp/coderev-pr.diff
|
|
809
|
+
- env:
|
|
810
|
+
DEEPSEEK_API_KEY: \${{ secrets.DEEPSEEK_API_KEY }}
|
|
811
|
+
run: |
|
|
812
|
+
cat /tmp/coderev-pr.diff | coderev review --output markdown --ci --min-confidence 60 > /tmp/coderev-report.md
|
|
813
|
+
- uses: marocchino/sticky-pull-request-comment@v2
|
|
814
|
+
with:
|
|
815
|
+
header: coderev-review
|
|
816
|
+
path: /tmp/coderev-report.md
|
|
817
|
+
`;
|
|
818
|
+
fs.mkdirSync(gaDir, { recursive: true });
|
|
819
|
+
fs.writeFileSync(gaPath, gaContent);
|
|
820
|
+
console.log(chalk.green(`✔ GitHub Actions workflow created at ${gaPath}`));
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
console.log(chalk.blue(' Next steps:'));
|
|
824
|
+
console.log(chalk.blue(' 1. Go to GitHub → Settings → Secrets and variables → Actions'));
|
|
825
|
+
console.log(chalk.blue(' 2. Add secret DEEPSEEK_API_KEY with your API key'));
|
|
826
|
+
console.log(chalk.blue(' 3. Push to GitHub — coderev reviews every PR!'));
|
|
827
|
+
}
|
|
769
828
|
});
|
|
770
829
|
|
|
771
830
|
// ── Serve (GitHub App) ────────────────────────────────────────────
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# coderev — Multi-Agent AI Code Review for GitHub Actions
|
|
2
|
+
# Quick start:
|
|
3
|
+
# 1. Copy this file to .github/workflows/coderev.yml
|
|
4
|
+
# Or run: npx coderev-cli init --github-action
|
|
5
|
+
# 2. Set Secrets: DEEPSEEK_API_KEY in Settings → Secrets and variables → Actions
|
|
6
|
+
# 3. (Optional) Set GITHUB_TOKEN is auto-provided, no setup needed
|
|
7
|
+
#
|
|
8
|
+
# Usage:
|
|
9
|
+
# - Review on every PR: default trigger
|
|
10
|
+
# - Block merging on issues: enable CODEREV_BLOCK or comment with coderev status
|
|
11
|
+
#
|
|
12
|
+
# Variables (set in workflow or as env):
|
|
13
|
+
# CODEREV_PROVIDER AI provider (default: deepseek)
|
|
14
|
+
# CODEREV_MODEL Model name (default: deepseek-chat)
|
|
15
|
+
# CODEREV_CONFIDENCE Minimum confidence 0-100 (default: 60)
|
|
16
|
+
# CODEREV_BLOCK Block PR on issues (default: false)
|
|
17
|
+
# CODEREV_BLAME Enable git blame context (default: false)
|
|
18
|
+
# CODEREV_MODE Review mode: comment | check (default: comment)
|
|
19
|
+
|
|
20
|
+
name: coderev AI Code Review
|
|
21
|
+
|
|
22
|
+
on:
|
|
23
|
+
pull_request:
|
|
24
|
+
types: [opened, synchronize, reopened]
|
|
25
|
+
workflow_dispatch:
|
|
26
|
+
inputs:
|
|
27
|
+
ref:
|
|
28
|
+
description: 'Git ref to review (branch/commit)'
|
|
29
|
+
required: false
|
|
30
|
+
|
|
31
|
+
permissions:
|
|
32
|
+
contents: read
|
|
33
|
+
pull-requests: write
|
|
34
|
+
checks: write
|
|
35
|
+
|
|
36
|
+
jobs:
|
|
37
|
+
coderev:
|
|
38
|
+
name: AI Code Review
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
timeout-minutes: 10
|
|
41
|
+
|
|
42
|
+
steps:
|
|
43
|
+
- name: Checkout
|
|
44
|
+
uses: actions/checkout@v4
|
|
45
|
+
with:
|
|
46
|
+
fetch-depth: 0
|
|
47
|
+
|
|
48
|
+
- name: Setup Node.js
|
|
49
|
+
uses: actions/setup-node@v4
|
|
50
|
+
with:
|
|
51
|
+
node-version: 20
|
|
52
|
+
|
|
53
|
+
- name: Install coderev
|
|
54
|
+
run: npm install -g coderev-cli
|
|
55
|
+
|
|
56
|
+
- name: Generate diff
|
|
57
|
+
id: diff
|
|
58
|
+
run: |
|
|
59
|
+
if [ -n "${{ github.event.pull_request.base.sha }}" ]; then
|
|
60
|
+
git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} > /tmp/coderev-pr.diff
|
|
61
|
+
else
|
|
62
|
+
git diff HEAD~1 > /tmp/coderev-pr.diff
|
|
63
|
+
fi
|
|
64
|
+
echo "Diff size: $(wc -c < /tmp/coderev-pr.diff) bytes"
|
|
65
|
+
|
|
66
|
+
- name: Run coderev review
|
|
67
|
+
id: review
|
|
68
|
+
env:
|
|
69
|
+
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
|
|
70
|
+
CODEREV_PROVIDER: ${{ env.CODEREV_PROVIDER || 'deepseek' }}
|
|
71
|
+
CODEREV_MODEL: ${{ env.CODEREV_MODEL || 'deepseek-chat' }}
|
|
72
|
+
run: |
|
|
73
|
+
BLAME_FLAG=""
|
|
74
|
+
if [ "${{ env.CODEREV_BLAME || 'false' }}" = "true" ]; then
|
|
75
|
+
BLAME_FLAG="--blame"
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
cat /tmp/coderev-pr.diff | coderev review \
|
|
79
|
+
--output markdown \
|
|
80
|
+
--ci $BLAME_FLAG \
|
|
81
|
+
--min-confidence ${{ env.CODEREV_CONFIDENCE || '60' }} \
|
|
82
|
+
> /tmp/coderev-report.md 2>/tmp/coderev-stderr.log
|
|
83
|
+
|
|
84
|
+
echo "Exit code: $?"
|
|
85
|
+
|
|
86
|
+
- name: Post review as PR comment
|
|
87
|
+
if: github.event_name == 'pull_request' && env.CODEREV_MODE != 'check'
|
|
88
|
+
uses: marocchino/sticky-pull-request-comment@v2
|
|
89
|
+
with:
|
|
90
|
+
header: coderev-review
|
|
91
|
+
path: /tmp/coderev-report.md
|
|
92
|
+
|
|
93
|
+
- name: Post review as GitHub Check
|
|
94
|
+
if: env.CODEREV_MODE == 'check'
|
|
95
|
+
uses: actions/github-script@v7
|
|
96
|
+
with:
|
|
97
|
+
script: |
|
|
98
|
+
const fs = require('fs');
|
|
99
|
+
const report = fs.readFileSync('/tmp/coderev-report.md', 'utf8');
|
|
100
|
+
|
|
101
|
+
// Parse score from report
|
|
102
|
+
const scoreMatch = report.match(/\*\*Score:\*\*\s*(\d+)\/100/);
|
|
103
|
+
const score = scoreMatch ? parseInt(scoreMatch[1]) : 0;
|
|
104
|
+
const conclusion = score >= 80 ? 'success' : score >= 50 ? 'neutral' : 'failure';
|
|
105
|
+
|
|
106
|
+
// Count issues
|
|
107
|
+
const issueMatches = report.match(/\*\*ERROR\*\*/g);
|
|
108
|
+
const warnMatches = report.match(/\*\*WARNING\*\*/g);
|
|
109
|
+
|
|
110
|
+
await github.rest.checks.create({
|
|
111
|
+
owner: context.repo.owner,
|
|
112
|
+
repo: context.repo.repo,
|
|
113
|
+
name: 'coderev AI Review',
|
|
114
|
+
head_sha: context.payload.pull_request?.head?.sha || context.sha,
|
|
115
|
+
status: 'completed',
|
|
116
|
+
conclusion: conclusion,
|
|
117
|
+
output: {
|
|
118
|
+
title: `Code Review: ${score}/100`,
|
|
119
|
+
summary: report.substring(0, 65535),
|
|
120
|
+
annotations: []
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
- name: Block on issues (optional)
|
|
125
|
+
if: env.CODEREV_BLOCK == 'true'
|
|
126
|
+
run: |
|
|
127
|
+
SCORE=$(grep -oP '\*\*Score:\*\*\s*\K\d+' /tmp/coderev-report.md || echo 0)
|
|
128
|
+
if [ "$SCORE" -lt 60 ]; then
|
|
129
|
+
echo "⛔ Score $SCORE/100 below threshold (60). Blocking PR."
|
|
130
|
+
cat /tmp/coderev-report.md
|
|
131
|
+
exit 1
|
|
132
|
+
fi
|
|
133
|
+
echo "✅ Score $SCORE/100 — passed."
|
|
134
|
+
|
|
135
|
+
- name: Upload review artifacts
|
|
136
|
+
if: always()
|
|
137
|
+
uses: actions/upload-artifact@v4
|
|
138
|
+
with:
|
|
139
|
+
name: coderev-report
|
|
140
|
+
path: |
|
|
141
|
+
/tmp/coderev-report.md
|
|
142
|
+
/tmp/coderev-stderr.log
|
|
143
|
+
retention-days: 7
|