@logickernel/agileflow 0.16.1 → 0.17.0
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/index.js +2 -1
- package/src/utils.js +56 -3
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -15,6 +15,7 @@ Commands:
|
|
|
15
15
|
push [remote] Push a semantic version tag to the remote repository (default: origin)
|
|
16
16
|
gitlab Create a semantic version tag via GitLab API (for GitLab CI)
|
|
17
17
|
github Create a semantic version tag via GitHub API (for GitHub Actions)
|
|
18
|
+
version Print the agileflow tool version
|
|
18
19
|
|
|
19
20
|
Options:
|
|
20
21
|
--quiet Only output the next version (or empty if no bump)
|
|
@@ -33,7 +34,7 @@ const VALID_OPTIONS = ['--quiet', '--help', '-h', '--version', '-v'];
|
|
|
33
34
|
/**
|
|
34
35
|
* Valid commands.
|
|
35
36
|
*/
|
|
36
|
-
const VALID_COMMANDS = ['push', 'gitlab', 'github'];
|
|
37
|
+
const VALID_COMMANDS = ['push', 'gitlab', 'github', 'version'];
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* Parses command line arguments and validates them.
|
package/src/utils.js
CHANGED
|
@@ -108,11 +108,10 @@ function fetchTags() {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* Builds a map
|
|
112
|
-
* Uses a single git call instead of one per commit.
|
|
111
|
+
* Builds a tag map from locally stored tags.
|
|
113
112
|
* @returns {Map<string, string[]>}
|
|
114
113
|
*/
|
|
115
|
-
function
|
|
114
|
+
function buildTagMapFromLocal() {
|
|
116
115
|
try {
|
|
117
116
|
// %(objecttype) distinguishes lightweight (commit) from annotated (tag) refs.
|
|
118
117
|
// %(*objectname) is the peeled commit SHA for annotated tags, but may be empty
|
|
@@ -152,6 +151,60 @@ function buildTagMap() {
|
|
|
152
151
|
}
|
|
153
152
|
}
|
|
154
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Builds a tag map by reading tags directly from the remote via ls-remote.
|
|
156
|
+
* Used as a fallback when git fetch --tags fails (e.g. in shallow CI clones).
|
|
157
|
+
* Does not store anything locally.
|
|
158
|
+
* @returns {Map<string, string[]>}
|
|
159
|
+
*/
|
|
160
|
+
function buildTagMapFromRemote() {
|
|
161
|
+
try {
|
|
162
|
+
const remotes = runWithOutput('git remote').trim();
|
|
163
|
+
if (!remotes) return new Map();
|
|
164
|
+
const remote = remotes.split('\n')[0].trim();
|
|
165
|
+
const output = runWithOutput(`git ls-remote --tags ${remote}`).trim();
|
|
166
|
+
if (!output) return new Map();
|
|
167
|
+
|
|
168
|
+
const map = new Map();
|
|
169
|
+
const direct = new Map(); // tagName -> SHA (tag obj or commit)
|
|
170
|
+
const peeled = new Map(); // tagName -> commit SHA (from ^{} entries)
|
|
171
|
+
|
|
172
|
+
for (const line of output.split('\n')) {
|
|
173
|
+
const tabIdx = line.indexOf('\t');
|
|
174
|
+
if (tabIdx === -1) continue;
|
|
175
|
+
const sha = line.slice(0, tabIdx).trim();
|
|
176
|
+
const ref = line.slice(tabIdx + 1).trim();
|
|
177
|
+
if (ref.endsWith('^{}')) {
|
|
178
|
+
// Annotated tag: peeled entry gives the commit SHA
|
|
179
|
+
peeled.set(ref.slice('refs/tags/'.length, -3), sha);
|
|
180
|
+
} else if (ref.startsWith('refs/tags/')) {
|
|
181
|
+
direct.set(ref.slice('refs/tags/'.length), sha);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
for (const [name, sha] of direct) {
|
|
186
|
+
const commitSha = peeled.get(name) || sha;
|
|
187
|
+
if (!map.has(commitSha)) map.set(commitSha, []);
|
|
188
|
+
map.get(commitSha).push(name);
|
|
189
|
+
}
|
|
190
|
+
return map;
|
|
191
|
+
} catch {
|
|
192
|
+
return new Map();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Builds a map of commit SHA → tag names for all tags in the repository.
|
|
198
|
+
* Tries local tags first; falls back to reading from the remote when local
|
|
199
|
+
* tags are absent (common in shallow CI clones where git fetch --tags fails).
|
|
200
|
+
* @returns {Map<string, string[]>}
|
|
201
|
+
*/
|
|
202
|
+
function buildTagMap() {
|
|
203
|
+
const local = buildTagMapFromLocal();
|
|
204
|
+
if (local.size > 0) return local;
|
|
205
|
+
return buildTagMapFromRemote();
|
|
206
|
+
}
|
|
207
|
+
|
|
155
208
|
/**
|
|
156
209
|
* Parses a conventional commit message.
|
|
157
210
|
* @param {string} message - The commit message to parse
|