coderev-cli 1.0.19 → 1.0.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coderev-cli",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Multi-agent AI code review for git -- parallel agents with confidence scoring",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "files": [
37
37
  "src/",
38
+ "templates/",
38
39
  "README.md",
39
40
  ".env.example"
40
41
  ],
package/src/cli.js CHANGED
@@ -639,7 +639,8 @@ fi
639
639
  program
640
640
  .command('init')
641
641
  .description('Create a default coderev config file')
642
- .action(() => {
642
+ .option('--gitlab-ci', 'Generate a .gitlab-ci.yml template for GitLab CI/CD review')
643
+ .action((options) => {
643
644
  const fs = require('fs');
644
645
  const path = require('path');
645
646
  const defaultConfig = {
@@ -708,6 +709,63 @@ build/
708
709
  fs.writeFileSync(hintPath, hintContent);
709
710
  console.log(chalk.green(`✔ Default .coderevhint created at ${hintPath}`));
710
711
  }
712
+
713
+ // --gitlab-ci: generate GitLab CI template
714
+ if (options.gitlabCi) {
715
+ const ciPath = path.join(process.cwd(), '.gitlab-ci.yml');
716
+ if (fs.existsSync(ciPath)) {
717
+ console.log(chalk.yellow(`⚠ .gitlab-ci.yml already exists. Skipping.`));
718
+ } else {
719
+ const templatePath = path.join(__dirname, '..', 'templates', '.gitlab-ci.yml');
720
+ if (fs.existsSync(templatePath)) {
721
+ fs.copyFileSync(templatePath, ciPath);
722
+ console.log(chalk.green(`✔ GitLab CI template created at ${ciPath}`));
723
+ } else {
724
+ // Fallback: inline the template content
725
+ const ciContent = `# coderev — Multi-Agent AI Code Review for GitLab CI
726
+ # Quick start:
727
+ # 1. Set CI variable DEEPSEEK_API_KEY in GitLab → Settings → CI/CD → Variables
728
+ # 2. (Optional) Set GITLAB_TOKEN for auto-posting MR comments
729
+
730
+ stages:
731
+ - review
732
+
733
+ coderev-review:
734
+ stage: review
735
+ image: node:20-alpine
736
+ needs: []
737
+ rules:
738
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
739
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
740
+ when: never
741
+ before_script:
742
+ - npm install -g coderev-cli
743
+ - command -v git >/dev/null 2>&1 || apk add --no-cache git
744
+ script:
745
+ - |
746
+ if [ -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA" ]; then
747
+ git diff $CI_MERGE_REQUEST_DIFF_BASE_SHA...$CI_COMMIT_SHA > /tmp/coderev-mr.diff
748
+ else
749
+ git diff HEAD~1 > /tmp/coderev-mr.diff
750
+ fi
751
+ - cat /tmp/coderev-mr.diff | coderev review --output markdown --ci --min-confidence 60 > /tmp/coderev-output.md
752
+ - cat /tmp/coderev-output.md
753
+ artifacts:
754
+ when: always
755
+ paths:
756
+ - /tmp/coderev-output.md
757
+ expire_in: 7 days
758
+ `;
759
+ fs.writeFileSync(ciPath, ciContent);
760
+ console.log(chalk.green(`✔ GitLab CI template created at ${ciPath}`));
761
+ }
762
+ }
763
+ console.log(chalk.blue(' Next steps:'));
764
+ console.log(chalk.blue(' 1. Go to GitLab → Settings → CI/CD → Variables'));
765
+ console.log(chalk.blue(' 2. Add variable DEEPSEEK_API_KEY with your API key'));
766
+ console.log(chalk.blue(' 3. (Optional) Add GITLAB_TOKEN with api scope for MR comments'));
767
+ console.log(chalk.blue(' 4. Push to GitLab — coderev runs on every MR!'));
768
+ }
711
769
  });
712
770
 
713
771
  // ── Serve (GitHub App) ────────────────────────────────────────────
package/src/config.js CHANGED
@@ -9,8 +9,9 @@ const CONFIG_FILES = [
9
9
 
10
10
  const DEFAULTS = {
11
11
  ai: {
12
- provider: 'openai',
13
- model: 'gpt-4o',
12
+ provider: process.env.DEEPSEEK_API_KEY ? 'deepseek' : 'openai',
13
+ model: process.env.DEEPSEEK_API_KEY ? 'deepseek-chat' : 'gpt-4o',
14
+ apiKeyEnv: process.env.DEEPSEEK_API_KEY ? 'DEEPSEEK_API_KEY' : 'OPENAI_API_KEY',
14
15
  temperature: 0.3,
15
16
  maxTokens: 4096,
16
17
  },
@@ -0,0 +1,134 @@
1
+ # =============================================================================
2
+ # coderev — Multi-Agent AI Code Review for GitLab CI
3
+ # =============================================================================
4
+ #
5
+ # This template runs coderev on every merge request, using 3 parallel AI agents
6
+ # (Security / Bug / Quality) with confidence scoring.
7
+ #
8
+ # QUICK START:
9
+ # 1. Copy this file to your repo as .gitlab-ci.yml
10
+ # 2. Set CI variable DEEPSEEK_API_KEY in GitLab → Settings → CI/CD → Variables
11
+ # 3. (Optional) Set GITLAB_TOKEN for private repos or to post review comments
12
+ #
13
+ # VARIABLES (set in GitLab CI/CD Settings):
14
+ # DEEPSEEK_API_KEY (required) AI provider API key
15
+ # GITLAB_TOKEN (optional) GitLab PAT for posting MR comments (api scope)
16
+ # CODEREV_PROVIDER (optional) AI provider: deepseek | openai (default: deepseek)
17
+ # CODEREV_MODEL (optional) Model name (default: deepseek-chat)
18
+ # CODEREV_CONFIDENCE (optional) Min confidence 0-100 (default: 60)
19
+ # CODEREV_MODE (optional) Review mode: full | security | bugs | quality
20
+ # CODEREV_BLAME (optional) Enable git blame: "true" | "false" (default: false)
21
+ # CODEREV_BLOCK (optional) Block MR on issues: "true" | "false" (default: false)
22
+ # =============================================================================
23
+
24
+ stages:
25
+ - review
26
+
27
+ coderev-review:
28
+ stage: review
29
+ image: node:20-alpine
30
+ needs: []
31
+ rules:
32
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
33
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
34
+ when: never
35
+ before_script:
36
+ # Install coderev and dependencies
37
+ - npm install -g coderev-cli
38
+ # Ensure git is configured for diff generation
39
+ - command -v git >/dev/null 2>&1 || apk add --no-cache git
40
+ script:
41
+ # ── Generate MR diff ──
42
+ - |
43
+ echo "📋 Generating diff for merge request..."
44
+ if [ -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA" ]; then
45
+ git diff $CI_MERGE_REQUEST_DIFF_BASE_SHA...$CI_COMMIT_SHA > /tmp/coderev-mr.diff
46
+ elif [ -n "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA" ]; then
47
+ git diff $CI_MERGE_REQUEST_TARGET_BRANCH_SHA...$CI_COMMIT_SHA > /tmp/coderev-mr.diff
48
+ else
49
+ echo "⚠️ Could not determine MR base. Reviewing working tree..."
50
+ git diff HEAD~1 > /tmp/coderev-mr.diff
51
+ fi
52
+ echo "Debug: Diff saved ($(wc -c < /tmp/coderev-mr.diff) bytes)"
53
+
54
+ # ── Build CLI args ──
55
+ - |
56
+ CODEREV_ARGS=""
57
+
58
+ # Output format
59
+ CODEREV_ARGS="$CODEREV_ARGS --output markdown"
60
+
61
+ # Provider
62
+ PROVIDER="${CODEREV_PROVIDER:-deepseek}"
63
+
64
+ # Mode filter
65
+ case "${CODEREV_MODE:-full}" in
66
+ security) CODEREV_ARGS="$CODEREV_ARGS --audit" ;;
67
+ bugs) CODEREV_ARGS="$CODEREV_ARGS --agents bugs" ;;
68
+ quality) CODEREV_ARGS="$CODEREV_ARGS --agents quality" ;;
69
+ esac
70
+
71
+ # Confidence threshold
72
+ CONFIDENCE="${CODEREV_CONFIDENCE:-60}"
73
+ CODEREV_ARGS="$CODEREV_ARGS --min-confidence $CONFIDENCE"
74
+
75
+ # Git blame
76
+ if [ "${CODEREV_BLAME:-false}" = "true" ]; then
77
+ CODEREV_ARGS="$CODEREV_ARGS --blame"
78
+ fi
79
+
80
+ # CI mode (block MR on issues)
81
+ if [ "${CODEREV_BLOCK:-false}" = "true" ]; then
82
+ CODEREV_ARGS="$CODEREV_ARGS --ci"
83
+ fi
84
+
85
+ # ── Run coderev ──
86
+ - |
87
+ echo "🔍 Running coderev multi-agent review..."
88
+ export DEEPSEEK_API_KEY="${DEEPSEEK_API_KEY}"
89
+ export OPENAI_API_KEY="${OPENAI_API_KEY:-$DEEPSEEK_API_KEY}"
90
+ cat /tmp/coderev-mr.diff | coderev review $CODEREV_ARGS > /tmp/coderev-output.md 2>/tmp/coderev-stderr.txt
91
+ REVIEW_EXIT_CODE=$?
92
+ echo "Debug: review exit code = $REVIEW_EXIT_CODE"
93
+
94
+ # ── Post review as MR comment (if GITLAB_TOKEN is set) ──
95
+ - |
96
+ if [ -n "$GITLAB_TOKEN" ] && [ -n "$CI_MERGE_REQUEST_IID" ]; then
97
+ echo "💬 Posting review comment to MR !$CI_MERGE_REQUEST_IID ..."
98
+
99
+ # Read and escape the review output for JSON
100
+ REVIEW_BODY=$(cat /tmp/coderev-output.md | python3 -c "import sys,json; print(json.dumps(sys.stdin.read()))" 2>/dev/null || \
101
+ node -e "const fs=require('fs');console.log(JSON.stringify(fs.readFileSync('/tmp/coderev-output.md','utf8')))")
102
+
103
+ # Post via GitLab API
104
+ curl -s -X POST \
105
+ "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests/${CI_MERGE_REQUEST_IID}/notes" \
106
+ --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
107
+ --header "Content-Type: application/json" \
108
+ --data "{\"body\": $REVIEW_BODY}" \
109
+ > /tmp/coderev-post-response.json 2>/tmp/coderev-curl-stderr.txt
110
+
111
+ if [ $? -eq 0 ]; then
112
+ echo "✅ Review comment posted to MR !$CI_MERGE_REQUEST_IID"
113
+ else
114
+ echo "⚠️ Failed to post comment (check GITLAB_TOKEN scope: api)"
115
+ fi
116
+ else
117
+ echo "ℹ️ GITLAB_TOKEN not set — skipping MR comment. Review output:"
118
+ cat /tmp/coderev-output.md
119
+ fi
120
+
121
+ # ── Exit with review status (CI mode) ──
122
+ - |
123
+ if [ "${CODEREV_BLOCK:-false}" = "true" ] && [ $REVIEW_EXIT_CODE -ne 0 ]; then
124
+ echo "🚫 Issues found! Blocking MR. Fix issues or lower CODEREV_CONFIDENCE."
125
+ exit 1
126
+ fi
127
+ echo "✅ coderev review complete."
128
+
129
+ artifacts:
130
+ when: always
131
+ paths:
132
+ - /tmp/coderev-output.md
133
+ - /tmp/coderev-stderr.txt
134
+ expire_in: 7 days