korekt-cli 0.9.5 → 0.9.7

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": "korekt-cli",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "description": "AI-powered code review CLI - Keep your kode korekt",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/git-logic.js CHANGED
@@ -316,9 +316,10 @@ export async function getContributors(diffRange, repoRootPath) {
316
316
  */
317
317
  export async function runLocalReview(targetBranch = null, ignorePatterns = null) {
318
318
  try {
319
- // 1. Get Repo URL, current branch name, and repository root
319
+ // 1. Get Repo URL, current branch name, commit hash, and repository root
320
320
  const { stdout: repoUrl } = await execa('git', ['remote', 'get-url', 'origin']);
321
321
  const { stdout: sourceBranch } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
322
+ const { stdout: commitHash } = await execa('git', ['rev-parse', 'HEAD']);
322
323
  let branchName = sourceBranch.trim();
323
324
 
324
325
  // Handle detached HEAD state (common in CI pipelines)
@@ -533,6 +534,7 @@ export async function runLocalReview(targetBranch = null, ignorePatterns = null)
533
534
  changed_files: changedFiles,
534
535
  source_branch: branchName,
535
536
  destination_branch: targetBranch,
537
+ commit_hash: commitHash.trim(),
536
538
  author_email,
537
539
  author_name,
538
540
  contributors,
@@ -259,6 +259,64 @@ describe('runLocalReview - branch fetching', () => {
259
259
  });
260
260
  });
261
261
 
262
+ describe('runLocalReview - no files changed', () => {
263
+ beforeEach(() => {
264
+ vi.mock('execa');
265
+ vi.spyOn(console, 'error').mockImplementation(() => {});
266
+ });
267
+
268
+ afterEach(() => {
269
+ vi.restoreAllMocks();
270
+ });
271
+
272
+ it('should return payload with empty changed_files when diff has no files', async () => {
273
+ vi.mocked(execa).mockImplementation(async (cmd, args) => {
274
+ const command = [cmd, ...args].join(' ');
275
+
276
+ if (command.includes('remote get-url origin')) {
277
+ return { stdout: 'https://github.com/user/repo.git' };
278
+ }
279
+ if (command.includes('rev-parse --abbrev-ref HEAD')) {
280
+ return { stdout: 'feature-branch' };
281
+ }
282
+ if (command === 'git rev-parse HEAD') {
283
+ return { stdout: 'abc123def456789' };
284
+ }
285
+ if (command.includes('rev-parse --show-toplevel')) {
286
+ return { stdout: '/path/to/repo' };
287
+ }
288
+ if (command.includes('rev-parse --verify main')) {
289
+ return { stdout: 'commit-hash' };
290
+ }
291
+ if (command === 'git fetch origin main') {
292
+ return { stdout: '' };
293
+ }
294
+ if (command.includes('merge-base origin/main HEAD')) {
295
+ return { stdout: 'abc123' };
296
+ }
297
+ if (command.includes('log --no-merges --pretty=%B---EOC---')) {
298
+ return { stdout: 'feat: some commit---EOC---' };
299
+ }
300
+ if (command.includes('log --no-merges --format=%ae|%an')) {
301
+ return { stdout: 'user@example.com|User Name' };
302
+ }
303
+ // No files changed
304
+ if (command.includes('diff --name-status')) {
305
+ return { stdout: '' };
306
+ }
307
+
308
+ return { stdout: '' };
309
+ });
310
+
311
+ const result = await runLocalReview('main');
312
+
313
+ expect(result).not.toBeNull();
314
+ expect(result.changed_files).toEqual([]);
315
+ expect(result.source_branch).toBe('feature-branch');
316
+ expect(result.destination_branch).toBe('main');
317
+ });
318
+ });
319
+
262
320
  describe('runLocalReview - fork point detection', () => {
263
321
  beforeEach(() => {
264
322
  vi.mock('execa');
@@ -279,6 +337,9 @@ describe('runLocalReview - fork point detection', () => {
279
337
  if (command.includes('rev-parse --abbrev-ref HEAD')) {
280
338
  return { stdout: 'feature-branch' };
281
339
  }
340
+ if (command === 'git rev-parse HEAD') {
341
+ return { stdout: 'abc123def456789' };
342
+ }
282
343
  if (command.includes('rev-parse --show-toplevel')) {
283
344
  return { stdout: '/path/to/repo' };
284
345
  }
@@ -329,6 +390,9 @@ describe('runLocalReview - fork point detection', () => {
329
390
  if (command.includes('rev-parse --abbrev-ref HEAD')) {
330
391
  return { stdout: 'feature-branch' };
331
392
  }
393
+ if (command === 'git rev-parse HEAD') {
394
+ return { stdout: 'abc123def456789' };
395
+ }
332
396
  if (command.includes('rev-parse --show-toplevel')) {
333
397
  return { stdout: '/path/to/repo' };
334
398
  }
@@ -1116,6 +1180,71 @@ describe('destination_branch in payload', () => {
1116
1180
  });
1117
1181
  });
1118
1182
 
1183
+ describe('commit_hash in payload', () => {
1184
+ beforeEach(() => {
1185
+ vi.mock('execa');
1186
+ vi.mock('./utils.js', () => ({
1187
+ detectCIProvider: vi.fn().mockReturnValue(null),
1188
+ getPrUrl: vi.fn().mockReturnValue(null),
1189
+ getSourceBranchFromCI: vi.fn().mockReturnValue(null),
1190
+ }));
1191
+ });
1192
+
1193
+ afterEach(() => {
1194
+ vi.restoreAllMocks();
1195
+ });
1196
+
1197
+ it('should include commit_hash in payload', async () => {
1198
+ vi.mocked(execa).mockImplementation(async (cmd, args) => {
1199
+ const command = [cmd, ...args].join(' ');
1200
+
1201
+ if (command.includes('remote get-url origin')) {
1202
+ return { stdout: 'https://github.com/user/repo.git' };
1203
+ }
1204
+ if (command.includes('rev-parse --abbrev-ref HEAD')) {
1205
+ return { stdout: 'feature-branch' };
1206
+ }
1207
+ if (command === 'git rev-parse HEAD') {
1208
+ return { stdout: 'a1b2c3d4e5f6g7h8i9j0' };
1209
+ }
1210
+ if (command.includes('rev-parse --show-toplevel')) {
1211
+ return { stdout: '/path/to/repo' };
1212
+ }
1213
+ if (command.includes('rev-parse --verify main')) {
1214
+ return { stdout: 'commit-hash' };
1215
+ }
1216
+ if (command === 'git fetch origin main') {
1217
+ return { stdout: '' };
1218
+ }
1219
+ if (command.includes('merge-base origin/main HEAD')) {
1220
+ return { stdout: 'abc123' };
1221
+ }
1222
+ if (command.includes('log --no-merges --pretty=%B---EOC---')) {
1223
+ return { stdout: 'feat: add feature---EOC---' };
1224
+ }
1225
+ if (command.includes('log --no-merges --format=%ae|%an')) {
1226
+ return { stdout: 'user@example.com|User Name' };
1227
+ }
1228
+ if (command.includes('diff --name-status')) {
1229
+ return { stdout: 'M\tfile.js' };
1230
+ }
1231
+ if (command.includes('diff -U15')) {
1232
+ return { stdout: 'diff content' };
1233
+ }
1234
+ if (command.includes('show abc123:file.js')) {
1235
+ return { stdout: 'original content' };
1236
+ }
1237
+
1238
+ return { stdout: '' };
1239
+ });
1240
+
1241
+ const result = await runLocalReview('main');
1242
+
1243
+ expect(result).toBeDefined();
1244
+ expect(result.commit_hash).toBe('a1b2c3d4e5f6g7h8i9j0');
1245
+ });
1246
+ });
1247
+
1119
1248
  describe('getSourceBranchFromCI', () => {
1120
1249
  const originalEnv = process.env;
1121
1250
 
package/src/index.js CHANGED
@@ -165,6 +165,12 @@ program
165
165
  process.exit(1);
166
166
  }
167
167
 
168
+ // Exit successfully if no files to review (common in CI when PR has no code changes)
169
+ if (payload.changed_files.length === 0) {
170
+ log(chalk.green('āœ“ No files changed to review. Exiting successfully.'));
171
+ return;
172
+ }
173
+
168
174
  // If dry-run, just show the payload and exit
169
175
  if (options.dryRun) {
170
176
  log(chalk.yellow('\nšŸ“‹ Dry Run - Payload that would be sent:\n'));