threadlines 0.2.4 → 0.2.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/dist/commands/check.js +83 -139
- package/dist/git/bitbucket.js +185 -0
- package/dist/git/diff.js +0 -196
- package/dist/git/github.js +25 -52
- package/dist/git/gitlab.js +21 -48
- package/dist/git/local.js +2 -2
- package/dist/git/vercel.js +2 -2
- package/dist/index.js +2 -4
- package/dist/types/git.js +5 -0
- package/dist/utils/context.js +4 -142
- package/dist/utils/environment.js +4 -1
- package/package.json +1 -1
- package/dist/git/context.js +0 -55
- package/dist/git/github-diff.js +0 -116
- package/dist/git/gitlab-diff.js +0 -86
- package/dist/git/local-diff.js +0 -53
- package/dist/git/repo.js +0 -253
- package/dist/git/vercel-diff.js +0 -42
- package/dist/utils/git-diff-executor.js +0 -65
- package/dist/utils/metadata.js +0 -290
package/dist/git/github.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* GitHub Actions Environment
|
|
3
|
+
* GitHub Actions Environment
|
|
4
4
|
*
|
|
5
5
|
* All GitHub-specific logic is contained in this file.
|
|
6
6
|
* No dependencies on other environment implementations.
|
|
@@ -52,10 +52,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
52
52
|
exports.getGitHubContext = getGitHubContext;
|
|
53
53
|
const simple_git_1 = __importDefault(require("simple-git"));
|
|
54
54
|
const fs = __importStar(require("fs"));
|
|
55
|
-
const repo_1 = require("./repo");
|
|
56
55
|
const diff_1 = require("./diff");
|
|
57
56
|
/**
|
|
58
|
-
* Gets all GitHub context
|
|
57
|
+
* Gets all GitHub context
|
|
59
58
|
*/
|
|
60
59
|
async function getGitHubContext(repoRoot) {
|
|
61
60
|
const git = (0, simple_git_1.default)(repoRoot);
|
|
@@ -70,7 +69,6 @@ async function getGitHubContext(repoRoot) {
|
|
|
70
69
|
const branchName = await getBranchName();
|
|
71
70
|
const context = detectContext();
|
|
72
71
|
const commitSha = getCommitSha(context);
|
|
73
|
-
// Get commit author (fails loudly if unavailable)
|
|
74
72
|
// Note: commitSha parameter not needed - GitHub reads from GITHUB_EVENT_PATH JSON
|
|
75
73
|
const commitAuthor = await getCommitAuthor();
|
|
76
74
|
// Get commit message if we have a SHA
|
|
@@ -96,17 +94,17 @@ async function getGitHubContext(repoRoot) {
|
|
|
96
94
|
}
|
|
97
95
|
/**
|
|
98
96
|
* Gets diff for GitHub Actions CI environment
|
|
97
|
+
*
|
|
98
|
+
* Strategy:
|
|
99
|
+
* - PR context: Compare source branch vs target branch (full PR diff)
|
|
100
|
+
* - Any push (main or feature branch): Compare last commit only (HEAD~1...HEAD)
|
|
99
101
|
*/
|
|
100
102
|
async function getDiff(repoRoot) {
|
|
101
103
|
const git = (0, simple_git_1.default)(repoRoot);
|
|
102
|
-
const defaultBranch = await (0, repo_1.getDefaultBranchName)(repoRoot);
|
|
103
|
-
// Determine context from GitHub environment variables
|
|
104
104
|
const eventName = process.env.GITHUB_EVENT_NAME;
|
|
105
105
|
const baseRef = process.env.GITHUB_BASE_REF;
|
|
106
106
|
const headRef = process.env.GITHUB_HEAD_REF;
|
|
107
|
-
|
|
108
|
-
const commitSha = process.env.GITHUB_SHA;
|
|
109
|
-
// Scenario 1: PR Context
|
|
107
|
+
// PR Context: Compare source vs target branch
|
|
110
108
|
if (eventName === 'pull_request') {
|
|
111
109
|
if (!baseRef || !headRef) {
|
|
112
110
|
throw new Error('GitHub PR context detected but GITHUB_BASE_REF or GITHUB_HEAD_REF is missing. ' +
|
|
@@ -120,36 +118,14 @@ async function getDiff(repoRoot) {
|
|
|
120
118
|
changedFiles
|
|
121
119
|
};
|
|
122
120
|
}
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
changedFiles
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
136
|
-
throw new Error(`Could not get diff for default branch '${defaultBranch}'. ` +
|
|
137
|
-
`This might be the first commit on the branch. Error: ${errorMessage}`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// Scenario 3: Feature Branch Push
|
|
141
|
-
if (refName) {
|
|
142
|
-
const diff = await git.diff([`origin/${defaultBranch}...origin/${refName}`, '-U200']);
|
|
143
|
-
const diffSummary = await git.diffSummary([`origin/${defaultBranch}...origin/${refName}`]);
|
|
144
|
-
const changedFiles = diffSummary.files.map(f => f.file);
|
|
145
|
-
return {
|
|
146
|
-
diff: diff || '',
|
|
147
|
-
changedFiles
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
throw new Error('GitHub Actions environment detected but no valid context found. ' +
|
|
151
|
-
'Expected GITHUB_EVENT_NAME="pull_request" (with GITHUB_BASE_REF/GITHUB_HEAD_REF) ' +
|
|
152
|
-
'or GITHUB_REF_NAME for branch context.');
|
|
121
|
+
// Any push (main or feature branch): Review last commit only
|
|
122
|
+
const diff = await git.diff(['HEAD~1...HEAD', '-U200']);
|
|
123
|
+
const diffSummary = await git.diffSummary(['HEAD~1...HEAD']);
|
|
124
|
+
const changedFiles = diffSummary.files.map(f => f.file);
|
|
125
|
+
return {
|
|
126
|
+
diff: diff || '',
|
|
127
|
+
changedFiles
|
|
128
|
+
};
|
|
153
129
|
}
|
|
154
130
|
/**
|
|
155
131
|
* Gets repository name for GitHub Actions
|
|
@@ -175,10 +151,13 @@ async function getBranchName() {
|
|
|
175
151
|
return refName;
|
|
176
152
|
}
|
|
177
153
|
/**
|
|
178
|
-
* Detects GitHub context (PR
|
|
154
|
+
* Detects GitHub context (PR or commit)
|
|
155
|
+
*
|
|
156
|
+
* - PR context: When GITHUB_EVENT_NAME is 'pull_request'
|
|
157
|
+
* - Commit context: Any push (main or feature branch) - reviews single commit
|
|
179
158
|
*/
|
|
180
159
|
function detectContext() {
|
|
181
|
-
//
|
|
160
|
+
// PR context
|
|
182
161
|
if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
|
|
183
162
|
const targetBranch = process.env.GITHUB_BASE_REF;
|
|
184
163
|
const sourceBranch = process.env.GITHUB_HEAD_REF;
|
|
@@ -192,22 +171,16 @@ function detectContext() {
|
|
|
192
171
|
};
|
|
193
172
|
}
|
|
194
173
|
}
|
|
195
|
-
//
|
|
196
|
-
if (process.env.GITHUB_REF_NAME) {
|
|
197
|
-
return {
|
|
198
|
-
type: 'branch',
|
|
199
|
-
branchName: process.env.GITHUB_REF_NAME
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
// 3. Check for commit context
|
|
174
|
+
// Any push (main or feature branch) → commit context
|
|
203
175
|
if (process.env.GITHUB_SHA) {
|
|
204
176
|
return {
|
|
205
177
|
type: 'commit',
|
|
206
178
|
commitSha: process.env.GITHUB_SHA
|
|
207
179
|
};
|
|
208
180
|
}
|
|
209
|
-
|
|
210
|
-
|
|
181
|
+
throw new Error('GitHub Actions: Could not detect context. ' +
|
|
182
|
+
'Expected GITHUB_EVENT_NAME="pull_request" or GITHUB_SHA to be set. ' +
|
|
183
|
+
'This should be automatically provided by GitHub Actions.');
|
|
211
184
|
}
|
|
212
185
|
/**
|
|
213
186
|
* Gets commit SHA from context
|
|
@@ -216,7 +189,7 @@ function getCommitSha(context) {
|
|
|
216
189
|
if (context.type === 'commit') {
|
|
217
190
|
return context.commitSha;
|
|
218
191
|
}
|
|
219
|
-
if (context.type === '
|
|
192
|
+
if (context.type === 'pr') {
|
|
220
193
|
return process.env.GITHUB_SHA;
|
|
221
194
|
}
|
|
222
195
|
return undefined;
|
package/dist/git/gitlab.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* GitLab CI Environment
|
|
3
|
+
* GitLab CI Environment
|
|
4
4
|
*
|
|
5
5
|
* All GitLab-specific logic is contained in this file.
|
|
6
6
|
* No dependencies on other environment implementations.
|
|
@@ -20,7 +20,7 @@ exports.getGitLabContext = getGitLabContext;
|
|
|
20
20
|
const simple_git_1 = __importDefault(require("simple-git"));
|
|
21
21
|
const diff_1 = require("./diff");
|
|
22
22
|
/**
|
|
23
|
-
* Gets all GitLab context
|
|
23
|
+
* Gets all GitLab context
|
|
24
24
|
*/
|
|
25
25
|
async function getGitLabContext(repoRoot) {
|
|
26
26
|
const git = (0, simple_git_1.default)(repoRoot);
|
|
@@ -61,29 +61,19 @@ async function getGitLabContext(repoRoot) {
|
|
|
61
61
|
/**
|
|
62
62
|
* Get diff for GitLab CI environment
|
|
63
63
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
64
|
+
* Strategy:
|
|
65
|
+
* - MR context: Fetch target branch, compare source vs target (full MR diff)
|
|
66
|
+
* - Any push (main or feature branch): Compare last commit only (HEAD~1...HEAD)
|
|
66
67
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* 1. MR Context (CI_MERGE_REQUEST_IID is set):
|
|
70
|
-
* - Fetch target branch, then diff target vs source
|
|
71
|
-
*
|
|
72
|
-
* 2. Feature Branch Push (CI_COMMIT_REF_NAME != CI_DEFAULT_BRANCH):
|
|
73
|
-
* - Fetch default branch, then diff default vs feature
|
|
74
|
-
*
|
|
75
|
-
* 3. Default Branch Push (CI_COMMIT_REF_NAME == CI_DEFAULT_BRANCH):
|
|
76
|
-
* - Use HEAD~1...HEAD (last commit only, no fetch needed)
|
|
68
|
+
* Note: GitLab CI does a shallow clone, so we fetch the target branch for MR context.
|
|
69
|
+
* For regular pushes, HEAD~1...HEAD works without additional fetching.
|
|
77
70
|
*/
|
|
78
71
|
async function getDiff(repoRoot) {
|
|
79
72
|
const git = (0, simple_git_1.default)(repoRoot);
|
|
80
|
-
// Get GitLab CI environment variables
|
|
81
73
|
const mrIid = process.env.CI_MERGE_REQUEST_IID;
|
|
82
74
|
const targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME;
|
|
83
75
|
const sourceBranch = process.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME;
|
|
84
|
-
|
|
85
|
-
const defaultBranch = process.env.CI_DEFAULT_BRANCH || 'main';
|
|
86
|
-
// Scenario 1: MR Context
|
|
76
|
+
// MR Context: Fetch target branch and compare
|
|
87
77
|
if (mrIid) {
|
|
88
78
|
if (!targetBranch || !sourceBranch) {
|
|
89
79
|
throw new Error('GitLab MR context detected but CI_MERGE_REQUEST_TARGET_BRANCH_NAME or ' +
|
|
@@ -97,23 +87,9 @@ async function getDiff(repoRoot) {
|
|
|
97
87
|
const changedFiles = diffSummary.files.map(f => f.file);
|
|
98
88
|
return { diff: diff || '', changedFiles };
|
|
99
89
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
// Scenario 3: Default Branch Push
|
|
105
|
-
if (refName === defaultBranch) {
|
|
106
|
-
console.log(` [GitLab] Push to default branch (${defaultBranch}), using HEAD~1...HEAD`);
|
|
107
|
-
const diff = await git.diff(['HEAD~1...HEAD', '-U200']);
|
|
108
|
-
const diffSummary = await git.diffSummary(['HEAD~1...HEAD']);
|
|
109
|
-
const changedFiles = diffSummary.files.map(f => f.file);
|
|
110
|
-
return { diff: diff || '', changedFiles };
|
|
111
|
-
}
|
|
112
|
-
// Scenario 2: Feature Branch Push
|
|
113
|
-
console.log(` [GitLab] Feature branch push, fetching default branch: origin/${defaultBranch}`);
|
|
114
|
-
await git.fetch(['origin', `${defaultBranch}:refs/remotes/origin/${defaultBranch}`, '--depth=1']);
|
|
115
|
-
const diff = await git.diff([`origin/${defaultBranch}...origin/${refName}`, '-U200']);
|
|
116
|
-
const diffSummary = await git.diffSummary([`origin/${defaultBranch}...origin/${refName}`]);
|
|
90
|
+
// Any push (main or feature branch): Review last commit only
|
|
91
|
+
const diff = await git.diff(['HEAD~1...HEAD', '-U200']);
|
|
92
|
+
const diffSummary = await git.diffSummary(['HEAD~1...HEAD']);
|
|
117
93
|
const changedFiles = diffSummary.files.map(f => f.file);
|
|
118
94
|
return { diff: diff || '', changedFiles };
|
|
119
95
|
}
|
|
@@ -140,10 +116,13 @@ async function getBranchName() {
|
|
|
140
116
|
return refName;
|
|
141
117
|
}
|
|
142
118
|
/**
|
|
143
|
-
* Detects GitLab context (MR
|
|
119
|
+
* Detects GitLab context (MR or commit)
|
|
120
|
+
*
|
|
121
|
+
* - MR context: When CI_MERGE_REQUEST_IID is set
|
|
122
|
+
* - Commit context: Any push (main or feature branch) - reviews single commit
|
|
144
123
|
*/
|
|
145
124
|
function detectContext() {
|
|
146
|
-
//
|
|
125
|
+
// MR context
|
|
147
126
|
const mrIid = process.env.CI_MERGE_REQUEST_IID;
|
|
148
127
|
if (mrIid) {
|
|
149
128
|
const targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME;
|
|
@@ -157,22 +136,16 @@ function detectContext() {
|
|
|
157
136
|
};
|
|
158
137
|
}
|
|
159
138
|
}
|
|
160
|
-
//
|
|
161
|
-
if (process.env.CI_COMMIT_REF_NAME) {
|
|
162
|
-
return {
|
|
163
|
-
type: 'branch',
|
|
164
|
-
branchName: process.env.CI_COMMIT_REF_NAME
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
// 3. Check for commit context
|
|
139
|
+
// Any push (main or feature branch) → commit context
|
|
168
140
|
if (process.env.CI_COMMIT_SHA) {
|
|
169
141
|
return {
|
|
170
142
|
type: 'commit',
|
|
171
143
|
commitSha: process.env.CI_COMMIT_SHA
|
|
172
144
|
};
|
|
173
145
|
}
|
|
174
|
-
|
|
175
|
-
|
|
146
|
+
throw new Error('GitLab CI: Could not detect context. ' +
|
|
147
|
+
'Expected CI_MERGE_REQUEST_IID or CI_COMMIT_SHA to be set. ' +
|
|
148
|
+
'This should be automatically provided by GitLab CI.');
|
|
176
149
|
}
|
|
177
150
|
/**
|
|
178
151
|
* Gets commit SHA from context
|
|
@@ -181,7 +154,7 @@ function getCommitSha(context) {
|
|
|
181
154
|
if (context.type === 'commit') {
|
|
182
155
|
return context.commitSha;
|
|
183
156
|
}
|
|
184
|
-
if (context.type === '
|
|
157
|
+
if (context.type === 'mr') {
|
|
185
158
|
return process.env.CI_COMMIT_SHA;
|
|
186
159
|
}
|
|
187
160
|
return undefined;
|
package/dist/git/local.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Local Environment
|
|
3
|
+
* Local Environment
|
|
4
4
|
*
|
|
5
5
|
* All Local-specific logic is contained in this file.
|
|
6
6
|
* No dependencies on other environment implementations.
|
|
@@ -19,7 +19,7 @@ exports.getLocalContext = getLocalContext;
|
|
|
19
19
|
const simple_git_1 = __importDefault(require("simple-git"));
|
|
20
20
|
const diff_1 = require("./diff");
|
|
21
21
|
/**
|
|
22
|
-
* Gets all Local context
|
|
22
|
+
* Gets all Local context
|
|
23
23
|
*/
|
|
24
24
|
async function getLocalContext(repoRoot, commitSha) {
|
|
25
25
|
const git = (0, simple_git_1.default)(repoRoot);
|
package/dist/git/vercel.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Vercel Environment
|
|
3
|
+
* Vercel Environment
|
|
4
4
|
*
|
|
5
5
|
* All Vercel-specific logic is contained in this file.
|
|
6
6
|
* No dependencies on other environment implementations.
|
|
@@ -20,7 +20,7 @@ const simple_git_1 = __importDefault(require("simple-git"));
|
|
|
20
20
|
const child_process_1 = require("child_process");
|
|
21
21
|
const diff_1 = require("./diff");
|
|
22
22
|
/**
|
|
23
|
-
* Gets all Vercel context
|
|
23
|
+
* Gets all Vercel context
|
|
24
24
|
*/
|
|
25
25
|
async function getVercelContext(repoRoot) {
|
|
26
26
|
const git = (0, simple_git_1.default)(repoRoot);
|
package/dist/index.js
CHANGED
|
@@ -63,7 +63,6 @@ program
|
|
|
63
63
|
.description('Check code against your threadlines')
|
|
64
64
|
.option('--api-url <url>', 'Threadline server URL', process.env.THREADLINE_API_URL || 'https://devthreadline.com')
|
|
65
65
|
.option('--full', 'Show all results (compliant, attention, not_relevant). Default: only attention items')
|
|
66
|
-
.option('--branch <name>', 'Review all commits in branch vs base (e.g., --branch feature/new-feature)')
|
|
67
66
|
.option('--commit <ref>', 'Review specific commit. Accepts commit SHA or git reference (e.g., HEAD, HEAD~1, abc123). Example: --commit HEAD')
|
|
68
67
|
.option('--file <path>', 'Review entire file (all lines as additions)')
|
|
69
68
|
.option('--folder <path>', 'Review all files in folder recursively')
|
|
@@ -72,13 +71,12 @@ program
|
|
|
72
71
|
Examples:
|
|
73
72
|
$ threadlines check # Check staged/unstaged changes (local dev)
|
|
74
73
|
$ threadlines check --commit HEAD # Check latest commit locally
|
|
75
|
-
$ threadlines check --branch main # Check all commits in branch vs base
|
|
76
74
|
$ threadlines check --file src/api.ts # Check entire file
|
|
77
75
|
$ threadlines check --full # Show all results (not just attention items)
|
|
78
76
|
|
|
79
77
|
Auto-detection in CI:
|
|
80
|
-
-
|
|
81
|
-
-
|
|
78
|
+
- PR/MR context → reviews all changes in the PR/MR
|
|
79
|
+
- Push to any branch → reviews the commit being pushed
|
|
82
80
|
- Local development → reviews staged/unstaged changes
|
|
83
81
|
`)
|
|
84
82
|
.action(check_1.checkCommand);
|
package/dist/utils/context.js
CHANGED
|
@@ -1,148 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Review Context
|
|
3
|
+
* Review Context Types
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* - PR/MR:
|
|
7
|
-
* -
|
|
8
|
-
* - Commit: Single commit changes
|
|
5
|
+
* Type definitions for the different code review contexts:
|
|
6
|
+
* - PR/MR: Comparing source branch vs target branch (branch-level diff)
|
|
7
|
+
* - Commit: Single commit changes (any push without PR/MR)
|
|
9
8
|
* - Local: Staged/unstaged changes in working directory
|
|
10
|
-
*
|
|
11
|
-
* Context detection is environment-specific - each CI platform
|
|
12
|
-
* provides different environment variables.
|
|
13
9
|
*/
|
|
14
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.detectContext = detectContext;
|
|
16
|
-
/**
|
|
17
|
-
* Detects the review context based on the environment.
|
|
18
|
-
*
|
|
19
|
-
* Each environment has different environment variables available,
|
|
20
|
-
* so detection logic is environment-specific.
|
|
21
|
-
*/
|
|
22
|
-
function detectContext(environment) {
|
|
23
|
-
switch (environment) {
|
|
24
|
-
case 'github':
|
|
25
|
-
return detectGitHubContext();
|
|
26
|
-
case 'gitlab':
|
|
27
|
-
return detectGitLabContext();
|
|
28
|
-
case 'vercel':
|
|
29
|
-
return detectVercelContext();
|
|
30
|
-
case 'local':
|
|
31
|
-
return { type: 'local' };
|
|
32
|
-
default:
|
|
33
|
-
return { type: 'local' };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* GitHub Actions context detection
|
|
38
|
-
*
|
|
39
|
-
* Environment Variables:
|
|
40
|
-
* - PR: GITHUB_EVENT_NAME='pull_request', GITHUB_BASE_REF, GITHUB_HEAD_REF, GITHUB_EVENT_NUMBER
|
|
41
|
-
* - Branch: GITHUB_REF_NAME
|
|
42
|
-
* - Commit: GITHUB_SHA
|
|
43
|
-
*/
|
|
44
|
-
function detectGitHubContext() {
|
|
45
|
-
// 1. Check for PR context
|
|
46
|
-
if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
|
|
47
|
-
const targetBranch = process.env.GITHUB_BASE_REF;
|
|
48
|
-
const sourceBranch = process.env.GITHUB_HEAD_REF;
|
|
49
|
-
const prNumber = process.env.GITHUB_EVENT_PULL_REQUEST_NUMBER || process.env.GITHUB_EVENT_NUMBER;
|
|
50
|
-
if (targetBranch && sourceBranch && prNumber) {
|
|
51
|
-
return {
|
|
52
|
-
type: 'pr',
|
|
53
|
-
prNumber,
|
|
54
|
-
sourceBranch,
|
|
55
|
-
targetBranch
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// 2. Check for branch context
|
|
60
|
-
if (process.env.GITHUB_REF_NAME) {
|
|
61
|
-
return {
|
|
62
|
-
type: 'branch',
|
|
63
|
-
branchName: process.env.GITHUB_REF_NAME
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
// 3. Check for commit context
|
|
67
|
-
if (process.env.GITHUB_SHA) {
|
|
68
|
-
return {
|
|
69
|
-
type: 'commit',
|
|
70
|
-
commitSha: process.env.GITHUB_SHA
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
// 4. Fallback to local
|
|
74
|
-
return { type: 'local' };
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* GitLab CI context detection
|
|
78
|
-
*
|
|
79
|
-
* Environment Variables:
|
|
80
|
-
* - MR: CI_MERGE_REQUEST_IID, CI_MERGE_REQUEST_TARGET_BRANCH_NAME, CI_MERGE_REQUEST_SOURCE_BRANCH_NAME, CI_MERGE_REQUEST_TITLE
|
|
81
|
-
* - Branch: CI_COMMIT_REF_NAME
|
|
82
|
-
* - Commit: CI_COMMIT_SHA
|
|
83
|
-
*/
|
|
84
|
-
function detectGitLabContext() {
|
|
85
|
-
// 1. Check for MR context
|
|
86
|
-
if (process.env.CI_MERGE_REQUEST_IID) {
|
|
87
|
-
const targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME;
|
|
88
|
-
const sourceBranch = process.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME;
|
|
89
|
-
const mrNumber = process.env.CI_MERGE_REQUEST_IID;
|
|
90
|
-
const mrTitle = process.env.CI_MERGE_REQUEST_TITLE;
|
|
91
|
-
if (targetBranch && sourceBranch && mrNumber) {
|
|
92
|
-
return {
|
|
93
|
-
type: 'mr',
|
|
94
|
-
mrNumber,
|
|
95
|
-
sourceBranch,
|
|
96
|
-
targetBranch,
|
|
97
|
-
prTitle: mrTitle || undefined
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// 2. Check for branch context
|
|
102
|
-
if (process.env.CI_COMMIT_REF_NAME) {
|
|
103
|
-
return {
|
|
104
|
-
type: 'branch',
|
|
105
|
-
branchName: process.env.CI_COMMIT_REF_NAME
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
// 3. Check for commit context
|
|
109
|
-
if (process.env.CI_COMMIT_SHA) {
|
|
110
|
-
return {
|
|
111
|
-
type: 'commit',
|
|
112
|
-
commitSha: process.env.CI_COMMIT_SHA
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
// 4. Fallback to local
|
|
116
|
-
return { type: 'local' };
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Vercel context detection
|
|
120
|
-
*
|
|
121
|
-
* Environment Variables:
|
|
122
|
-
* - Branch: VERCEL_GIT_COMMIT_REF
|
|
123
|
-
* - Commit: VERCEL_GIT_COMMIT_SHA
|
|
124
|
-
*
|
|
125
|
-
* Vercel Limitation:
|
|
126
|
-
* Vercel performs shallow clones of the repository, typically fetching only the
|
|
127
|
-
* specific commit being deployed. The git repository in Vercel's build environment
|
|
128
|
-
* does not contain the full git history or remote branch references (e.g., origin/main).
|
|
129
|
-
* This means branch-based diff operations (comparing feature branch against base branch)
|
|
130
|
-
* are not possible because the base branch refs are not available in the repository.
|
|
131
|
-
*
|
|
132
|
-
* Solution:
|
|
133
|
-
* We hardcode commit context for Vercel, using VERCEL_GIT_COMMIT_SHA to get a
|
|
134
|
-
* commit-based diff (comparing the commit against its parent). This works within
|
|
135
|
-
* Vercel's constraints since we only need the commit SHA, not branch references.
|
|
136
|
-
*/
|
|
137
|
-
function detectVercelContext() {
|
|
138
|
-
// Hardcode commit context for Vercel due to shallow clone limitations
|
|
139
|
-
// Vercel's git repository doesn't have base branch refs available
|
|
140
|
-
if (process.env.VERCEL_GIT_COMMIT_SHA) {
|
|
141
|
-
return {
|
|
142
|
-
type: 'commit',
|
|
143
|
-
commitSha: process.env.VERCEL_GIT_COMMIT_SHA
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
// Fallback to local
|
|
147
|
-
return { type: 'local' };
|
|
148
|
-
}
|
|
@@ -15,7 +15,8 @@ exports.isCIEnvironment = isCIEnvironment;
|
|
|
15
15
|
* 1. Vercel: VERCEL=1
|
|
16
16
|
* 2. GitHub Actions: GITHUB_ACTIONS=1
|
|
17
17
|
* 3. GitLab CI: GITLAB_CI=1 or (CI=1 + CI_COMMIT_SHA)
|
|
18
|
-
* 4.
|
|
18
|
+
* 4. Bitbucket Pipelines: BITBUCKET_BUILD_NUMBER exists
|
|
19
|
+
* 5. Local: None of the above
|
|
19
20
|
*/
|
|
20
21
|
function detectEnvironment() {
|
|
21
22
|
if (process.env.VERCEL)
|
|
@@ -24,6 +25,8 @@ function detectEnvironment() {
|
|
|
24
25
|
return 'github';
|
|
25
26
|
if (process.env.GITLAB_CI || (process.env.CI && process.env.CI_COMMIT_SHA))
|
|
26
27
|
return 'gitlab';
|
|
28
|
+
if (process.env.BITBUCKET_BUILD_NUMBER)
|
|
29
|
+
return 'bitbucket';
|
|
27
30
|
return 'local';
|
|
28
31
|
}
|
|
29
32
|
/**
|
package/package.json
CHANGED
package/dist/git/context.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Unified Git Context Collection
|
|
4
|
-
*
|
|
5
|
-
* Collects all git-related information (diff, repo name, branch name) in a unified way.
|
|
6
|
-
* Each environment has isolated implementations - changes to one don't affect others.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getGitContextForEnvironment = getGitContextForEnvironment;
|
|
10
|
-
const git_diff_executor_1 = require("../utils/git-diff-executor");
|
|
11
|
-
const repo_1 = require("./repo");
|
|
12
|
-
const repo_2 = require("./repo");
|
|
13
|
-
/**
|
|
14
|
-
* Collects all git context (diff, repo name, branch name) for the given environment.
|
|
15
|
-
*
|
|
16
|
-
* Each environment has a single, specific implementation:
|
|
17
|
-
* - GitHub: Uses GITHUB_REPOSITORY, GITHUB_REF_NAME, and GitHub-specific diff logic
|
|
18
|
-
* - Vercel: Uses VERCEL_GIT_REPO_OWNER/SLUG, VERCEL_GIT_COMMIT_REF, and Vercel-specific diff logic
|
|
19
|
-
* - GitLab: Uses CI_PROJECT_URL, CI_COMMIT_REF_NAME, and GitLab-specific diff logic
|
|
20
|
-
* (fetches default branch on-demand since GitLab only clones current branch)
|
|
21
|
-
* - Local: Uses git commands for repo/branch, and local diff logic
|
|
22
|
-
*
|
|
23
|
-
* All methods fail loudly if they can't get the required information.
|
|
24
|
-
*/
|
|
25
|
-
async function getGitContextForEnvironment(environment, repoRoot) {
|
|
26
|
-
switch (environment) {
|
|
27
|
-
case 'github':
|
|
28
|
-
return {
|
|
29
|
-
diff: await (0, git_diff_executor_1.getDiffForEnvironment)('github', repoRoot),
|
|
30
|
-
repoName: await (0, repo_1.getGitHubRepoName)(repoRoot),
|
|
31
|
-
branchName: await (0, repo_2.getGitHubBranchName)(repoRoot)
|
|
32
|
-
};
|
|
33
|
-
case 'vercel':
|
|
34
|
-
return {
|
|
35
|
-
diff: await (0, git_diff_executor_1.getDiffForEnvironment)('vercel', repoRoot),
|
|
36
|
-
repoName: await (0, repo_1.getVercelRepoName)(repoRoot),
|
|
37
|
-
branchName: await (0, repo_2.getVercelBranchName)(repoRoot)
|
|
38
|
-
};
|
|
39
|
-
case 'local':
|
|
40
|
-
return {
|
|
41
|
-
diff: await (0, git_diff_executor_1.getDiffForEnvironment)('local', repoRoot),
|
|
42
|
-
repoName: await (0, repo_1.getLocalRepoName)(repoRoot),
|
|
43
|
-
branchName: await (0, repo_2.getLocalBranchName)(repoRoot)
|
|
44
|
-
};
|
|
45
|
-
case 'gitlab':
|
|
46
|
-
return {
|
|
47
|
-
diff: await (0, git_diff_executor_1.getDiffForEnvironment)('gitlab', repoRoot),
|
|
48
|
-
repoName: await (0, repo_1.getGitLabRepoName)(repoRoot),
|
|
49
|
-
branchName: await (0, repo_2.getGitLabBranchName)(repoRoot)
|
|
50
|
-
};
|
|
51
|
-
default:
|
|
52
|
-
const _exhaustive = environment;
|
|
53
|
-
throw new Error(`Unknown environment: ${_exhaustive}`);
|
|
54
|
-
}
|
|
55
|
-
}
|