threadlines 0.1.23 → 0.1.24
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/git/context.js +7 -2
- package/dist/git/github-diff.js +7 -1
- package/dist/git/gitlab-diff.js +42 -19
- package/dist/git/repo.js +32 -0
- package/package.json +1 -1
package/dist/git/context.js
CHANGED
|
@@ -16,6 +16,8 @@ const repo_2 = require("./repo");
|
|
|
16
16
|
* Each environment has a single, specific implementation:
|
|
17
17
|
* - GitHub: Uses GITHUB_REPOSITORY, GITHUB_REF_NAME, and GitHub-specific diff logic
|
|
18
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)
|
|
19
21
|
* - Local: Uses git commands for repo/branch, and local diff logic
|
|
20
22
|
*
|
|
21
23
|
* All methods fail loudly if they can't get the required information.
|
|
@@ -41,8 +43,11 @@ async function getGitContextForEnvironment(environment, repoRoot) {
|
|
|
41
43
|
branchName: await (0, repo_2.getLocalBranchName)(repoRoot)
|
|
42
44
|
};
|
|
43
45
|
case 'gitlab':
|
|
44
|
-
|
|
45
|
-
|
|
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
|
+
};
|
|
46
51
|
default:
|
|
47
52
|
const _exhaustive = environment;
|
|
48
53
|
throw new Error(`Unknown environment: ${_exhaustive}`);
|
package/dist/git/github-diff.js
CHANGED
|
@@ -27,7 +27,13 @@ const repo_1 = require("./repo");
|
|
|
27
27
|
* Compare: origin/default~1 vs origin/default
|
|
28
28
|
* Shows: Changes in the direct commit
|
|
29
29
|
*
|
|
30
|
-
|
|
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
|
+
*/
|
|
31
37
|
async function getGitHubDiff(repoRoot) {
|
|
32
38
|
const git = (0, simple_git_1.default)(repoRoot);
|
|
33
39
|
// Check if we're in a git repo
|
package/dist/git/gitlab-diff.js
CHANGED
|
@@ -8,13 +8,21 @@ const simple_git_1 = __importDefault(require("simple-git"));
|
|
|
8
8
|
/**
|
|
9
9
|
* Get diff for GitLab CI environment
|
|
10
10
|
*
|
|
11
|
-
* GitLab CI
|
|
12
|
-
*
|
|
13
|
-
* - Branch context: CI_COMMIT_REF_NAME (current branch), compare against origin/main
|
|
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.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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.
|
|
18
26
|
*/
|
|
19
27
|
async function getGitLabDiff(repoRoot) {
|
|
20
28
|
const git = (0, simple_git_1.default)(repoRoot);
|
|
@@ -23,19 +31,23 @@ async function getGitLabDiff(repoRoot) {
|
|
|
23
31
|
if (!isRepo) {
|
|
24
32
|
throw new Error('Not a git repository. Threadline requires a git repository.');
|
|
25
33
|
}
|
|
26
|
-
//
|
|
34
|
+
// Get GitLab CI environment variables
|
|
27
35
|
const mrIid = process.env.CI_MERGE_REQUEST_IID;
|
|
28
36
|
const targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME;
|
|
29
37
|
const sourceBranch = process.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME;
|
|
30
38
|
const refName = process.env.CI_COMMIT_REF_NAME;
|
|
31
|
-
|
|
39
|
+
const defaultBranch = process.env.CI_DEFAULT_BRANCH || 'main';
|
|
40
|
+
// Scenario 1: MR Context
|
|
32
41
|
if (mrIid) {
|
|
33
42
|
if (!targetBranch || !sourceBranch) {
|
|
34
43
|
throw new Error('GitLab MR context detected but CI_MERGE_REQUEST_TARGET_BRANCH_NAME or ' +
|
|
35
44
|
'CI_MERGE_REQUEST_SOURCE_BRANCH_NAME is missing. ' +
|
|
36
45
|
'This should be automatically provided by GitLab CI.');
|
|
37
46
|
}
|
|
38
|
-
//
|
|
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
|
|
39
51
|
const diff = await git.diff([`origin/${targetBranch}...origin/${sourceBranch}`, '-U200']);
|
|
40
52
|
const diffSummary = await git.diffSummary([`origin/${targetBranch}...origin/${sourceBranch}`]);
|
|
41
53
|
const changedFiles = diffSummary.files.map(f => f.file);
|
|
@@ -44,20 +56,31 @@ async function getGitLabDiff(repoRoot) {
|
|
|
44
56
|
changedFiles
|
|
45
57
|
};
|
|
46
58
|
}
|
|
47
|
-
//
|
|
48
|
-
if (refName) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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']);
|
|
53
69
|
const changedFiles = diffSummary.files.map(f => f.file);
|
|
54
70
|
return {
|
|
55
71
|
diff: diff || '',
|
|
56
72
|
changedFiles
|
|
57
73
|
};
|
|
58
74
|
}
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
};
|
|
63
86
|
}
|
package/dist/git/repo.js
CHANGED
|
@@ -42,6 +42,8 @@ exports.getLocalRepoName = getLocalRepoName;
|
|
|
42
42
|
exports.getGitHubBranchName = getGitHubBranchName;
|
|
43
43
|
exports.getVercelBranchName = getVercelBranchName;
|
|
44
44
|
exports.getLocalBranchName = getLocalBranchName;
|
|
45
|
+
exports.getGitLabRepoName = getGitLabRepoName;
|
|
46
|
+
exports.getGitLabBranchName = getGitLabBranchName;
|
|
45
47
|
exports.getDefaultBranchName = getDefaultBranchName;
|
|
46
48
|
const simple_git_1 = __importDefault(require("simple-git"));
|
|
47
49
|
const fs = __importStar(require("fs"));
|
|
@@ -173,6 +175,36 @@ async function getLocalBranchName(repoRoot) {
|
|
|
173
175
|
throw new Error(`Local: Failed to get branch name from git: ${error.message}`);
|
|
174
176
|
}
|
|
175
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* GitLab CI: Get repository name
|
|
180
|
+
*
|
|
181
|
+
* Uses CI_PROJECT_URL environment variable.
|
|
182
|
+
* This is the ONLY method for GitLab - no fallbacks, no alternatives.
|
|
183
|
+
*/
|
|
184
|
+
async function getGitLabRepoName(repoRoot) {
|
|
185
|
+
const projectUrl = process.env.CI_PROJECT_URL;
|
|
186
|
+
if (!projectUrl) {
|
|
187
|
+
throw new Error('GitLab CI: CI_PROJECT_URL environment variable is not set. ' +
|
|
188
|
+
'This should be automatically provided by GitLab CI.');
|
|
189
|
+
}
|
|
190
|
+
// CI_PROJECT_URL is like "https://gitlab.com/owner/repo"
|
|
191
|
+
// Add .git suffix for consistency with other environments
|
|
192
|
+
return `${projectUrl}.git`;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* GitLab CI: Get branch name
|
|
196
|
+
*
|
|
197
|
+
* Uses CI_COMMIT_REF_NAME environment variable.
|
|
198
|
+
* This is the ONLY method for GitLab - no fallbacks, no alternatives.
|
|
199
|
+
*/
|
|
200
|
+
async function getGitLabBranchName(repoRoot) {
|
|
201
|
+
const refName = process.env.CI_COMMIT_REF_NAME;
|
|
202
|
+
if (!refName) {
|
|
203
|
+
throw new Error('GitLab CI: CI_COMMIT_REF_NAME environment variable is not set. ' +
|
|
204
|
+
'This should be automatically provided by GitLab CI.');
|
|
205
|
+
}
|
|
206
|
+
return refName;
|
|
207
|
+
}
|
|
176
208
|
/**
|
|
177
209
|
* Detects the default branch name of the repository for GitHub Actions.
|
|
178
210
|
*
|