@logickernel/agileflow 0.4.1 → 0.4.2
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/package.json +1 -1
- package/src/utils.js +23 -6
package/package.json
CHANGED
package/src/utils.js
CHANGED
|
@@ -52,14 +52,23 @@ function ensureGitRepo() {
|
|
|
52
52
|
/**
|
|
53
53
|
* Gets the current branch name.
|
|
54
54
|
* @returns {string} Current branch name
|
|
55
|
-
* @throws {Error} If in detached HEAD state
|
|
55
|
+
* @throws {Error} If in detached HEAD state and no CI environment variable is available
|
|
56
56
|
*/
|
|
57
57
|
function getCurrentBranch() {
|
|
58
58
|
const branch = runWithOutput('git branch --show-current').trim();
|
|
59
|
-
if (
|
|
60
|
-
|
|
59
|
+
if (branch) {
|
|
60
|
+
return branch;
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
|
|
63
|
+
// Handle detached HEAD state (common in CI environments)
|
|
64
|
+
// GitLab CI provides CI_COMMIT_BRANCH (for branches) or CI_COMMIT_REF_NAME (for branches/tags)
|
|
65
|
+
// GitHub Actions provides GITHUB_REF_NAME (for branches/tags)
|
|
66
|
+
const ciBranch = process.env.CI_COMMIT_BRANCH || process.env.CI_COMMIT_REF_NAME || process.env.GITHUB_REF_NAME;
|
|
67
|
+
if (ciBranch) {
|
|
68
|
+
return ciBranch;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
throw new Error('Repository is in a detached HEAD state. Please check out a branch and try again.');
|
|
63
72
|
}
|
|
64
73
|
|
|
65
74
|
// Conventional commit type configuration
|
|
@@ -375,17 +384,25 @@ function calculateNextVersionAndChangelog(expandedInfo) {
|
|
|
375
384
|
* @returns {Array<{hash: string, datetime: string, author: string, message: string, tags: Array<string>}>}
|
|
376
385
|
*/
|
|
377
386
|
function getAllBranchCommits(branch) {
|
|
387
|
+
// Try to resolve the branch (may be a local branch or remote branch like origin/main)
|
|
388
|
+
let branchRef = branch;
|
|
378
389
|
try {
|
|
379
390
|
runWithOutput(`git rev-parse --verify ${branch}`);
|
|
380
391
|
} catch {
|
|
381
|
-
|
|
392
|
+
// Try with origin/ prefix (common in CI environments where local branch doesn't exist)
|
|
393
|
+
try {
|
|
394
|
+
runWithOutput(`git rev-parse --verify origin/${branch}`);
|
|
395
|
+
branchRef = `origin/${branch}`;
|
|
396
|
+
} catch {
|
|
397
|
+
return [];
|
|
398
|
+
}
|
|
382
399
|
}
|
|
383
400
|
|
|
384
401
|
const RS = '\x1E';
|
|
385
402
|
const COMMIT_SEP = `${RS}${RS}`;
|
|
386
403
|
|
|
387
404
|
try {
|
|
388
|
-
const logCmd = `git log --format=%H${RS}%ai${RS}%an${RS}%B${COMMIT_SEP} ${
|
|
405
|
+
const logCmd = `git log --format=%H${RS}%ai${RS}%an${RS}%B${COMMIT_SEP} ${branchRef}`;
|
|
389
406
|
const output = runWithOutput(logCmd).trim();
|
|
390
407
|
if (!output) return [];
|
|
391
408
|
|