threadlines 0.2.18 → 0.2.20
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/dist/commands/check.js +8 -0
- package/dist/git/diff.js +41 -3
- package/package.json +1 -1
package/dist/commands/check.js
CHANGED
|
@@ -227,6 +227,14 @@ async function checkCommand(options) {
|
|
|
227
227
|
console.error(chalk_1.default.bold('ℹ️ No changes detected.'));
|
|
228
228
|
process.exit(0);
|
|
229
229
|
}
|
|
230
|
+
// Safety limit: prevent expensive API calls on large diffs
|
|
231
|
+
const MAX_CHANGED_FILES = 20;
|
|
232
|
+
if (gitDiff.changedFiles.length > MAX_CHANGED_FILES) {
|
|
233
|
+
console.error(chalk_1.default.red(`❌ Too many changed files: ${gitDiff.changedFiles.length} (max: ${MAX_CHANGED_FILES})`));
|
|
234
|
+
console.error(chalk_1.default.gray(' This limit prevents expensive API calls on large diffs.'));
|
|
235
|
+
console.error(chalk_1.default.gray(' Consider reviewing smaller batches of changes.'));
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
230
238
|
// Check for zero diff (files changed but no actual code changes)
|
|
231
239
|
if (!gitDiff.diff || gitDiff.diff.trim() === '') {
|
|
232
240
|
console.log(chalk_1.default.blue('ℹ️ No code changes detected. Diff contains zero lines added or removed.'));
|
package/dist/git/diff.js
CHANGED
|
@@ -190,8 +190,13 @@ async function getPRDiff(repoRoot, targetBranch, logger) {
|
|
|
190
190
|
/**
|
|
191
191
|
* Get diff for a specific commit (or HEAD if no SHA provided).
|
|
192
192
|
*
|
|
193
|
-
*
|
|
194
|
-
* This
|
|
193
|
+
* Fetches the parent commit on-demand to ensure git show can generate a proper diff.
|
|
194
|
+
* This works regardless of CI checkout depth settings (depth=1 or depth=2).
|
|
195
|
+
*
|
|
196
|
+
* Strategy:
|
|
197
|
+
* 1. Get parent SHA from commit metadata (git show --format=%P)
|
|
198
|
+
* 2. Fetch parent commit if available (git fetch origin <parentSHA> --depth=1)
|
|
199
|
+
* 3. Use git show to get diff (now parent is available for comparison)
|
|
195
200
|
*
|
|
196
201
|
* Used by:
|
|
197
202
|
* - All CI environments for push/commit context (GitHub, GitLab, Bitbucket, Vercel)
|
|
@@ -202,7 +207,40 @@ async function getPRDiff(repoRoot, targetBranch, logger) {
|
|
|
202
207
|
*/
|
|
203
208
|
async function getCommitDiff(repoRoot, sha = 'HEAD') {
|
|
204
209
|
const git = (0, simple_git_1.default)(repoRoot);
|
|
205
|
-
//
|
|
210
|
+
// Fetch parent commit on-demand to ensure git show can generate a proper diff
|
|
211
|
+
// This works regardless of CI checkout depth settings (depth=1 or depth=2)
|
|
212
|
+
// If parent is already available, fetch is fast/no-op; if not, we fetch it
|
|
213
|
+
// Get parent SHA from commit metadata (works even if parent isn't fetched locally)
|
|
214
|
+
let parentSha;
|
|
215
|
+
try {
|
|
216
|
+
parentSha = (0, child_process_1.execSync)(`git show ${sha} --format=%P --no-patch`, {
|
|
217
|
+
encoding: 'utf-8',
|
|
218
|
+
cwd: repoRoot
|
|
219
|
+
}).trim();
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
223
|
+
throw new Error(`Failed to get parent commit SHA for ${sha}. ` +
|
|
224
|
+
`This is required to generate a proper diff. ` +
|
|
225
|
+
`Error: ${errorMessage}`);
|
|
226
|
+
}
|
|
227
|
+
// Fetch parent commit if we have a parent (root commits have no parent)
|
|
228
|
+
if (parentSha && parentSha.length === 40) {
|
|
229
|
+
try {
|
|
230
|
+
// Fetch just this one commit (depth=1 is fine, we only need the parent)
|
|
231
|
+
await git.fetch(['origin', parentSha, '--depth=1']);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
235
|
+
throw new Error(`Failed to fetch parent commit ${parentSha} from origin. ` +
|
|
236
|
+
`This is required to generate a proper diff in shallow clones. ` +
|
|
237
|
+
`Ensure 'origin' remote is configured and accessible. ` +
|
|
238
|
+
`Error: ${errorMessage}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// If no parent (root commit), git show will show the full commit content
|
|
242
|
+
// This is expected behavior for root commits
|
|
243
|
+
// Get diff using git show (now parent should be available)
|
|
206
244
|
let diff;
|
|
207
245
|
let changedFiles;
|
|
208
246
|
try {
|