threadlines 0.2.4 → 0.2.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/dist/commands/check.js +97 -138
- package/dist/git/bitbucket.js +259 -0
- package/dist/git/repo.js +1 -1
- package/dist/types/git.js +5 -0
- package/dist/utils/context.js +42 -0
- 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/vercel-diff.js +0 -42
- package/dist/utils/git-diff-executor.js +0 -65
- package/dist/utils/metadata.js +0 -290
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
|
-
}
|
package/dist/git/github-diff.js
DELETED
|
@@ -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
|
-
}
|
package/dist/git/gitlab-diff.js
DELETED
|
@@ -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
|
-
}
|
package/dist/git/local-diff.js
DELETED
|
@@ -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/vercel-diff.js
DELETED
|
@@ -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
|
-
}
|