threadlines 0.1.7 → 0.1.8
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 +5 -2
- package/dist/git/diff.js +52 -13
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/commands/check.js
CHANGED
|
@@ -195,8 +195,11 @@ async function checkCommand(options) {
|
|
|
195
195
|
// 4. Get repo name and branch name
|
|
196
196
|
const repoName = await (0, repo_1.getRepoName)(repoRoot);
|
|
197
197
|
const branchName = await (0, repo_1.getBranchName)(repoRoot);
|
|
198
|
-
// 5. Get API URL
|
|
199
|
-
const apiUrl = options.apiUrl ||
|
|
198
|
+
// 5. Get API URL (auto-detect Vercel if available)
|
|
199
|
+
const apiUrl = options.apiUrl ||
|
|
200
|
+
process.env.THREADLINE_API_URL ||
|
|
201
|
+
(process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : null) ||
|
|
202
|
+
'http://localhost:3000';
|
|
200
203
|
// 6. Call review API
|
|
201
204
|
console.log(chalk_1.default.gray('🤖 Running threadline checks...'));
|
|
202
205
|
const client = new client_1.ReviewAPIClient(apiUrl);
|
package/dist/git/diff.js
CHANGED
|
@@ -63,6 +63,33 @@ async function getBranchDiff(repoRoot, branchName, baseBranch) {
|
|
|
63
63
|
base = baseBranch;
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
|
+
// Check if the branch itself is a base branch (main/master)
|
|
67
|
+
const baseBranchNames = ['main', 'master'];
|
|
68
|
+
const isBaseBranch = baseBranchNames.includes(branchName.toLowerCase());
|
|
69
|
+
if (isBaseBranch) {
|
|
70
|
+
// For main/master branch, compare against previous commit (HEAD~1)
|
|
71
|
+
// This checks what changed in the most recent commit
|
|
72
|
+
try {
|
|
73
|
+
const previousCommit = await git.revparse(['HEAD~1']).catch(() => null);
|
|
74
|
+
if (previousCommit) {
|
|
75
|
+
// Use commit-based diff instead
|
|
76
|
+
const diff = await git.diff([`${previousCommit}..HEAD`]);
|
|
77
|
+
const diffSummary = await git.diffSummary([`${previousCommit}..HEAD`]);
|
|
78
|
+
const changedFiles = diffSummary.files.map(f => f.file);
|
|
79
|
+
return {
|
|
80
|
+
diff: diff || '',
|
|
81
|
+
changedFiles
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// If no previous commit, return empty (first commit)
|
|
87
|
+
return {
|
|
88
|
+
diff: '',
|
|
89
|
+
changedFiles: []
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
66
93
|
// Try to detect base branch: upstream, default branch, or common names
|
|
67
94
|
base = await detectBaseBranch(git, branchName);
|
|
68
95
|
}
|
|
@@ -72,27 +99,39 @@ async function getBranchDiff(repoRoot, branchName, baseBranch) {
|
|
|
72
99
|
const upstream = await git.revparse(['--abbrev-ref', '--symbolic-full-name', `${branchName}@{u}`]).catch(() => null);
|
|
73
100
|
if (upstream) {
|
|
74
101
|
// Extract base from upstream (e.g., "origin/main" -> "main")
|
|
75
|
-
|
|
102
|
+
const upstreamBranch = upstream.replace(/^origin\//, '');
|
|
103
|
+
// Don't use the branch itself as its base
|
|
104
|
+
if (upstreamBranch !== branchName) {
|
|
105
|
+
return upstreamBranch;
|
|
106
|
+
}
|
|
76
107
|
}
|
|
77
108
|
// Try default branch
|
|
78
109
|
try {
|
|
79
110
|
const defaultBranch = await git.revparse(['--abbrev-ref', 'refs/remotes/origin/HEAD']);
|
|
80
|
-
|
|
111
|
+
const defaultBranchName = defaultBranch.replace(/^origin\//, '');
|
|
112
|
+
// Don't use the branch itself as its base
|
|
113
|
+
if (defaultBranchName !== branchName) {
|
|
114
|
+
return defaultBranchName;
|
|
115
|
+
}
|
|
81
116
|
}
|
|
82
117
|
catch {
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
118
|
+
// Continue to fallback
|
|
119
|
+
}
|
|
120
|
+
// Fallback to common names (excluding the branch itself)
|
|
121
|
+
const commonBases = ['main', 'master', 'develop'];
|
|
122
|
+
for (const candidate of commonBases) {
|
|
123
|
+
if (candidate.toLowerCase() === branchName.toLowerCase()) {
|
|
124
|
+
continue; // Skip if it's the same branch
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
await git.revparse([`origin/${candidate}`]);
|
|
128
|
+
return candidate;
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// Try next
|
|
93
132
|
}
|
|
94
|
-
throw new Error(`Could not determine base branch. Please specify with --base flag or set upstream tracking.`);
|
|
95
133
|
}
|
|
134
|
+
throw new Error(`Could not determine base branch for '${branchName}'. Please specify with --base flag or set upstream tracking.`);
|
|
96
135
|
}
|
|
97
136
|
// Get diff between base and branch (cumulative diff of all commits)
|
|
98
137
|
// Format: git diff base...branch (three-dot notation finds common ancestor)
|
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ program
|
|
|
61
61
|
program
|
|
62
62
|
.command('check')
|
|
63
63
|
.description('Check code against your threadlines')
|
|
64
|
-
.option('--api-url <url>', 'Threadline server URL', process.env.THREADLINE_API_URL || 'http://localhost:3000')
|
|
64
|
+
.option('--api-url <url>', 'Threadline server URL', process.env.THREADLINE_API_URL || (process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : 'http://localhost:3000'))
|
|
65
65
|
.option('--full', 'Show all results (compliant, attention, not_relevant). Default: only attention items')
|
|
66
66
|
.option('--branch <name>', 'Review all commits in branch vs base')
|
|
67
67
|
.option('--commit <sha>', 'Review specific commit')
|