@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/utils.js +23 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logickernel/agileflow",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Automatic semantic versioning and changelog generation based on conventional commits",
5
5
  "main": "src/index.js",
6
6
  "bin": {
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 (!branch) {
60
- throw new Error('Repository is in a detached HEAD state. Please check out a branch and try again.');
59
+ if (branch) {
60
+ return branch;
61
61
  }
62
- return branch;
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
- return [];
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} ${branch}`;
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