korekt-cli 0.9.5 → 0.9.6
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 +1 -1
- package/src/git-logic.js +3 -1
- package/src/git-logic.test.js +71 -0
package/package.json
CHANGED
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,
|
package/src/git-logic.test.js
CHANGED
|
@@ -279,6 +279,9 @@ describe('runLocalReview - fork point detection', () => {
|
|
|
279
279
|
if (command.includes('rev-parse --abbrev-ref HEAD')) {
|
|
280
280
|
return { stdout: 'feature-branch' };
|
|
281
281
|
}
|
|
282
|
+
if (command === 'git rev-parse HEAD') {
|
|
283
|
+
return { stdout: 'abc123def456789' };
|
|
284
|
+
}
|
|
282
285
|
if (command.includes('rev-parse --show-toplevel')) {
|
|
283
286
|
return { stdout: '/path/to/repo' };
|
|
284
287
|
}
|
|
@@ -329,6 +332,9 @@ describe('runLocalReview - fork point detection', () => {
|
|
|
329
332
|
if (command.includes('rev-parse --abbrev-ref HEAD')) {
|
|
330
333
|
return { stdout: 'feature-branch' };
|
|
331
334
|
}
|
|
335
|
+
if (command === 'git rev-parse HEAD') {
|
|
336
|
+
return { stdout: 'abc123def456789' };
|
|
337
|
+
}
|
|
332
338
|
if (command.includes('rev-parse --show-toplevel')) {
|
|
333
339
|
return { stdout: '/path/to/repo' };
|
|
334
340
|
}
|
|
@@ -1116,6 +1122,71 @@ describe('destination_branch in payload', () => {
|
|
|
1116
1122
|
});
|
|
1117
1123
|
});
|
|
1118
1124
|
|
|
1125
|
+
describe('commit_hash in payload', () => {
|
|
1126
|
+
beforeEach(() => {
|
|
1127
|
+
vi.mock('execa');
|
|
1128
|
+
vi.mock('./utils.js', () => ({
|
|
1129
|
+
detectCIProvider: vi.fn().mockReturnValue(null),
|
|
1130
|
+
getPrUrl: vi.fn().mockReturnValue(null),
|
|
1131
|
+
getSourceBranchFromCI: vi.fn().mockReturnValue(null),
|
|
1132
|
+
}));
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
afterEach(() => {
|
|
1136
|
+
vi.restoreAllMocks();
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
it('should include commit_hash in payload', async () => {
|
|
1140
|
+
vi.mocked(execa).mockImplementation(async (cmd, args) => {
|
|
1141
|
+
const command = [cmd, ...args].join(' ');
|
|
1142
|
+
|
|
1143
|
+
if (command.includes('remote get-url origin')) {
|
|
1144
|
+
return { stdout: 'https://github.com/user/repo.git' };
|
|
1145
|
+
}
|
|
1146
|
+
if (command.includes('rev-parse --abbrev-ref HEAD')) {
|
|
1147
|
+
return { stdout: 'feature-branch' };
|
|
1148
|
+
}
|
|
1149
|
+
if (command === 'git rev-parse HEAD') {
|
|
1150
|
+
return { stdout: 'a1b2c3d4e5f6g7h8i9j0' };
|
|
1151
|
+
}
|
|
1152
|
+
if (command.includes('rev-parse --show-toplevel')) {
|
|
1153
|
+
return { stdout: '/path/to/repo' };
|
|
1154
|
+
}
|
|
1155
|
+
if (command.includes('rev-parse --verify main')) {
|
|
1156
|
+
return { stdout: 'commit-hash' };
|
|
1157
|
+
}
|
|
1158
|
+
if (command === 'git fetch origin main') {
|
|
1159
|
+
return { stdout: '' };
|
|
1160
|
+
}
|
|
1161
|
+
if (command.includes('merge-base origin/main HEAD')) {
|
|
1162
|
+
return { stdout: 'abc123' };
|
|
1163
|
+
}
|
|
1164
|
+
if (command.includes('log --no-merges --pretty=%B---EOC---')) {
|
|
1165
|
+
return { stdout: 'feat: add feature---EOC---' };
|
|
1166
|
+
}
|
|
1167
|
+
if (command.includes('log --no-merges --format=%ae|%an')) {
|
|
1168
|
+
return { stdout: 'user@example.com|User Name' };
|
|
1169
|
+
}
|
|
1170
|
+
if (command.includes('diff --name-status')) {
|
|
1171
|
+
return { stdout: 'M\tfile.js' };
|
|
1172
|
+
}
|
|
1173
|
+
if (command.includes('diff -U15')) {
|
|
1174
|
+
return { stdout: 'diff content' };
|
|
1175
|
+
}
|
|
1176
|
+
if (command.includes('show abc123:file.js')) {
|
|
1177
|
+
return { stdout: 'original content' };
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
return { stdout: '' };
|
|
1181
|
+
});
|
|
1182
|
+
|
|
1183
|
+
const result = await runLocalReview('main');
|
|
1184
|
+
|
|
1185
|
+
expect(result).toBeDefined();
|
|
1186
|
+
expect(result.commit_hash).toBe('a1b2c3d4e5f6g7h8i9j0');
|
|
1187
|
+
});
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1119
1190
|
describe('getSourceBranchFromCI', () => {
|
|
1120
1191
|
const originalEnv = process.env;
|
|
1121
1192
|
|