korekt-cli 0.9.4 → 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 +4 -1
- package/src/git-logic.test.js +174 -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)
|
|
@@ -532,6 +533,8 @@ export async function runLocalReview(targetBranch = null, ignorePatterns = null)
|
|
|
532
533
|
commit_messages: commitMessages,
|
|
533
534
|
changed_files: changedFiles,
|
|
534
535
|
source_branch: branchName,
|
|
536
|
+
destination_branch: targetBranch,
|
|
537
|
+
commit_hash: commitHash.trim(),
|
|
535
538
|
author_email,
|
|
536
539
|
author_name,
|
|
537
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
|
}
|
|
@@ -1013,6 +1019,174 @@ describe('is_ci flag in payload', () => {
|
|
|
1013
1019
|
});
|
|
1014
1020
|
});
|
|
1015
1021
|
|
|
1022
|
+
describe('destination_branch in payload', () => {
|
|
1023
|
+
beforeEach(() => {
|
|
1024
|
+
vi.mock('execa');
|
|
1025
|
+
vi.mock('./utils.js', () => ({
|
|
1026
|
+
detectCIProvider: vi.fn().mockReturnValue(null),
|
|
1027
|
+
getPrUrl: vi.fn().mockReturnValue(null),
|
|
1028
|
+
getSourceBranchFromCI: vi.fn().mockReturnValue(null),
|
|
1029
|
+
}));
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
afterEach(() => {
|
|
1033
|
+
vi.restoreAllMocks();
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
it('should include destination_branch when target branch is specified', async () => {
|
|
1037
|
+
vi.mocked(execa).mockImplementation(async (cmd, args) => {
|
|
1038
|
+
const command = [cmd, ...args].join(' ');
|
|
1039
|
+
|
|
1040
|
+
if (command.includes('remote get-url origin')) {
|
|
1041
|
+
return { stdout: 'https://github.com/user/repo.git' };
|
|
1042
|
+
}
|
|
1043
|
+
if (command.includes('rev-parse --abbrev-ref HEAD')) {
|
|
1044
|
+
return { stdout: 'feature-branch' };
|
|
1045
|
+
}
|
|
1046
|
+
if (command.includes('rev-parse --show-toplevel')) {
|
|
1047
|
+
return { stdout: '/path/to/repo' };
|
|
1048
|
+
}
|
|
1049
|
+
if (command.includes('rev-parse --verify main')) {
|
|
1050
|
+
return { stdout: 'commit-hash' };
|
|
1051
|
+
}
|
|
1052
|
+
if (command === 'git fetch origin main') {
|
|
1053
|
+
return { stdout: '' };
|
|
1054
|
+
}
|
|
1055
|
+
if (command.includes('merge-base origin/main HEAD')) {
|
|
1056
|
+
return { stdout: 'abc123' };
|
|
1057
|
+
}
|
|
1058
|
+
if (command.includes('log --no-merges --pretty=%B---EOC---')) {
|
|
1059
|
+
return { stdout: 'feat: add feature---EOC---' };
|
|
1060
|
+
}
|
|
1061
|
+
if (command.includes('log --no-merges --format=%ae|%an')) {
|
|
1062
|
+
return { stdout: 'user@example.com|User Name' };
|
|
1063
|
+
}
|
|
1064
|
+
if (command.includes('diff --name-status')) {
|
|
1065
|
+
return { stdout: 'M\tfile.js' };
|
|
1066
|
+
}
|
|
1067
|
+
if (command.includes('diff -U15')) {
|
|
1068
|
+
return { stdout: 'diff content' };
|
|
1069
|
+
}
|
|
1070
|
+
if (command.includes('show abc123:file.js')) {
|
|
1071
|
+
return { stdout: 'original content' };
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
return { stdout: '' };
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
const result = await runLocalReview('main');
|
|
1078
|
+
|
|
1079
|
+
expect(result).toBeDefined();
|
|
1080
|
+
expect(result.destination_branch).toBe('main');
|
|
1081
|
+
});
|
|
1082
|
+
|
|
1083
|
+
it('should have null destination_branch when no target branch specified', async () => {
|
|
1084
|
+
vi.mocked(execa).mockImplementation(async (cmd, args) => {
|
|
1085
|
+
const command = [cmd, ...args].join(' ');
|
|
1086
|
+
|
|
1087
|
+
if (command.includes('remote get-url origin')) {
|
|
1088
|
+
return { stdout: 'https://github.com/user/repo.git' };
|
|
1089
|
+
}
|
|
1090
|
+
if (command.includes('rev-parse --abbrev-ref HEAD')) {
|
|
1091
|
+
return { stdout: 'feature-branch' };
|
|
1092
|
+
}
|
|
1093
|
+
if (command.includes('rev-parse --show-toplevel')) {
|
|
1094
|
+
return { stdout: '/path/to/repo' };
|
|
1095
|
+
}
|
|
1096
|
+
if (command.includes('reflog show --no-abbrev-commit')) {
|
|
1097
|
+
return {
|
|
1098
|
+
stdout:
|
|
1099
|
+
'510572bc5197788770004d0d0585822adab0128f checkout: moving from main to feature-branch',
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
if (command.includes('log --no-merges --pretty=%B---EOC---')) {
|
|
1103
|
+
return { stdout: 'feat: add feature---EOC---' };
|
|
1104
|
+
}
|
|
1105
|
+
if (command.includes('diff --name-status')) {
|
|
1106
|
+
return { stdout: 'M\tfile.js' };
|
|
1107
|
+
}
|
|
1108
|
+
if (command.includes('diff -U15')) {
|
|
1109
|
+
return { stdout: 'diff content' };
|
|
1110
|
+
}
|
|
1111
|
+
if (command.includes('show 510572bc5197788770004d0d0585822adab0128f:file.js')) {
|
|
1112
|
+
return { stdout: 'original content' };
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
return { stdout: '' };
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
const result = await runLocalReview(); // No target branch
|
|
1119
|
+
|
|
1120
|
+
expect(result).toBeDefined();
|
|
1121
|
+
expect(result.destination_branch).toBeNull();
|
|
1122
|
+
});
|
|
1123
|
+
});
|
|
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
|
+
|
|
1016
1190
|
describe('getSourceBranchFromCI', () => {
|
|
1017
1191
|
const originalEnv = process.env;
|
|
1018
1192
|
|