threadlines 0.2.10 → 0.2.11
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/github.js +23 -12
- package/package.json +1 -1
package/dist/git/github.js
CHANGED
|
@@ -83,7 +83,7 @@ async function getDiff(repoRoot) {
|
|
|
83
83
|
const git = (0, simple_git_1.default)(repoRoot);
|
|
84
84
|
const eventName = process.env.GITHUB_EVENT_NAME;
|
|
85
85
|
const baseRef = process.env.GITHUB_BASE_REF;
|
|
86
|
-
// PR Context:
|
|
86
|
+
// PR Context: Only pull_request events have GITHUB_BASE_REF set
|
|
87
87
|
if (eventName === 'pull_request') {
|
|
88
88
|
if (!baseRef) {
|
|
89
89
|
throw new Error('GitHub PR context detected but GITHUB_BASE_REF is missing. ' +
|
|
@@ -91,10 +91,19 @@ async function getDiff(repoRoot) {
|
|
|
91
91
|
}
|
|
92
92
|
// Fetch base branch on-demand (works with shallow clones)
|
|
93
93
|
logger_1.logger.debug(`Fetching base branch: origin/${baseRef}`);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
try {
|
|
95
|
+
await git.fetch(['origin', `${baseRef}:refs/remotes/origin/${baseRef}`, '--depth=1']);
|
|
96
|
+
}
|
|
97
|
+
catch (fetchError) {
|
|
98
|
+
throw new Error(`Failed to fetch base branch origin/${baseRef}. ` +
|
|
99
|
+
`This is required for PR diff comparison. Error: ${fetchError instanceof Error ? fetchError.message : 'Unknown error'}`);
|
|
100
|
+
}
|
|
101
|
+
logger_1.logger.debug(`PR context, using origin/${baseRef}..HEAD (two dots for direct comparison)`);
|
|
102
|
+
// Use two dots (..) instead of three dots (...) for direct comparison
|
|
103
|
+
// Three dots requires finding merge base which can fail with shallow clones
|
|
104
|
+
// Two dots shows all changes in HEAD that aren't in origin/${baseRef}
|
|
105
|
+
const diff = await git.diff([`origin/${baseRef}..HEAD`, '-U200']);
|
|
106
|
+
const diffSummary = await git.diffSummary([`origin/${baseRef}..HEAD`]);
|
|
98
107
|
const changedFiles = diffSummary.files.map(f => f.file);
|
|
99
108
|
return {
|
|
100
109
|
diff: diff || '',
|
|
@@ -102,13 +111,15 @@ async function getDiff(repoRoot) {
|
|
|
102
111
|
};
|
|
103
112
|
}
|
|
104
113
|
// Any push (main or feature branch): Review last commit only
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
// Use git show HEAD - works with shallow clones and shows the commit diff
|
|
115
|
+
const diff = await git.show(['HEAD', '--format=', '--no-color', '-U200']);
|
|
116
|
+
// Extract changed files from git show
|
|
117
|
+
const showNameOnly = await git.show(['HEAD', '--name-only', '--format=', '--pretty=format:']);
|
|
118
|
+
const changedFiles = showNameOnly
|
|
119
|
+
.split('\n')
|
|
120
|
+
.filter(line => line.trim().length > 0)
|
|
121
|
+
.map(line => line.trim());
|
|
122
|
+
return { diff: diff || '', changedFiles };
|
|
112
123
|
}
|
|
113
124
|
/**
|
|
114
125
|
* Gets repository name for GitHub Actions
|