release-cherry-pick 1.0.3 → 1.1.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/README.md +30 -10
- package/package.json +5 -1
- package/src/config/defaults.js +5 -0
- package/src/config/loader.js +9 -1
- package/src/config/setup.js +201 -20
- package/src/config/validator.js +7 -0
- package/src/git/branch-parser.js +111 -3
- package/src/git/branch-selector.js +76 -4
- package/src/git/cherry-pick.js +64 -7
- package/src/gitlab/client.js +32 -1
- package/src/gitlab/mr-creator.js +1 -0
- package/src/index.js +9 -1
- package/src/workflow/release.js +295 -51
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Given a list of task IDs (from a file, a `-b` flag, or interactive branch select
|
|
|
25
25
|
3. **Cherry-picks only that task's own commits** onto the release branch — matched by the team's `[TASK-ID] description` commit message convention (not a naive branch diff, which breaks when a branch wasn't cut from a recent `staging`).
|
|
26
26
|
4. **Drafts the MR title and description with Anthropic Claude** from the picked commits, falling back to a static template if AI is disabled or fails.
|
|
27
27
|
5. **Lists real GitLab project members** for the reviewer prompt, pre-selecting your configured default reviewers.
|
|
28
|
-
6. **Creates the MR** with squash-commits and delete-source-branch checked by default, assigned to your configured default assignees.
|
|
28
|
+
6. **Creates the MR** with squash-commits and delete-source-branch checked by default, assigned to your configured default assignees and tagged with your configured default labels.
|
|
29
29
|
7. **Never auto-resolves problems for you**: if cherry-picking conflicts, or the release branch already exists remotely, it stops touching that branch immediately and reports it — you decide manually. Branches whose changes are already present get reported as `SKIPPED`, not silently pushed.
|
|
30
30
|
8. **Produces a final report** (console + `release-summary.md`) showing exactly which branches shipped, which need manual conflict resolution, which were skipped, and the MR link for each.
|
|
31
31
|
|
|
@@ -66,9 +66,24 @@ node src/index.js release --file branches.txt
|
|
|
66
66
|
# Direct — comma-separated task IDs and/or full branch names
|
|
67
67
|
node src/index.js release --branches PB-123,PB-124
|
|
68
68
|
node src/index.js release --branches feature/PB-123-list-user,hotfix/PB-124-fix-favicon
|
|
69
|
+
|
|
70
|
+
# Look up branches on origin only (ignore local branches)
|
|
71
|
+
node src/index.js release --remote --branches PB-123
|
|
72
|
+
|
|
73
|
+
# Also cherry-pick commits that are missing the "[PB-123]" tag: hashes in brackets after the task
|
|
74
|
+
node src/index.js release --branches "PB-123[3f2a9c1,8d1e004],PB-124[a1b2c3d],PB-125"
|
|
75
|
+
|
|
76
|
+
# ...or with --commits (repeatable, one per task)
|
|
77
|
+
node src/index.js release --branches PB-123,PB-124 --commits PB-123=3f2a9c1,8d1e004
|
|
69
78
|
```
|
|
70
79
|
|
|
71
|
-
|
|
80
|
+
In PowerShell, **quote comma-separated lists** (`-b "PB-123,PB-124"`): unquoted, PowerShell turns `PB-123,PB-124` into an array and the npm `.ps1` shim passes it on as `PB-123 PB-124`.
|
|
81
|
+
|
|
82
|
+
**Commits missing the task tag.** Commits are found by their `[TASK-ID] description` title. One that mentions the ID loosely (`PB-123: fix`) is detected and offered; one with no ID at all (`fix typo`) can only be added by hash: in brackets after the task in `-b` (`PB-123[<hash>,<hash>]`, a leading `+` on each hash is optional), with `--commits PB-123=<hash>[,<hash>...]`, with `[+<hash>, ...]` at the end of the task's line in the branch list file, or by typing it when a task has no tagged commits (the tool offers it). Each hash is checked before the release branch is created: unknown/ambiguous hashes and merge commits make the task `NO PROCEDE`, commits already on staging are skipped, and a commit that isn't on the task's branch needs your confirmation. Added commits are cherry-picked in branch-history order with the tagged ones and listed under the task in the summary. Hashes given for the same task in several ways are merged. They're ignored with `--list-branches`, which doesn't cherry-pick.
|
|
83
|
+
|
|
84
|
+
A bare task ID is resolved to its real branch (same as the file input); for a full branch name, the task ID is extracted from it. Branches whose name doesn't start with a task ID are skipped with a warning.
|
|
85
|
+
|
|
86
|
+
**Where branches are looked up.** By default (`git.branchSource: "local"`) the tool looks at your **local** feature/hotfix branches first and falls back to `origin` for branches you don't have locally, so a branch you haven't pushed can be released too. Commits are cherry-picked from whichever copy was chosen; the release branch is still created from `origin/staging` and pushed, and the MR is opened from it, so the source branch never needs to be on origin. If your local copy is **behind** `origin` (someone pushed commits you haven't pulled), the tool says so and asks which version to release — `origin`'s by default — instead of silently leaving those commits out. Use `--remote` (or `git.branchSource: "remote"`) to look at `origin` only, and `--local` to force local-first when the config says `remote`. `--list-branches` opens each MR straight from the source branch, so it always looks branches up on `origin` and can't be combined with `--local`.
|
|
72
87
|
|
|
73
88
|
### Configure
|
|
74
89
|
|
|
@@ -85,9 +100,10 @@ node src/index.js config --show
|
|
|
85
100
|
```
|
|
86
101
|
*PB-I3217*: Al gestionar autos de una póliza y al renovar una póliza de auto, el campo Endoso no está listando los posibles valores a seleccionar.
|
|
87
102
|
*PB-I3218*: Error al listar "Coberturas afectadas" (Configuraciones / Reclamos / Coberturas afectadas).
|
|
103
|
+
*PB-I3220*: Corregir redirección del login [+3f2a9c1, +8d1e004]
|
|
88
104
|
```
|
|
89
105
|
|
|
90
|
-
The tool resolves each task ID to its real
|
|
106
|
+
The tool resolves each task ID to its real branch automatically — local first, then `origin` (see above) — asking you to disambiguate if more than one branch matches. An optional `[+hash, ...]` at the end of a line adds those commits to the task's cherry-pick (see "Commits missing the task tag" above); it isn't part of the description used for the MR title.
|
|
91
107
|
|
|
92
108
|
### Configuration file
|
|
93
109
|
|
|
@@ -97,6 +113,7 @@ Since it can hold secrets (`gitlab.token`, `ai.apiKey`), the configuration is **
|
|
|
97
113
|
{
|
|
98
114
|
"git": {
|
|
99
115
|
"stagingBranch": "staging",
|
|
116
|
+
"branchSource": "local",
|
|
100
117
|
"branchPrefix": {
|
|
101
118
|
"feature": "feature/",
|
|
102
119
|
"hotfix": "hotfix/",
|
|
@@ -119,6 +136,7 @@ Since it can hold secrets (`gitlab.token`, `ai.apiKey`), the configuration is **
|
|
|
119
136
|
"mrTitleFormat": "[{taskId}] {description}",
|
|
120
137
|
"defaultReviewers": [],
|
|
121
138
|
"defaultAssignees": [],
|
|
139
|
+
"defaultLabels": [],
|
|
122
140
|
"mrSquash": true,
|
|
123
141
|
"mrRemoveSourceBranch": true,
|
|
124
142
|
"branches": []
|
|
@@ -130,7 +148,7 @@ Since it can hold secrets (`gitlab.token`, `ai.apiKey`), the configuration is **
|
|
|
130
148
|
|
|
131
149
|
Any option missing from the file is filled in from these defaults when it's loaded, so config files written by older versions keep working; the merged result is validated up front, and every problem (wrong type, invalid value) is reported in a single clear error.
|
|
132
150
|
|
|
133
|
-
`config --init` asks for every option above. When `autoCreateMR` is on, it uses the GitLab token (the one just entered, or `GITLAB_TOKEN`) to list the **real GitLab project members** so you pick `defaultReviewers` (preselected in each MR's reviewer prompt, still editable per MR) and `defaultAssignees` (assigned automatically to every MR) from them. If there's no token yet or
|
|
151
|
+
`config --init` asks for every option above. Source branch prefixes are picked from a list: the configured ones (checked), the prefixes this repo's branches actually use (with how many branches each, shown when 2+ branches share it) and common ones (`feature/`, `hotfix/`, `bugfix/`, `feat/`, `fix/`, `chore/`); **+ Add another prefix…** adds your own. The release prefix is asked separately. When `autoCreateMR` is on, it uses the GitLab token (the one just entered, or `GITLAB_TOKEN`) to list the **real GitLab project members** so you pick `defaultReviewers` (preselected in each MR's reviewer prompt, still editable per MR) and `defaultAssignees` (assigned automatically to every MR) from them. It also lists the **project's labels** (including those inherited from parent groups) to pick `defaultLabels`, added to every MR. If there's no token yet or an API call fails, it falls back to typing comma-separated usernames / labels. Older configs with `release.defaultReviewerPattern` (a regex over usernames) still work — it's used when `defaultReviewers` is empty — and running the wizard migrates it into the explicit list.
|
|
134
152
|
|
|
135
153
|
GitLab authentication uses a personal access token stored in `gitlab.token` (or the `GITLAB_TOKEN` environment variable, which takes effect when the config value is empty). The GitLab host and project path are both resolved from the `origin` remote URL (SSH `git@host:group/proj.git`, `ssh://…`, or HTTPS, with or without credentials) — no `projectId` is stored. Set `gitlab.host` only when the remote's host isn't the GitLab web host, e.g. an SSH alias from `~/.ssh/config`. The Anthropic API key can also be supplied via the `ANTHROPIC_API_KEY` environment variable instead of the config file.
|
|
136
154
|
|
|
@@ -150,7 +168,7 @@ There's no automated test suite yet (`npm test` is a placeholder). To validate a
|
|
|
150
168
|
```bash
|
|
151
169
|
find src -name "*.js" -exec node --check {} \;
|
|
152
170
|
```
|
|
153
|
-
3. **Run the full release flow against the synthetic sandbox** — a throwaway local `origin` (bare repo) plus a clone with prepared branches covering each scenario (normal feature/hotfix, untagged commit that must not be picked, real conflict, already-applied change → `SKIPPED`, two branches with the same task ID, branch with no task ID). Its config has `autoCreateMR: false`, so nothing is pushed and the GitLab API is never called:
|
|
171
|
+
3. **Run the full release flow against the synthetic sandbox** — a throwaway local `origin` (bare repo) plus a clone with prepared branches covering each scenario (normal feature/hotfix, untagged commit that must not be picked, real conflict, already-applied change → `SKIPPED`, two branches with the same task ID, branch with no task ID, a local-only branch `PB-600`, a local branch `PB-610` that is behind origin, and `PB-700`, whose only commit has no task tag — release it with `--commits PB-700=<hash>`). Its config has `autoCreateMR: false`, so nothing is pushed and the GitLab API is never called:
|
|
154
172
|
```bash
|
|
155
173
|
npm run sandbox:create # (re)creates it in $TMPDIR/release-cherry-pick-sandbox
|
|
156
174
|
npm run sandbox:run -- -b "PB-100,hotfix/PB-I200-favicon,PB-300,PB-400,PB-500,feature/refactor"
|
|
@@ -160,7 +178,7 @@ There's no automated test suite yet (`npm test` is a placeholder). To validate a
|
|
|
160
178
|
`sandbox:run` auto-answers every prompt (list → first choice, checkbox → the checked choices or all if none are, confirm → no), so it runs unattended. Re-run `sandbox:create` before each run to start from a clean state.
|
|
161
179
|
|
|
162
180
|
Two more flags work with both `sandbox:run` and `sandbox:config` (the setup wizard, whose prompts default to their current values):
|
|
163
|
-
- `--fake-gitlab` intercepts `fetch()` calls to the GitLab REST API (`/user`, project members, `POST merge_requests` — which prints the request body it received and returns a fake URL) and sets a fake `GITLAB_TOKEN`, so the real client, member-selection and MR-creation code run end to end with no GitLab. Release branches are pushed to the sandbox's local `origin` only.
|
|
181
|
+
- `--fake-gitlab` intercepts `fetch()` calls to the GitLab REST API (`/user`, project members, project labels, `POST merge_requests` — which prints the request body it received and returns a fake URL) and sets a fake `GITLAB_TOKEN`, so the real client, member-selection and MR-creation code run end to end with no GitLab. Release branches are pushed to the sandbox's local `origin` only.
|
|
164
182
|
- `--answer name=value` forces the answer of a prompt by name (value parsed as JSON when possible).
|
|
165
183
|
```bash
|
|
166
184
|
npm run sandbox:config -- --fake-gitlab --answer autoCreateMR=true --answer 'defaultAssignees=["abel"]'
|
|
@@ -181,11 +199,13 @@ There's no automated test suite yet (`npm test` is a placeholder). To validate a
|
|
|
181
199
|
This gives you real branches, real commit history, and real conflict scenarios with zero risk to the actual GitLab project.
|
|
182
200
|
5. **GitLab API behavior** (token validation, listing reviewers, MR creation) and **AI generation** need a real token (PAT with `api` scope) and a real Anthropic key respectively to exercise end-to-end — verify these manually against a test GitLab project before relying on them in production.
|
|
183
201
|
|
|
184
|
-
##
|
|
202
|
+
## Contributors
|
|
203
|
+
|
|
204
|
+
<a href="https://github.com/drobinetm/release-cherry-pick/graphs/contributors">
|
|
205
|
+
<img src="https://contrib.rocks/image?repo=drobinetm/release-cherry-pick" alt="Contributors" />
|
|
206
|
+
</a>
|
|
185
207
|
|
|
186
|
-
|
|
187
|
-
- ariel@ingeniuscuba.com
|
|
188
|
-
- drobinetm@outlook.com
|
|
208
|
+
Made with [contrib.rocks](https://contrib.rocks).
|
|
189
209
|
|
|
190
210
|
## License
|
|
191
211
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "release-cherry-pick",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "CLI tool for automating release cherry-pick and GitLab MR creation",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/drobinetm/release-cherry-pick.git"
|
|
9
|
+
},
|
|
6
10
|
"files": [
|
|
7
11
|
"src"
|
|
8
12
|
],
|
package/src/config/defaults.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
const defaultConfig = {
|
|
4
4
|
git: {
|
|
5
5
|
stagingBranch: 'staging',
|
|
6
|
+
// Where source branches are looked up: 'local' (local branches first, origin as a fallback for
|
|
7
|
+
// branches that don't exist locally) or 'remote' (origin only). --local/--remote override it.
|
|
8
|
+
branchSource: 'local',
|
|
6
9
|
branchPrefix: {
|
|
7
10
|
feature: 'feature/',
|
|
8
11
|
hotfix: 'hotfix/',
|
|
@@ -29,6 +32,8 @@ const defaultConfig = {
|
|
|
29
32
|
// GitLab usernames, picked from the real project members in the setup wizard
|
|
30
33
|
defaultReviewers: [],
|
|
31
34
|
defaultAssignees: [],
|
|
35
|
+
// GitLab label names added to every MR, picked from the project's labels in the setup wizard
|
|
36
|
+
defaultLabels: [],
|
|
32
37
|
mrSquash: true,
|
|
33
38
|
mrRemoveSourceBranch: true,
|
|
34
39
|
branches: []
|
package/src/config/loader.js
CHANGED
|
@@ -93,7 +93,15 @@ function loadConfig({ validate = true } = {}) {
|
|
|
93
93
|
throw new ConfigError(`Config file ${configPath} must contain a JSON object`);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const
|
|
96
|
+
const defaults = getDefaultConfig();
|
|
97
|
+
const config = mergeWithDefaults(defaults, fileConfig);
|
|
98
|
+
// git.branchPrefix is a set picked as a whole (the wizard may drop default prefixes like hotfix/),
|
|
99
|
+
// so a saved one replaces the defaults instead of being merged with them; only the release prefix
|
|
100
|
+
// is filled in when missing.
|
|
101
|
+
const savedPrefixes = isPlainObject(fileConfig.git) ? fileConfig.git.branchPrefix : undefined;
|
|
102
|
+
if (isPlainObject(savedPrefixes)) {
|
|
103
|
+
config.git.branchPrefix = { ...savedPrefixes, release: savedPrefixes.release || defaults.git.branchPrefix.release };
|
|
104
|
+
}
|
|
97
105
|
if (validate) {
|
|
98
106
|
validateConfig(config, configPath);
|
|
99
107
|
}
|
package/src/config/setup.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const inquirer = require('inquirer');
|
|
4
|
-
const { searchableList } = require('../utils/prompts');
|
|
4
|
+
const { searchableList, searchableCheckbox } = require('../utils/prompts');
|
|
5
|
+
const { countBranchesByPrefix } = require('../git/branch-selector');
|
|
5
6
|
const { loadConfig, saveConfig, getConfigPath } = require('./loader');
|
|
6
7
|
const { getDefaultConfig } = require('./defaults');
|
|
7
8
|
const { validateConfig } = require('./validator');
|
|
@@ -22,6 +23,109 @@ const CUSTOM_MODEL_CHOICE = '__custom_model__';
|
|
|
22
23
|
const BACK_CHOICE = '__back__';
|
|
23
24
|
const RESTORE_SAVED_CHOICE = '__restore_saved__';
|
|
24
25
|
const RESET_MODEL_CHOICE = '__reset_model__';
|
|
26
|
+
const ADD_PREFIX_CHOICE = '__add_prefix__';
|
|
27
|
+
|
|
28
|
+
// Offered in the source-prefix list even when this repo has no branch using them yet
|
|
29
|
+
const COMMON_SOURCE_PREFIXES = ['feature/', 'hotfix/', 'bugfix/', 'feat/', 'fix/', 'chore/'];
|
|
30
|
+
|
|
31
|
+
// "task" -> "task/": prefixes always end in a slash, as the branch name follows it
|
|
32
|
+
function normalizePrefix(value) {
|
|
33
|
+
const trimmed = String(value || '').trim();
|
|
34
|
+
if (!trimmed) return '';
|
|
35
|
+
return trimmed.endsWith('/') ? trimmed : `${trimmed}/`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Key a prefix is saved under in git.branchPrefix: "feat/" -> "feat"
|
|
39
|
+
function prefixKey(prefix) {
|
|
40
|
+
return prefix.replace(/\/+$/, '');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function validateSourcePrefix(prefix, known, releasePrefix) {
|
|
44
|
+
if (!prefix) return 'Enter a prefix, e.g. task/';
|
|
45
|
+
if (/\s/.test(prefix)) return 'Prefixes cannot contain spaces';
|
|
46
|
+
if (prefix === releasePrefix || prefixKey(prefix) === 'release') {
|
|
47
|
+
return `${prefix} is reserved for release branches`;
|
|
48
|
+
}
|
|
49
|
+
if (known.includes(prefix)) return `${prefix} is already in the list`;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Multi-select of the prefixes source branches can have (everything but the release prefix):
|
|
54
|
+
// the configured ones (checked), the ones this repo's branches really use (with how many branches
|
|
55
|
+
// each), and the common ones; "+ Add another prefix…" asks for a new one and shows the list again.
|
|
56
|
+
// Returns them as git.branchPrefix entries, keeping the key each configured prefix already had.
|
|
57
|
+
async function promptSourcePrefixes(config) {
|
|
58
|
+
const current = config.git.branchPrefix || {};
|
|
59
|
+
const releasePrefix = current.release || getDefaultConfig().git.branchPrefix.release;
|
|
60
|
+
const configured = Object.entries(current)
|
|
61
|
+
.filter(([type, prefix]) => type !== 'release' && prefix)
|
|
62
|
+
.map(([, prefix]) => prefix);
|
|
63
|
+
const counts = await countBranchesByPrefix();
|
|
64
|
+
// A prefix seen on a single branch is usually noise (a slash inside a branch name, a typo like
|
|
65
|
+
// "realease/"), so only prefixes shared by 2+ branches are suggested; the configured and common
|
|
66
|
+
// ones are always listed.
|
|
67
|
+
const detected = Object.keys(counts)
|
|
68
|
+
.filter(prefix => prefix !== releasePrefix && counts[prefix] >= 2)
|
|
69
|
+
.sort((a, b) => counts[b] - counts[a]);
|
|
70
|
+
const known = [...new Set([...configured, ...detected, ...COMMON_SOURCE_PREFIXES])];
|
|
71
|
+
let selected = configured.length > 0 ? configured : ['feature/', 'hotfix/'];
|
|
72
|
+
|
|
73
|
+
for (;;) {
|
|
74
|
+
const width = Math.max(...known.map(prefix => prefix.length));
|
|
75
|
+
const choices = known.map(prefix => {
|
|
76
|
+
const count = counts[prefix] || 0;
|
|
77
|
+
return {
|
|
78
|
+
name: `${prefix.padEnd(width)} ${count} branch${count === 1 ? '' : 'es'}`,
|
|
79
|
+
value: prefix,
|
|
80
|
+
checked: selected.includes(prefix)
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
choices.push({ name: '+ Add another prefix…', value: ADD_PREFIX_CHOICE });
|
|
84
|
+
|
|
85
|
+
const { sourcePrefixes } = await inquirer.prompt([
|
|
86
|
+
searchableCheckbox({
|
|
87
|
+
name: 'sourcePrefixes',
|
|
88
|
+
message: 'Source branch prefixes (space to toggle, type to search):',
|
|
89
|
+
pageSize: 15,
|
|
90
|
+
default: selected
|
|
91
|
+
}, choices)
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
selected = sourcePrefixes.filter(prefix => prefix !== ADD_PREFIX_CHOICE);
|
|
95
|
+
if (!sourcePrefixes.includes(ADD_PREFIX_CHOICE)) {
|
|
96
|
+
if (selected.length > 0) break;
|
|
97
|
+
logger.warn('Select at least one source branch prefix');
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const { newPrefix } = await inquirer.prompt([
|
|
102
|
+
{
|
|
103
|
+
type: 'input',
|
|
104
|
+
name: 'newPrefix',
|
|
105
|
+
message: 'New source branch prefix, e.g. task/ (blank to go back):',
|
|
106
|
+
filter: normalizePrefix,
|
|
107
|
+
validate: (value) => value === '' || validateSourcePrefix(value, known, releasePrefix)
|
|
108
|
+
}
|
|
109
|
+
]);
|
|
110
|
+
if (newPrefix) {
|
|
111
|
+
known.push(newPrefix);
|
|
112
|
+
selected.push(newPrefix);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const keyByPrefix = new Map(
|
|
117
|
+
Object.entries(current).filter(([type]) => type !== 'release').map(([type, prefix]) => [prefix, type])
|
|
118
|
+
);
|
|
119
|
+
const branchPrefix = {};
|
|
120
|
+
for (const prefix of selected) {
|
|
121
|
+
let key = keyByPrefix.get(prefix) || prefixKey(prefix);
|
|
122
|
+
for (let n = 2; key in branchPrefix || key === 'release'; n++) {
|
|
123
|
+
key = `${prefixKey(prefix)}${n}`;
|
|
124
|
+
}
|
|
125
|
+
branchPrefix[key] = prefix;
|
|
126
|
+
}
|
|
127
|
+
return branchPrefix;
|
|
128
|
+
}
|
|
25
129
|
|
|
26
130
|
// Sequential flow like OpenCode's /connect: list all providers → enter API key
|
|
27
131
|
// (skipped when the env var is already set) → connect and list that provider's models.
|
|
@@ -209,30 +313,40 @@ async function setupWizard() {
|
|
|
209
313
|
config.ai = getDefaultConfig().ai;
|
|
210
314
|
}
|
|
211
315
|
|
|
212
|
-
const
|
|
316
|
+
const { stagingBranch } = await inquirer.prompt([
|
|
213
317
|
{
|
|
214
318
|
type: 'input',
|
|
215
319
|
name: 'stagingBranch',
|
|
216
320
|
message: 'Staging branch name:',
|
|
217
321
|
default: config.git.stagingBranch
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
{
|
|
226
|
-
type: 'input',
|
|
227
|
-
name: 'hotfixPrefix',
|
|
228
|
-
message: 'Hotfix branch prefix:',
|
|
229
|
-
default: config.git.branchPrefix.hotfix
|
|
230
|
-
},
|
|
322
|
+
}
|
|
323
|
+
]);
|
|
324
|
+
|
|
325
|
+
const sourcePrefixes = await promptSourcePrefixes(config);
|
|
326
|
+
const sourcePrefixList = Object.values(sourcePrefixes);
|
|
327
|
+
|
|
328
|
+
const questions = [
|
|
231
329
|
{
|
|
232
330
|
type: 'input',
|
|
233
331
|
name: 'releasePrefix',
|
|
234
332
|
message: 'Release branch prefix:',
|
|
235
|
-
default: config.git.branchPrefix.release
|
|
333
|
+
default: config.git.branchPrefix.release || getDefaultConfig().git.branchPrefix.release,
|
|
334
|
+
filter: normalizePrefix,
|
|
335
|
+
validate: (value) => {
|
|
336
|
+
if (!value) return 'The release prefix is required';
|
|
337
|
+
if (sourcePrefixList.includes(value)) return `${value} is already a source branch prefix`;
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
type: 'list',
|
|
343
|
+
name: 'branchSource',
|
|
344
|
+
message: `Where should source branches (${sourcePrefixList.join(', ')}) be looked up?`,
|
|
345
|
+
choices: [
|
|
346
|
+
{ name: 'Local branches first, origin as a fallback', value: 'local' },
|
|
347
|
+
{ name: 'Origin only', value: 'remote' }
|
|
348
|
+
],
|
|
349
|
+
default: config.git.branchSource || 'local'
|
|
236
350
|
},
|
|
237
351
|
{
|
|
238
352
|
type: 'input',
|
|
@@ -296,10 +410,10 @@ async function setupWizard() {
|
|
|
296
410
|
|
|
297
411
|
const newConfig = {
|
|
298
412
|
git: {
|
|
299
|
-
stagingBranch
|
|
413
|
+
stagingBranch,
|
|
414
|
+
branchSource: answers.branchSource,
|
|
300
415
|
branchPrefix: {
|
|
301
|
-
|
|
302
|
-
hotfix: answers.hotfixPrefix,
|
|
416
|
+
...sourcePrefixes,
|
|
303
417
|
release: answers.releasePrefix
|
|
304
418
|
}
|
|
305
419
|
},
|
|
@@ -334,6 +448,7 @@ async function setupWizard() {
|
|
|
334
448
|
newConfig.release.mrRemoveSourceBranch = answers.mrRemoveSourceBranch;
|
|
335
449
|
|
|
336
450
|
await selectDefaultMembers(newConfig);
|
|
451
|
+
await selectDefaultLabels(newConfig);
|
|
337
452
|
}
|
|
338
453
|
|
|
339
454
|
const { reviewAction } = await inquirer.prompt([
|
|
@@ -446,6 +561,71 @@ async function pickMembers(name, members, checkedUsernames, configuredUsernames,
|
|
|
446
561
|
return answers[name];
|
|
447
562
|
}
|
|
448
563
|
|
|
564
|
+
// Sets release.defaultLabels (added to every MR), picked from the project's real labels when they
|
|
565
|
+
// can be listed, or typed otherwise. Like the members, it never prompts for a token mid-wizard.
|
|
566
|
+
async function selectDefaultLabels(config) {
|
|
567
|
+
const release = config.release;
|
|
568
|
+
const current = Array.isArray(release.defaultLabels) ? release.defaultLabels : [];
|
|
569
|
+
const labels = await fetchProjectLabels(config);
|
|
570
|
+
|
|
571
|
+
if (!labels) {
|
|
572
|
+
const { defaultLabels } = await inquirer.prompt([
|
|
573
|
+
{ type: 'input', name: 'defaultLabels', message: 'Default MR labels (comma-separated, blank for none):', default: current.join(', ') }
|
|
574
|
+
]);
|
|
575
|
+
release.defaultLabels = String(defaultLabels).split(',').map(l => l.trim()).filter(Boolean);
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const isCurrent = (name) => current.some(c => c.toLowerCase() === name.toLowerCase());
|
|
580
|
+
const choices = labels.map(label => ({
|
|
581
|
+
name: label.description ? `${label.name} — ${truncate(label.description, 60)}` : label.name,
|
|
582
|
+
value: label.name,
|
|
583
|
+
checked: isCurrent(label.name)
|
|
584
|
+
}));
|
|
585
|
+
// Keep configured labels that no longer exist in the project visible, so they aren't dropped
|
|
586
|
+
// silently — the user decides whether to keep them.
|
|
587
|
+
for (const name of current) {
|
|
588
|
+
if (!labels.some(label => label.name.toLowerCase() === name.toLowerCase())) {
|
|
589
|
+
choices.push({ name: `${name} (not found among project labels)`, value: name, checked: true });
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const { defaultLabels } = await inquirer.prompt([
|
|
594
|
+
searchableCheckbox({
|
|
595
|
+
name: 'defaultLabels',
|
|
596
|
+
message: 'Default MR labels, added to every MR (space to toggle, type to search):',
|
|
597
|
+
pageSize: 15,
|
|
598
|
+
default: choices.filter(c => c.checked).map(c => c.value)
|
|
599
|
+
}, choices)
|
|
600
|
+
]);
|
|
601
|
+
release.defaultLabels = defaultLabels;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
async function fetchProjectLabels(config) {
|
|
605
|
+
if (!gitlab.getToken(config)) {
|
|
606
|
+
logger.warn('No GitLab token configured (gitlab.token / GITLAB_TOKEN), so project labels can\'t be listed; enter them manually instead.');
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
try {
|
|
611
|
+
logger.info('Loading GitLab project labels...');
|
|
612
|
+
const labels = await gitlab.getProjectLabels(config);
|
|
613
|
+
if (labels.length === 0) {
|
|
614
|
+
logger.warn('The GitLab project has no labels to choose from; enter them manually instead.');
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
return labels;
|
|
618
|
+
} catch (error) {
|
|
619
|
+
logger.warn(`Could not load GitLab project labels (${error.message}); enter them manually instead.`);
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function truncate(text, max) {
|
|
625
|
+
const oneLine = String(text).replace(/\s+/g, ' ').trim();
|
|
626
|
+
return oneLine.length > max ? `${oneLine.slice(0, max - 1)}…` : oneLine;
|
|
627
|
+
}
|
|
628
|
+
|
|
449
629
|
async function askUsernames(name, message, current) {
|
|
450
630
|
const answers = await inquirer.prompt([
|
|
451
631
|
{ type: 'input', name, message, default: current.join(', ') }
|
|
@@ -459,5 +639,6 @@ async function askUsernames(name, message, current) {
|
|
|
459
639
|
module.exports = {
|
|
460
640
|
setupWizard,
|
|
461
641
|
ensureAiSettings,
|
|
462
|
-
promptAiProviderAndModel
|
|
642
|
+
promptAiProviderAndModel,
|
|
643
|
+
promptSourcePrefixes
|
|
463
644
|
};
|
package/src/config/validator.js
CHANGED
|
@@ -31,11 +31,17 @@ function validateConfig(config, source = 'configuration') {
|
|
|
31
31
|
const { git, gitlab, ai, release } = config;
|
|
32
32
|
|
|
33
33
|
expect(git.stagingBranch, 'git.stagingBranch', isNonEmptyString, 'a non-empty string');
|
|
34
|
+
expect(git.branchSource, 'git.branchSource', v => v === 'local' || v === 'remote', '"local" or "remote"');
|
|
34
35
|
if (isPlainObject(git.branchPrefix)) {
|
|
35
36
|
for (const [type, prefix] of Object.entries(git.branchPrefix)) {
|
|
36
37
|
expect(prefix, `git.branchPrefix.${type}`, isString, 'a string');
|
|
37
38
|
}
|
|
38
39
|
expect(git.branchPrefix.release, 'git.branchPrefix.release', isNonEmptyString, 'a non-empty string');
|
|
40
|
+
const hasSourcePrefix = Object.entries(git.branchPrefix)
|
|
41
|
+
.some(([type, prefix]) => type !== 'release' && isNonEmptyString(prefix));
|
|
42
|
+
if (!hasSourcePrefix) {
|
|
43
|
+
errors.push('git.branchPrefix must define at least one source prefix besides release (e.g. "feature": "feature/")');
|
|
44
|
+
}
|
|
39
45
|
} else {
|
|
40
46
|
errors.push('git.branchPrefix must be an object');
|
|
41
47
|
}
|
|
@@ -57,6 +63,7 @@ function validateConfig(config, source = 'configuration') {
|
|
|
57
63
|
expect(release.mrRemoveSourceBranch, 'release.mrRemoveSourceBranch', isBoolean, 'true or false');
|
|
58
64
|
expect(release.defaultReviewers, 'release.defaultReviewers', isStringArray, 'a list of GitLab usernames');
|
|
59
65
|
expect(release.defaultAssignees, 'release.defaultAssignees', isStringArray, 'a list of GitLab usernames');
|
|
66
|
+
expect(release.defaultLabels, 'release.defaultLabels', isStringArray, 'a list of GitLab label names');
|
|
60
67
|
expect(release.branches, 'release.branches', isStringArray, 'a list of branch names');
|
|
61
68
|
|
|
62
69
|
if (release.defaultReviewerPattern !== undefined) {
|
package/src/git/branch-parser.js
CHANGED
|
@@ -26,15 +26,30 @@ function parseBranchListFile(filePath) {
|
|
|
26
26
|
return branches;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// A commit hash as users type it: 4 to 40 hex characters (short or full)
|
|
30
|
+
const HASH = /^[0-9a-f]{4,40}$/i;
|
|
31
|
+
|
|
32
|
+
// Optional trailing list of extra commits to cherry-pick: "... [+abc1234, +def5678]". Only a list
|
|
33
|
+
// made entirely of +hashes counts, so a description that just ends in brackets is left alone.
|
|
34
|
+
const EXTRA_COMMITS = /\s*\[\s*(\+[0-9a-f]{4,40}(?:\s*,\s*\+[0-9a-f]{4,40})*)\s*\]\s*$/i;
|
|
35
|
+
|
|
29
36
|
function parseBranchLine(line) {
|
|
30
|
-
// Pattern: *TASK-ID*: Description
|
|
31
|
-
// Example: *PB-I3217*: Al gestionar autos de una póliza...
|
|
37
|
+
// Pattern: *TASK-ID*: Description [+hash, +hash]
|
|
38
|
+
// Example: *PB-I3217*: Al gestionar autos de una póliza... [+3f2a9c1]
|
|
32
39
|
const match = line.match(/^\*?([A-Z]+-[A-Z0-9]+)\*?:\s*(.+)$/);
|
|
33
40
|
|
|
34
41
|
if (match) {
|
|
42
|
+
let description = match[2].trim();
|
|
43
|
+
let extraCommits = [];
|
|
44
|
+
const extra = description.match(EXTRA_COMMITS);
|
|
45
|
+
if (extra && extra.index > 0) {
|
|
46
|
+
description = description.slice(0, extra.index).trim();
|
|
47
|
+
extraCommits = extra[1].split(',').map(hash => hash.trim().replace(/^\+/, ''));
|
|
48
|
+
}
|
|
35
49
|
return {
|
|
36
50
|
taskId: match[1],
|
|
37
|
-
description
|
|
51
|
+
description,
|
|
52
|
+
extraCommits,
|
|
38
53
|
raw: line.trim()
|
|
39
54
|
};
|
|
40
55
|
}
|
|
@@ -42,6 +57,96 @@ function parseBranchLine(line) {
|
|
|
42
57
|
return null;
|
|
43
58
|
}
|
|
44
59
|
|
|
60
|
+
// Parses --commits values ("PB-123=abc1234,def5678", repeatable) into a Map of task ID -> hashes.
|
|
61
|
+
// Throws one error listing every malformed value.
|
|
62
|
+
function parseCommitSpecs(specs = []) {
|
|
63
|
+
const byTask = new Map();
|
|
64
|
+
const errors = [];
|
|
65
|
+
|
|
66
|
+
for (const spec of specs) {
|
|
67
|
+
const match = String(spec).match(/^\s*([^=\s]+)\s*=\s*(.*)$/);
|
|
68
|
+
const hashes = match ? match[2].split(',').map(hash => hash.trim()).filter(Boolean) : [];
|
|
69
|
+
if (!match || !isTaskId(match[1]) || hashes.length === 0) {
|
|
70
|
+
errors.push(`"${spec}" (expected TASK-ID=hash[,hash...], e.g. PB-123=abc1234)`);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const bad = hashes.filter(hash => !HASH.test(hash));
|
|
74
|
+
if (bad.length > 0) {
|
|
75
|
+
errors.push(`"${spec}" (not commit hashes: ${bad.join(', ')})`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const taskId = match[1].toUpperCase();
|
|
79
|
+
byTask.set(taskId, [...new Set([...(byTask.get(taskId) || []), ...hashes])]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (errors.length > 0) {
|
|
83
|
+
throw new AppError(`Invalid --commits value(s): ${errors.join('; ')}`);
|
|
84
|
+
}
|
|
85
|
+
return byTask;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Parses the -b/--branches list: comma-separated task IDs or branch names, each optionally followed
|
|
89
|
+
// by extra commit hashes in brackets — "PB-1[abc1234,+def5678],feature/PB-2-x,PB-3". Commas inside
|
|
90
|
+
// brackets separate hashes; outside, entries. Returns [{ name, extraCommits }]; throws one error
|
|
91
|
+
// listing every malformed entry.
|
|
92
|
+
function parseBranchEntries(value) {
|
|
93
|
+
const pieces = [];
|
|
94
|
+
const errors = [];
|
|
95
|
+
let current = '';
|
|
96
|
+
let inBrackets = false;
|
|
97
|
+
|
|
98
|
+
for (const char of String(value || '')) {
|
|
99
|
+
if (char === '[') {
|
|
100
|
+
if (inBrackets) errors.push(`nested "[" in "${current}["`);
|
|
101
|
+
inBrackets = true;
|
|
102
|
+
} else if (char === ']') {
|
|
103
|
+
if (!inBrackets) errors.push(`"]" without a matching "[" in "${current}]"`);
|
|
104
|
+
inBrackets = false;
|
|
105
|
+
}
|
|
106
|
+
if (char === ',' && !inBrackets) {
|
|
107
|
+
pieces.push(current);
|
|
108
|
+
current = '';
|
|
109
|
+
} else {
|
|
110
|
+
current += char;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (inBrackets) errors.push(`unclosed "[" in "${current}"`);
|
|
114
|
+
pieces.push(current);
|
|
115
|
+
|
|
116
|
+
const entries = [];
|
|
117
|
+
for (const piece of pieces.map(p => p.trim()).filter(Boolean)) {
|
|
118
|
+
const match = piece.match(/^([^[\]]+?)\s*(?:\[([^[\]]*)\])?$/);
|
|
119
|
+
if (!match) {
|
|
120
|
+
if (errors.length === 0) errors.push(`"${piece}" (brackets must come right after the task ID or branch name)`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const name = match[1].trim();
|
|
124
|
+
const hasBrackets = match[2] !== undefined;
|
|
125
|
+
const hashes = hasBrackets
|
|
126
|
+
? match[2].split(',').map(hash => hash.trim().replace(/^\+/, '')).filter(Boolean)
|
|
127
|
+
: [];
|
|
128
|
+
if (hasBrackets && hashes.length === 0) {
|
|
129
|
+
errors.push(`"${piece}" (empty commit list)`);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const bad = hashes.filter(hash => !HASH.test(hash));
|
|
133
|
+
if (bad.length > 0) {
|
|
134
|
+
errors.push(`"${piece}" (not commit hashes: ${bad.join(', ')})`);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
entries.push({ name, extraCommits: hashes });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (errors.length > 0) {
|
|
141
|
+
throw new AppError(`Invalid -b/--branches value: ${errors.join('; ')}. Expected e.g. "PB-123[abc1234,def5678],PB-124"`);
|
|
142
|
+
}
|
|
143
|
+
return entries;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function isCommitHash(value) {
|
|
147
|
+
return HASH.test(String(value).trim());
|
|
148
|
+
}
|
|
149
|
+
|
|
45
150
|
function getBranchNameFromTaskId(taskId, prefix = 'feature/') {
|
|
46
151
|
return `${prefix}${taskId.toLowerCase()}`;
|
|
47
152
|
}
|
|
@@ -81,6 +186,9 @@ function isTaskId(value) {
|
|
|
81
186
|
module.exports = {
|
|
82
187
|
parseBranchListFile,
|
|
83
188
|
parseBranchLine,
|
|
189
|
+
parseCommitSpecs,
|
|
190
|
+
parseBranchEntries,
|
|
191
|
+
isCommitHash,
|
|
84
192
|
getBranchNameFromTaskId,
|
|
85
193
|
extractTaskIdFromBranch,
|
|
86
194
|
describeBranch,
|