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.
@@ -1,116 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getGitHubDiff = getGitHubDiff;
7
- const simple_git_1 = __importDefault(require("simple-git"));
8
- const repo_1 = require("./repo");
9
- /**
10
- * Get diff for GitHub Actions CI environment
11
- *
12
- * Handles four scenarios:
13
- *
14
- * 1. PR Context (pull_request event):
15
- * Uses GITHUB_BASE_REF vs GITHUB_HEAD_REF
16
- * Shows: All changes in the PR
17
- *
18
- * 2. Merge Commit to Default Branch (push event, default branch):
19
- * Compare: origin/default~1 vs origin/default
20
- * Shows: All changes that were merged in
21
- *
22
- * 3. Feature Branch Push (push event, feature branch):
23
- * Compare: origin/default vs origin/feature-branch
24
- * Shows: Cumulative changes in feature branch vs default
25
- *
26
- * 4. Direct Commit to Default Branch (push event, default branch, non-merge):
27
- * Compare: origin/default~1 vs origin/default
28
- * Shows: Changes in the direct commit
29
- *
30
- * Known Limitation - Rebase and Merge:
31
- * When using "Rebase and merge" strategy in GitHub, multiple commits are
32
- * added to the default branch. Our approach (default~1 vs default) only
33
- * captures the LAST commit, not all rebased commits. This is a naive
34
- * implementation. To fully support rebase merges, we'd need to use the
35
- * `before` SHA from GITHUB_EVENT_PATH to compare before...after.
36
- */
37
- async function getGitHubDiff(repoRoot) {
38
- const git = (0, simple_git_1.default)(repoRoot);
39
- // Check if we're in a git repo
40
- const isRepo = await git.checkIsRepo();
41
- if (!isRepo) {
42
- throw new Error('Not a git repository. Threadline requires a git repository.');
43
- }
44
- // Detect the default branch name (e.g., "main", "master")
45
- // This is used for scenarios 2, 3, and 4
46
- const defaultBranch = await (0, repo_1.getDefaultBranchName)(repoRoot);
47
- // Determine context from GitHub environment variables
48
- const eventName = process.env.GITHUB_EVENT_NAME;
49
- const baseRef = process.env.GITHUB_BASE_REF;
50
- const headRef = process.env.GITHUB_HEAD_REF;
51
- const refName = process.env.GITHUB_REF_NAME;
52
- const commitSha = process.env.GITHUB_SHA;
53
- // Scenario 1: PR Context
54
- // When a PR is created or updated, GitHub provides both base and head branches
55
- // This is the simplest case - we use what GitHub gives us directly
56
- if (eventName === 'pull_request') {
57
- if (!baseRef || !headRef) {
58
- throw new Error('GitHub PR context detected but GITHUB_BASE_REF or GITHUB_HEAD_REF is missing. ' +
59
- 'This should be automatically provided by GitHub Actions.');
60
- }
61
- // Compare target branch (base) vs source branch (head)
62
- // This shows all changes in the PR
63
- const diff = await git.diff([`origin/${baseRef}...origin/${headRef}`, '-U200']);
64
- const diffSummary = await git.diffSummary([`origin/${baseRef}...origin/${headRef}`]);
65
- const changedFiles = diffSummary.files.map(f => f.file);
66
- return {
67
- diff: diff || '',
68
- changedFiles
69
- };
70
- }
71
- // Scenario 2 & 4: Default Branch Push (merge commit or direct commit)
72
- // When code is pushed to the default branch, we compare default~1 vs default
73
- // This works for both merge commits and direct commits:
74
- // - Merge commits: Shows all changes that were merged in
75
- // - Direct commits: Shows the changes in the direct commit
76
- if (refName === defaultBranch && commitSha) {
77
- // Compare default branch before the push (default~1) vs default branch after the push (default)
78
- // This shows all changes introduced by the push, whether merged or direct
79
- try {
80
- const diff = await git.diff([`origin/${defaultBranch}~1...origin/${defaultBranch}`, '-U200']);
81
- const diffSummary = await git.diffSummary([`origin/${defaultBranch}~1...origin/${defaultBranch}`]);
82
- const changedFiles = diffSummary.files.map(f => f.file);
83
- return {
84
- diff: diff || '',
85
- changedFiles
86
- };
87
- }
88
- catch (error) {
89
- // If we can't get the diff (e.g., first commit on branch), throw a clear error
90
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
91
- throw new Error(`Could not get diff for default branch '${defaultBranch}'. ` +
92
- `This might be the first commit on the branch. Error: ${errorMessage}`);
93
- }
94
- }
95
- // Scenario 3: Feature Branch Push
96
- // When code is pushed to a feature branch, we want to see all changes vs the default branch
97
- // Compare: origin/default vs origin/feature-branch
98
- // This shows cumulative changes in the feature branch (all commits vs default branch)
99
- // Note: We don't use HEAD~1 vs HEAD because that only shows the last commit,
100
- // not the cumulative changes in the branch
101
- if (refName) {
102
- // For branch pushes, compare against origin/default (detected default branch)
103
- // GitHub Actions with fetch-depth: 0 should have origin/default available
104
- const diff = await git.diff([`origin/${defaultBranch}...origin/${refName}`, '-U200']);
105
- const diffSummary = await git.diffSummary([`origin/${defaultBranch}...origin/${refName}`]);
106
- const changedFiles = diffSummary.files.map(f => f.file);
107
- return {
108
- diff: diff || '',
109
- changedFiles
110
- };
111
- }
112
- // Neither PR nor branch context available
113
- throw new Error('GitHub Actions environment detected but no valid context found. ' +
114
- 'Expected GITHUB_EVENT_NAME="pull_request" (with GITHUB_BASE_REF/GITHUB_HEAD_REF) ' +
115
- 'or GITHUB_REF_NAME for branch context.');
116
- }
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getGitLabDiff = getGitLabDiff;
7
- const simple_git_1 = __importDefault(require("simple-git"));
8
- /**
9
- * Get diff for GitLab CI environment
10
- *
11
- * GitLab CI does a shallow clone of ONLY the current branch. The default branch
12
- * (e.g., origin/main) is NOT available by default. We fetch it on-demand.
13
- *
14
- * Scenarios handled:
15
- *
16
- * 1. MR Context (CI_MERGE_REQUEST_IID is set):
17
- * - Fetch target branch, then diff target vs source
18
- *
19
- * 2. Feature Branch Push (CI_COMMIT_REF_NAME != CI_DEFAULT_BRANCH):
20
- * - Fetch default branch, then diff default vs feature
21
- *
22
- * 3. Default Branch Push (CI_COMMIT_REF_NAME == CI_DEFAULT_BRANCH):
23
- * - Use HEAD~1...HEAD (last commit only, no fetch needed)
24
- *
25
- * This is the ONLY implementation for GitLab - no fallbacks, no alternatives.
26
- */
27
- async function getGitLabDiff(repoRoot) {
28
- const git = (0, simple_git_1.default)(repoRoot);
29
- // Check if we're in a git repo
30
- const isRepo = await git.checkIsRepo();
31
- if (!isRepo) {
32
- throw new Error('Not a git repository. Threadline requires a git repository.');
33
- }
34
- // Get GitLab CI environment variables
35
- const mrIid = process.env.CI_MERGE_REQUEST_IID;
36
- const targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME;
37
- const sourceBranch = process.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME;
38
- const refName = process.env.CI_COMMIT_REF_NAME;
39
- const defaultBranch = process.env.CI_DEFAULT_BRANCH || 'main';
40
- // Scenario 1: MR Context
41
- if (mrIid) {
42
- if (!targetBranch || !sourceBranch) {
43
- throw new Error('GitLab MR context detected but CI_MERGE_REQUEST_TARGET_BRANCH_NAME or ' +
44
- 'CI_MERGE_REQUEST_SOURCE_BRANCH_NAME is missing. ' +
45
- 'This should be automatically provided by GitLab CI.');
46
- }
47
- // Fetch target branch (GitLab doesn't have it by default)
48
- console.log(` [GitLab] Fetching target branch: origin/${targetBranch}`);
49
- await git.fetch(['origin', `${targetBranch}:refs/remotes/origin/${targetBranch}`, '--depth=1']);
50
- // Diff target vs source
51
- const diff = await git.diff([`origin/${targetBranch}...origin/${sourceBranch}`, '-U200']);
52
- const diffSummary = await git.diffSummary([`origin/${targetBranch}...origin/${sourceBranch}`]);
53
- const changedFiles = diffSummary.files.map(f => f.file);
54
- return {
55
- diff: diff || '',
56
- changedFiles
57
- };
58
- }
59
- // Scenario 2 & 3: Branch Push
60
- if (!refName) {
61
- throw new Error('GitLab CI environment detected but CI_COMMIT_REF_NAME is not set. ' +
62
- 'This should be automatically provided by GitLab CI.');
63
- }
64
- // Scenario 3: Default Branch Push (e.g., direct commit to main)
65
- if (refName === defaultBranch) {
66
- console.log(` [GitLab] Push to default branch (${defaultBranch}), using HEAD~1...HEAD`);
67
- const diff = await git.diff(['HEAD~1...HEAD', '-U200']);
68
- const diffSummary = await git.diffSummary(['HEAD~1...HEAD']);
69
- const changedFiles = diffSummary.files.map(f => f.file);
70
- return {
71
- diff: diff || '',
72
- changedFiles
73
- };
74
- }
75
- // Scenario 2: Feature Branch Push
76
- console.log(` [GitLab] Feature branch push, fetching default branch: origin/${defaultBranch}`);
77
- await git.fetch(['origin', `${defaultBranch}:refs/remotes/origin/${defaultBranch}`, '--depth=1']);
78
- // Diff default vs feature
79
- const diff = await git.diff([`origin/${defaultBranch}...origin/${refName}`, '-U200']);
80
- const diffSummary = await git.diffSummary([`origin/${defaultBranch}...origin/${refName}`]);
81
- const changedFiles = diffSummary.files.map(f => f.file);
82
- return {
83
- diff: diff || '',
84
- changedFiles
85
- };
86
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getLocalDiff = getLocalDiff;
7
- const simple_git_1 = __importDefault(require("simple-git"));
8
- /**
9
- * Get diff for local development environment
10
- *
11
- * For local development, we check staged changes first, then unstaged changes.
12
- * This allows developers to review what they've staged before committing,
13
- * or review unstaged changes if nothing is staged.
14
- *
15
- * This is the ONLY implementation for local - no fallbacks, no alternatives.
16
- * If this doesn't work, we fail with a clear error.
17
- */
18
- async function getLocalDiff(repoRoot) {
19
- const git = (0, simple_git_1.default)(repoRoot);
20
- // Check if we're in a git repo
21
- const isRepo = await git.checkIsRepo();
22
- if (!isRepo) {
23
- throw new Error('Not a git repository. Threadline requires a git repository.');
24
- }
25
- // Get git status to determine what changes exist
26
- const status = await git.status();
27
- let diff;
28
- let changedFiles;
29
- // Priority 1: Use staged changes if available
30
- if (status.staged.length > 0) {
31
- diff = await git.diff(['--cached', '-U200']);
32
- // status.staged is an array of strings (file paths)
33
- changedFiles = status.staged;
34
- }
35
- // Priority 2: Use unstaged changes if no staged changes
36
- else if (status.files.length > 0) {
37
- diff = await git.diff(['-U200']);
38
- changedFiles = status.files
39
- .filter(f => f.working_dir !== ' ' || f.index !== ' ')
40
- .map(f => f.path);
41
- }
42
- // No changes at all
43
- else {
44
- return {
45
- diff: '',
46
- changedFiles: []
47
- };
48
- }
49
- return {
50
- diff: diff || '',
51
- changedFiles
52
- };
53
- }
package/dist/git/repo.js DELETED
@@ -1,253 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getGitHubRepoName = getGitHubRepoName;
40
- exports.getVercelRepoName = getVercelRepoName;
41
- exports.getLocalRepoName = getLocalRepoName;
42
- exports.getGitHubBranchName = getGitHubBranchName;
43
- exports.getVercelBranchName = getVercelBranchName;
44
- exports.getLocalBranchName = getLocalBranchName;
45
- exports.getGitLabRepoName = getGitLabRepoName;
46
- exports.getGitLabBranchName = getGitLabBranchName;
47
- exports.getDefaultBranchName = getDefaultBranchName;
48
- const simple_git_1 = __importDefault(require("simple-git"));
49
- const fs = __importStar(require("fs"));
50
- const path = __importStar(require("path"));
51
- /**
52
- * GitHub Actions: Get repository name
53
- *
54
- * Uses GITHUB_REPOSITORY environment variable (format: "owner/repo").
55
- * This is the ONLY method for GitHub - no fallbacks, no alternatives.
56
- */
57
- async function getGitHubRepoName(_repoRoot) {
58
- const githubRepo = process.env.GITHUB_REPOSITORY;
59
- if (!githubRepo) {
60
- throw new Error('GitHub Actions: GITHUB_REPOSITORY environment variable is not set. ' +
61
- 'This should be automatically provided by GitHub Actions.');
62
- }
63
- const serverUrl = process.env.GITHUB_SERVER_URL || 'https://github.com';
64
- return `${serverUrl}/${githubRepo}.git`;
65
- }
66
- /**
67
- * Vercel: Get repository name
68
- *
69
- * Uses VERCEL_GIT_REPO_OWNER and VERCEL_GIT_REPO_SLUG environment variables.
70
- * This is the ONLY method for Vercel - no fallbacks, no alternatives.
71
- */
72
- async function getVercelRepoName(_repoRoot) {
73
- const owner = process.env.VERCEL_GIT_REPO_OWNER;
74
- const slug = process.env.VERCEL_GIT_REPO_SLUG;
75
- if (!owner || !slug) {
76
- throw new Error('Vercel: VERCEL_GIT_REPO_OWNER or VERCEL_GIT_REPO_SLUG environment variable is not set. ' +
77
- 'This should be automatically provided by Vercel CI.');
78
- }
79
- return `https://github.com/${owner}/${slug}.git`;
80
- }
81
- /**
82
- * Local: Get repository name
83
- *
84
- * Uses git command to get origin remote URL.
85
- * This is the ONLY method for local - no fallbacks, no alternatives.
86
- * Git should always be available in local development.
87
- */
88
- async function getLocalRepoName(repoRoot) {
89
- const git = (0, simple_git_1.default)(repoRoot);
90
- // Check if we're in a git repo
91
- const isRepo = await git.checkIsRepo();
92
- if (!isRepo) {
93
- throw new Error('Local: Not a git repository. Threadline requires a git repository.');
94
- }
95
- try {
96
- const remotes = await git.getRemotes(true);
97
- const origin = remotes.find(r => r.name === 'origin');
98
- if (!origin || !origin.refs?.fetch) {
99
- throw new Error('Local: No origin remote found. ' +
100
- 'Please configure an origin remote: git remote add origin <url>');
101
- }
102
- return origin.refs.fetch;
103
- }
104
- catch (error) {
105
- // If it's already our error, re-throw it
106
- if (error instanceof Error && error.message.includes('Local:')) {
107
- throw error;
108
- }
109
- // Otherwise, wrap it
110
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
111
- throw new Error(`Local: Failed to get repository name from git: ${errorMessage}`);
112
- }
113
- }
114
- /**
115
- * GitHub Actions: Get branch name
116
- *
117
- * Uses GITHUB_REF_NAME environment variable.
118
- * This is the ONLY method for GitHub - no fallbacks, no alternatives.
119
- */
120
- async function getGitHubBranchName(_repoRoot) {
121
- const refName = process.env.GITHUB_REF_NAME;
122
- if (!refName) {
123
- throw new Error('GitHub Actions: GITHUB_REF_NAME environment variable is not set. ' +
124
- 'This should be automatically provided by GitHub Actions.');
125
- }
126
- return refName;
127
- }
128
- /**
129
- * Vercel: Get branch name
130
- *
131
- * Uses VERCEL_GIT_COMMIT_REF environment variable.
132
- * This is the ONLY method for Vercel - no fallbacks, no alternatives.
133
- */
134
- async function getVercelBranchName(_repoRoot) {
135
- const branchName = process.env.VERCEL_GIT_COMMIT_REF;
136
- if (!branchName) {
137
- throw new Error('Vercel: VERCEL_GIT_COMMIT_REF environment variable is not set. ' +
138
- 'This should be automatically provided by Vercel CI.');
139
- }
140
- return branchName;
141
- }
142
- /**
143
- * Local: Get branch name
144
- *
145
- * Uses git command to get current branch name.
146
- * This is the ONLY method for local - no fallbacks, no alternatives.
147
- * Git should always be available in local development.
148
- */
149
- async function getLocalBranchName(repoRoot) {
150
- const git = (0, simple_git_1.default)(repoRoot);
151
- // Check if we're in a git repo
152
- const isRepo = await git.checkIsRepo();
153
- if (!isRepo) {
154
- throw new Error('Local: Not a git repository. Threadline requires a git repository.');
155
- }
156
- try {
157
- const branchName = await git.revparse(['--abbrev-ref', 'HEAD']);
158
- if (!branchName || branchName.trim() === '') {
159
- throw new Error('Local: Could not determine branch name. ' +
160
- 'This might be a brand new repository with no commits. ' +
161
- 'Make at least one commit before running threadlines check.');
162
- }
163
- // Handle detached HEAD state
164
- if (branchName === 'HEAD') {
165
- throw new Error('Local: Currently in detached HEAD state. ' +
166
- 'Please checkout a branch before running threadlines check.');
167
- }
168
- return branchName.trim();
169
- }
170
- catch (error) {
171
- // If it's already our error, re-throw it
172
- if (error instanceof Error && error.message.includes('Local:')) {
173
- throw error;
174
- }
175
- // Otherwise, wrap it
176
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
177
- throw new Error(`Local: Failed to get branch name from git: ${errorMessage}`);
178
- }
179
- }
180
- /**
181
- * GitLab CI: Get repository name
182
- *
183
- * Uses CI_PROJECT_URL environment variable.
184
- * This is the ONLY method for GitLab - no fallbacks, no alternatives.
185
- */
186
- async function getGitLabRepoName(_repoRoot) {
187
- const projectUrl = process.env.CI_PROJECT_URL;
188
- if (!projectUrl) {
189
- throw new Error('GitLab CI: CI_PROJECT_URL environment variable is not set. ' +
190
- 'This should be automatically provided by GitLab CI.');
191
- }
192
- // CI_PROJECT_URL is like "https://gitlab.com/owner/repo"
193
- // Add .git suffix for consistency with other environments
194
- return `${projectUrl}.git`;
195
- }
196
- /**
197
- * GitLab CI: Get branch name
198
- *
199
- * Uses CI_COMMIT_REF_NAME environment variable.
200
- * This is the ONLY method for GitLab - no fallbacks, no alternatives.
201
- */
202
- async function getGitLabBranchName(_repoRoot) {
203
- const refName = process.env.CI_COMMIT_REF_NAME;
204
- if (!refName) {
205
- throw new Error('GitLab CI: CI_COMMIT_REF_NAME environment variable is not set. ' +
206
- 'This should be automatically provided by GitLab CI.');
207
- }
208
- return refName;
209
- }
210
- /**
211
- * Detects the default branch name of the repository for GitHub Actions.
212
- *
213
- * Uses GITHUB_EVENT_PATH JSON (repository.default_branch) - the most authoritative source
214
- * provided directly by GitHub Actions.
215
- *
216
- * This function is ONLY called from GitHub Actions context (getGitHubDiff),
217
- * so GITHUB_EVENT_PATH should always be available. If it's not, we fail with a clear error.
218
- *
219
- * Returns the branch name (e.g., "main", "master") without the "origin/" prefix.
220
- * Throws an error if the default branch cannot be detected.
221
- */
222
- async function getDefaultBranchName(_repoRoot) {
223
- // GitHub Actions provides GITHUB_EVENT_PATH which contains repository.default_branch
224
- const githubEventPath = process.env.GITHUB_EVENT_PATH;
225
- if (!githubEventPath) {
226
- throw new Error('GITHUB_EVENT_PATH environment variable is not set. ' +
227
- 'This should be automatically provided by GitHub Actions. ' +
228
- 'This function should only be called in GitHub Actions context.');
229
- }
230
- try {
231
- const eventPath = path.resolve(githubEventPath);
232
- if (!fs.existsSync(eventPath)) {
233
- throw new Error(`GITHUB_EVENT_PATH file does not exist: ${eventPath}`);
234
- }
235
- const eventJson = JSON.parse(fs.readFileSync(eventPath, 'utf8'));
236
- const defaultBranch = eventJson.repository?.default_branch;
237
- if (!defaultBranch || typeof defaultBranch !== 'string') {
238
- throw new Error('Could not find repository.default_branch in GITHUB_EVENT_PATH JSON. ' +
239
- 'This should be automatically provided by GitHub Actions.');
240
- }
241
- return defaultBranch;
242
- }
243
- catch (error) {
244
- // If it's already our error, re-throw it
245
- if (error instanceof Error && (error.message.includes('GITHUB_EVENT_PATH') || error.message.includes('default_branch'))) {
246
- throw error;
247
- }
248
- // Otherwise, wrap it
249
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
250
- throw new Error(`Failed to read or parse GITHUB_EVENT_PATH: ${errorMessage}. ` +
251
- 'This should be automatically provided by GitHub Actions.');
252
- }
253
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getVercelDiff = getVercelDiff;
7
- const simple_git_1 = __importDefault(require("simple-git"));
8
- /**
9
- * Get diff for Vercel CI environment
10
- *
11
- * Vercel provides VERCEL_GIT_COMMIT_SHA which contains the commit being deployed.
12
- * This function gets the diff for that specific commit using git show.
13
- *
14
- * This is the ONLY implementation for Vercel - no fallbacks, no alternatives.
15
- * If this doesn't work, we fail with a clear error.
16
- */
17
- async function getVercelDiff(repoRoot) {
18
- const git = (0, simple_git_1.default)(repoRoot);
19
- // Check if we're in a git repo
20
- const isRepo = await git.checkIsRepo();
21
- if (!isRepo) {
22
- throw new Error('Not a git repository. Threadline requires a git repository.');
23
- }
24
- // Get commit SHA from Vercel environment variable
25
- const commitSha = process.env.VERCEL_GIT_COMMIT_SHA;
26
- if (!commitSha) {
27
- throw new Error('VERCEL_GIT_COMMIT_SHA environment variable is not set. ' +
28
- 'This should be automatically provided by Vercel CI.');
29
- }
30
- // Get diff using git show - this is the ONLY way we get diff in Vercel
31
- const diff = await git.show([commitSha, '--format=', '--no-color', '-U200']);
32
- // Get changed files using git show --name-only
33
- const commitFiles = await git.show([commitSha, '--name-only', '--format=', '--pretty=format:']);
34
- const changedFiles = commitFiles
35
- .split('\n')
36
- .filter(line => line.trim().length > 0)
37
- .map(line => line.trim());
38
- return {
39
- diff: diff || '',
40
- changedFiles
41
- };
42
- }
@@ -1,65 +0,0 @@
1
- "use strict";
2
- /**
3
- * Git Diff Execution
4
- *
5
- * Executes the appropriate git diff function based on environment.
6
- * Each environment has ONE SINGLE IMPLEMENTATION - no fallbacks, no alternatives.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getDiffForEnvironment = getDiffForEnvironment;
10
- exports.getContextDescription = getContextDescription;
11
- const vercel_diff_1 = require("../git/vercel-diff");
12
- const github_diff_1 = require("../git/github-diff");
13
- const local_diff_1 = require("../git/local-diff");
14
- const gitlab_diff_1 = require("../git/gitlab-diff");
15
- /**
16
- * Executes the appropriate git diff function based on environment.
17
- *
18
- * Each environment has a single, specific implementation:
19
- * - Vercel: Uses VERCEL_GIT_COMMIT_SHA, gets commit diff via git show
20
- * - GitHub: Uses GITHUB_BASE_REF/GITHUB_HEAD_REF for PRs, GITHUB_REF_NAME for branches
21
- * - GitLab: Uses CI_MERGE_REQUEST_TARGET_BRANCH_NAME/CI_MERGE_REQUEST_SOURCE_BRANCH_NAME for MRs, CI_COMMIT_REF_NAME for branches
22
- * - Local: Uses staged changes first, then unstaged changes
23
- *
24
- * No fallbacks - if the environment-specific implementation fails, we fail clearly.
25
- * Each environment is completely isolated - changes to one don't affect others.
26
- */
27
- async function getDiffForEnvironment(environment, repoRoot, _context) {
28
- switch (environment) {
29
- case 'vercel':
30
- // Vercel: Single implementation using commit SHA
31
- return await (0, vercel_diff_1.getVercelDiff)(repoRoot);
32
- case 'github':
33
- // GitHub: Single implementation using GitHub-provided environment variables
34
- return await (0, github_diff_1.getGitHubDiff)(repoRoot);
35
- case 'gitlab':
36
- // GitLab: Single implementation using GitLab-provided environment variables
37
- return await (0, gitlab_diff_1.getGitLabDiff)(repoRoot);
38
- case 'local':
39
- // Local: Single implementation using staged/unstaged changes
40
- return await (0, local_diff_1.getLocalDiff)(repoRoot);
41
- default:
42
- const _exhaustive = environment;
43
- throw new Error(`Unknown environment: ${_exhaustive}`);
44
- }
45
- }
46
- /**
47
- * Returns a human-readable description of the context for logging.
48
- */
49
- function getContextDescription(context) {
50
- switch (context.type) {
51
- case 'pr':
52
- return `PR: ${context.prNumber}`;
53
- case 'mr':
54
- return `MR: ${context.mrNumber}`;
55
- case 'branch':
56
- return `branch: ${context.branchName}`;
57
- case 'commit':
58
- return `commit: ${context.commitSha.substring(0, 7)}`;
59
- case 'local':
60
- return 'local changes';
61
- default:
62
- const _exhaustive = context;
63
- throw new Error(`Unknown context type: ${_exhaustive}`);
64
- }
65
- }