git-diff-ai-reviewer 1.2.1 → 1.2.3
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/bin/review.js +6 -2
- package/package.json +1 -1
- package/src/claude.js +3 -3
- package/src/git.js +36 -8
package/bin/review.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require('dotenv').config();
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const fs = require('fs');
|
|
6
|
-
const { getDiff, getChangedFiles, getBranchName, isGitRepo } = require('../src/git');
|
|
6
|
+
const { getDiff, getChangedFiles, getBranchName, isGitRepo, resolveBaseRef } = require('../src/git');
|
|
7
7
|
const { reviewCode, parseSeverityCounts, detectProvider, PROVIDERS, DEFAULT_MODELS } = require('../src/provider');
|
|
8
8
|
const { buildFixPrompt } = require('../src/prompts');
|
|
9
9
|
const { loadConfig } = require('../src/config');
|
|
@@ -149,8 +149,12 @@ async function commandReview(config, flags) {
|
|
|
149
149
|
|
|
150
150
|
// Get branch and diff info
|
|
151
151
|
const branchName = getBranchName();
|
|
152
|
+
const { ref: effectiveBase, isRemote } = resolveBaseRef(baseBranch);
|
|
152
153
|
console.log(` Branch: ${branchName}`);
|
|
153
|
-
console.log(` Base: ${
|
|
154
|
+
console.log(` Base: ${effectiveBase}`);
|
|
155
|
+
if (!isRemote) {
|
|
156
|
+
console.log(` ⚠ Remote origin/${baseBranch} not found — using local ref`);
|
|
157
|
+
}
|
|
154
158
|
|
|
155
159
|
const changedFiles = getChangedFiles(baseBranch);
|
|
156
160
|
if (changedFiles.length === 0) {
|
package/package.json
CHANGED
package/src/claude.js
CHANGED
|
@@ -130,9 +130,9 @@ async function reviewCode(diff, options = {}) {
|
|
|
130
130
|
* @returns {{ critical: number, warning: number, suggestion: number }}
|
|
131
131
|
*/
|
|
132
132
|
function parseSeverityCounts(reviewText) {
|
|
133
|
-
const critical = (reviewText.match(
|
|
134
|
-
const warning = (reviewText.match(
|
|
135
|
-
const suggestion = (reviewText.match(
|
|
133
|
+
const critical = (reviewText.match(/(?:\[SEVERITY\]\s*CRITICAL|\[CRITICAL\])/gi) || []).length;
|
|
134
|
+
const warning = (reviewText.match(/(?:\[SEVERITY\]\s*WARNING|\[WARNING\])/gi) || []).length;
|
|
135
|
+
const suggestion = (reviewText.match(/(?:\[SEVERITY\]\s*SUGGESTION|\[SUGGESTION\])/gi) || []).length;
|
|
136
136
|
|
|
137
137
|
return { critical, warning, suggestion };
|
|
138
138
|
}
|
package/src/git.js
CHANGED
|
@@ -1,22 +1,48 @@
|
|
|
1
1
|
const { execSync } = require('child_process');
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Resolve the effective base ref for diff comparison.
|
|
5
|
+
* Always prefers the remote version of the base branch (e.g. origin/main)
|
|
6
|
+
* so the diff reflects what will actually change on the remote after push.
|
|
7
|
+
* Falls back to the local branch name when the remote ref doesn't exist
|
|
8
|
+
* (e.g. first push of a new repo).
|
|
9
|
+
* @param {string} baseBranch - The configured base branch name
|
|
10
|
+
* @param {string} cwd - Working directory
|
|
11
|
+
* @returns {{ ref: string, isRemote: boolean }} The ref to diff against
|
|
12
|
+
*/
|
|
13
|
+
function resolveBaseRef(baseBranch, cwd = process.cwd()) {
|
|
14
|
+
// Try origin/<baseBranch> first
|
|
15
|
+
try {
|
|
16
|
+
execSync(`git rev-parse --verify origin/${baseBranch}`, {
|
|
17
|
+
cwd,
|
|
18
|
+
encoding: 'utf-8',
|
|
19
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
20
|
+
});
|
|
21
|
+
return { ref: `origin/${baseBranch}`, isRemote: true };
|
|
22
|
+
} catch {
|
|
23
|
+
// Remote ref doesn't exist — fall back to local branch
|
|
24
|
+
return { ref: baseBranch, isRemote: false };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the diff between the current branch and the remote base branch.
|
|
5
30
|
* @param {string} baseBranch - The base branch to compare against (default: 'main')
|
|
6
31
|
* @param {string} cwd - Working directory (default: process.cwd())
|
|
7
32
|
* @returns {string} The git diff output
|
|
8
33
|
*/
|
|
9
34
|
function getDiff(baseBranch = 'main', cwd = process.cwd()) {
|
|
10
35
|
try {
|
|
11
|
-
|
|
12
|
-
|
|
36
|
+
const { ref } = resolveBaseRef(baseBranch, cwd);
|
|
37
|
+
|
|
38
|
+
const diff = execSync(`git diff ${ref}...HEAD`, {
|
|
13
39
|
cwd,
|
|
14
40
|
encoding: 'utf-8',
|
|
15
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
41
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
16
42
|
});
|
|
17
43
|
|
|
18
44
|
if (!diff.trim()) {
|
|
19
|
-
// Fallback:
|
|
45
|
+
// Fallback: uncommitted changes
|
|
20
46
|
const uncommitted = execSync('git diff HEAD', {
|
|
21
47
|
cwd,
|
|
22
48
|
encoding: 'utf-8',
|
|
@@ -24,7 +50,6 @@ function getDiff(baseBranch = 'main', cwd = process.cwd()) {
|
|
|
24
50
|
});
|
|
25
51
|
|
|
26
52
|
if (!uncommitted.trim()) {
|
|
27
|
-
// Also check staged changes
|
|
28
53
|
const staged = execSync('git diff --cached', {
|
|
29
54
|
cwd,
|
|
30
55
|
encoding: 'utf-8',
|
|
@@ -42,14 +67,16 @@ function getDiff(baseBranch = 'main', cwd = process.cwd()) {
|
|
|
42
67
|
}
|
|
43
68
|
|
|
44
69
|
/**
|
|
45
|
-
* Get list of changed files between current branch and base branch.
|
|
70
|
+
* Get list of changed files between current branch and the remote base branch.
|
|
46
71
|
* @param {string} baseBranch - The base branch to compare against
|
|
47
72
|
* @param {string} cwd - Working directory
|
|
48
73
|
* @returns {string[]} Array of changed file paths
|
|
49
74
|
*/
|
|
50
75
|
function getChangedFiles(baseBranch = 'main', cwd = process.cwd()) {
|
|
51
76
|
try {
|
|
52
|
-
const
|
|
77
|
+
const { ref } = resolveBaseRef(baseBranch, cwd);
|
|
78
|
+
|
|
79
|
+
const output = execSync(`git diff --name-only ${ref}...HEAD`, {
|
|
53
80
|
cwd,
|
|
54
81
|
encoding: 'utf-8',
|
|
55
82
|
});
|
|
@@ -110,4 +137,5 @@ module.exports = {
|
|
|
110
137
|
getChangedFiles,
|
|
111
138
|
getBranchName,
|
|
112
139
|
isGitRepo,
|
|
140
|
+
resolveBaseRef,
|
|
113
141
|
};
|