release-cherry-pick 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +186 -2
- package/package.json +64 -4
- package/src/cli/index.js +13 -0
- package/src/config/ai-providers.js +285 -0
- package/src/config/defaults.js +45 -0
- package/src/config/loader.js +127 -0
- package/src/config/setup.js +463 -0
- package/src/config/validator.js +80 -0
- package/src/doc/agents-generator.js +83 -0
- package/src/doc/rpd-generator.js +87 -0
- package/src/git/branch-parser.js +88 -0
- package/src/git/branch-selector.js +97 -0
- package/src/git/cherry-pick.js +216 -0
- package/src/git/git-auth.js +41 -0
- package/src/git/release-branch.js +106 -0
- package/src/git/release-status.js +121 -0
- package/src/git/remote-url.js +34 -0
- package/src/git/repo-state.js +153 -0
- package/src/gitlab/ai-description.js +157 -0
- package/src/gitlab/client.js +324 -0
- package/src/gitlab/mr-creator.js +55 -0
- package/src/gitlab/reviewer-selector.js +52 -0
- package/src/index.js +58 -0
- package/src/report/summary.js +91 -0
- package/src/utils/errors.js +47 -0
- package/src/utils/logger.js +36 -0
- package/src/utils/prompts.js +59 -0
- package/src/utils/secrets.js +24 -0
- package/src/workflow/release.js +464 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const inquirer = require('inquirer');
|
|
4
|
+
const simpleGit = require('simple-git');
|
|
5
|
+
const logger = require('../utils/logger');
|
|
6
|
+
const { GitLabError } = require('../utils/errors');
|
|
7
|
+
const { saveConfig } = require('../config/loader');
|
|
8
|
+
const { parseRemoteUrl } = require('../git/remote-url');
|
|
9
|
+
|
|
10
|
+
const git = simpleGit();
|
|
11
|
+
const DEFAULT_HOST = 'gitlab.com';
|
|
12
|
+
|
|
13
|
+
function getToken(config) {
|
|
14
|
+
return (config.gitlab && config.gitlab.token) || process.env.GITLAB_TOKEN || '';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Reads and parses the `origin` remote (once per run; it doesn't change during a release).
|
|
18
|
+
let originRemotePromise = null;
|
|
19
|
+
function getOriginRemote() {
|
|
20
|
+
if (!originRemotePromise) {
|
|
21
|
+
originRemotePromise = (async () => {
|
|
22
|
+
let url;
|
|
23
|
+
try {
|
|
24
|
+
url = (await git.raw(['remote', 'get-url', 'origin'])).trim();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new GitLabError(`Could not read git remote "origin": ${error.message}`);
|
|
27
|
+
}
|
|
28
|
+
const remote = parseRemoteUrl(url);
|
|
29
|
+
if (!remote || !remote.projectPath) {
|
|
30
|
+
throw new GitLabError(`Could not derive the GitLab project from the origin remote: ${url}`);
|
|
31
|
+
}
|
|
32
|
+
return { url, ...remote };
|
|
33
|
+
})();
|
|
34
|
+
originRemotePromise.catch(() => { originRemotePromise = null; });
|
|
35
|
+
}
|
|
36
|
+
return originRemotePromise;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Turns whatever was configured as gitlab.host into the GitLab base URL ("https://host[:port]" plus
|
|
40
|
+
// a relative URL root if GitLab is installed under a sub-path, e.g. "https://example.com/gitlab").
|
|
41
|
+
// People often paste a project or page URL instead of the host, e.g.
|
|
42
|
+
// "https://gitlab.example.com/group/proj/-/project_members", which would put the API under the
|
|
43
|
+
// project path and 404; so everything from GitLab's "/-/" page separator on is dropped, and so is
|
|
44
|
+
// the origin remote's project path when the value ends with it.
|
|
45
|
+
async function normalizeGitlabHost(host) {
|
|
46
|
+
let value = String(host || '').trim();
|
|
47
|
+
if (!value) {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
if (!/^https?:\/\//i.test(value)) {
|
|
51
|
+
value = `https://${value}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let url;
|
|
55
|
+
try {
|
|
56
|
+
url = new URL(value);
|
|
57
|
+
} catch {
|
|
58
|
+
return value.replace(/\/+$/, '');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let pathname = url.pathname.replace(/\/-(\/.*)?$/, '').replace(/\/+$/, '').replace(/\.git$/, '');
|
|
62
|
+
try {
|
|
63
|
+
const { projectPath } = await getOriginRemote();
|
|
64
|
+
if (pathname.toLowerCase().endsWith(`/${projectPath}`.toLowerCase())) {
|
|
65
|
+
pathname = pathname.slice(0, pathname.length - projectPath.length - 1);
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
// No usable origin remote: keep the path (it may be a relative URL root)
|
|
69
|
+
}
|
|
70
|
+
return `${url.protocol}//${url.host}${pathname}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let warnedAboutHost = false;
|
|
74
|
+
|
|
75
|
+
// API base URL: gitlab.host from config when set (needed e.g. when the SSH remote uses a
|
|
76
|
+
// ~/.ssh/config alias instead of the real host), otherwise the host of the origin remote, so a
|
|
77
|
+
// self-managed instance works without configuring anything; gitlab.com as a last resort.
|
|
78
|
+
async function getApiBase(config) {
|
|
79
|
+
const configured = config.gitlab && config.gitlab.host;
|
|
80
|
+
let base;
|
|
81
|
+
if (configured) {
|
|
82
|
+
base = await normalizeGitlabHost(configured);
|
|
83
|
+
const asGiven = String(configured).trim().replace(/\/+$/, '');
|
|
84
|
+
if (!warnedAboutHost && base !== asGiven && base !== `https://${asGiven}`) {
|
|
85
|
+
warnedAboutHost = true;
|
|
86
|
+
logger.warn(`gitlab.host "${configured}" looks like a project/page URL; using ${base} (run config --init to fix it, or leave it blank to use the origin remote's host)`);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
try {
|
|
90
|
+
const remote = await getOriginRemote();
|
|
91
|
+
base = `${remote.protocol}://${remote.host}`;
|
|
92
|
+
} catch {
|
|
93
|
+
base = `https://${DEFAULT_HOST}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return `${base}/api/v4`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Project path (e.g. "group/sub/proj") from the `origin` remote, URL-encoded for use as `:id`.
|
|
100
|
+
// If gitlab.host includes a relative URL root (GitLab served under e.g. https://example.com/gitlab),
|
|
101
|
+
// the remote's path starts with it ("gitlab/group/proj"), and it isn't part of the project path.
|
|
102
|
+
async function getProjectPathId(config) {
|
|
103
|
+
let { projectPath } = await getOriginRemote();
|
|
104
|
+
const configured = config && config.gitlab && config.gitlab.host;
|
|
105
|
+
if (configured) {
|
|
106
|
+
try {
|
|
107
|
+
const root = new URL(await normalizeGitlabHost(configured)).pathname.replace(/^\/+|\/+$/g, '');
|
|
108
|
+
if (root && projectPath.toLowerCase().startsWith(`${root.toLowerCase()}/`)) {
|
|
109
|
+
projectPath = projectPath.slice(root.length + 1);
|
|
110
|
+
}
|
|
111
|
+
} catch {
|
|
112
|
+
// Unparseable host: keep the remote's path as-is
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return encodeURIComponent(projectPath);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function apiRequest(config, path, { method = 'GET', body } = {}) {
|
|
119
|
+
const token = getToken(config);
|
|
120
|
+
if (!token) {
|
|
121
|
+
throw new GitLabError(
|
|
122
|
+
'No GitLab token. Set gitlab.token in config or the GITLAB_TOKEN environment variable (PAT with "api" scope).'
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const base = await getApiBase(config);
|
|
127
|
+
let response;
|
|
128
|
+
try {
|
|
129
|
+
response = await fetch(`${base}${path}`, {
|
|
130
|
+
method,
|
|
131
|
+
headers: {
|
|
132
|
+
'PRIVATE-TOKEN': token,
|
|
133
|
+
'Content-Type': 'application/json',
|
|
134
|
+
Accept: 'application/json'
|
|
135
|
+
},
|
|
136
|
+
body: body !== undefined ? JSON.stringify(body) : undefined
|
|
137
|
+
});
|
|
138
|
+
} catch (error) {
|
|
139
|
+
throw new GitLabError(`GitLab API request failed: ${error.message}`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (response.status === 401) {
|
|
143
|
+
throw new GitLabError('GitLab authentication failed (401): token is invalid or expired');
|
|
144
|
+
}
|
|
145
|
+
if (response.status === 403) {
|
|
146
|
+
const text = await response.text().catch(() => '');
|
|
147
|
+
throw new GitLabError(`GitLab permission denied (403): ${text.slice(0, 300)}`);
|
|
148
|
+
}
|
|
149
|
+
if (response.status === 404) {
|
|
150
|
+
// GitLab also answers 404 (not 403) for projects the token can't see
|
|
151
|
+
throw new GitLabError(
|
|
152
|
+
`GitLab resource not found (404) at ${base}${path.split('?')[0]}: check gitlab.host, the origin remote, and that the token's user can access the project`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (!response.ok) {
|
|
156
|
+
const text = await response.text().catch(() => '');
|
|
157
|
+
throw new GitLabError(`GitLab API error ${response.status}: ${text.slice(0, 300)}`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (response.status === 204) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
return response.json();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function checkAuthStatus(config) {
|
|
167
|
+
try {
|
|
168
|
+
const user = await apiRequest(config, '/user');
|
|
169
|
+
return { authenticated: true, user };
|
|
170
|
+
} catch (error) {
|
|
171
|
+
return { authenticated: false, error };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Preflight: resolve a token (config → env → interactive PAT prompt), then validate via GET /user.
|
|
176
|
+
async function ensureAuthenticated(config) {
|
|
177
|
+
let token = getToken(config);
|
|
178
|
+
|
|
179
|
+
if (!token) {
|
|
180
|
+
logger.warn('No GitLab token found (gitlab.token / GITLAB_TOKEN)');
|
|
181
|
+
const { enteredToken } = await inquirer.prompt([
|
|
182
|
+
{
|
|
183
|
+
type: 'password',
|
|
184
|
+
name: 'enteredToken',
|
|
185
|
+
message: 'GitLab personal access token (scope "api"), leave blank to abort:',
|
|
186
|
+
mask: '*',
|
|
187
|
+
filter: (value) => (value ? String(value).trim() : '')
|
|
188
|
+
}
|
|
189
|
+
]);
|
|
190
|
+
|
|
191
|
+
if (!enteredToken) {
|
|
192
|
+
throw new GitLabError(
|
|
193
|
+
'GitLab authentication is required to create merge requests. Set gitlab.token or GITLAB_TOKEN, or disable release.autoCreateMR.'
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
token = enteredToken;
|
|
198
|
+
if (!config.gitlab || typeof config.gitlab !== 'object') {
|
|
199
|
+
config.gitlab = {};
|
|
200
|
+
}
|
|
201
|
+
config.gitlab.token = token;
|
|
202
|
+
saveConfig(config);
|
|
203
|
+
logger.success('GitLab token saved to configuration');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const status = await checkAuthStatus(config);
|
|
207
|
+
if (!status.authenticated) {
|
|
208
|
+
throw new GitLabError(
|
|
209
|
+
`GitLab authentication failed: ${status.error.message}. Check gitlab.host and that the token has "api" scope.`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
logger.success(`GitLab: authenticated as @${status.user.username}`);
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function getProjectMembers(config) {
|
|
218
|
+
try {
|
|
219
|
+
const projectId = await getProjectPathId(config);
|
|
220
|
+
const members = [];
|
|
221
|
+
let page = 1;
|
|
222
|
+
|
|
223
|
+
for (;;) {
|
|
224
|
+
const batch = await apiRequest(
|
|
225
|
+
config,
|
|
226
|
+
`/projects/${projectId}/members/all?per_page=100&page=${page}`
|
|
227
|
+
);
|
|
228
|
+
if (!Array.isArray(batch) || batch.length === 0) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
members.push(...batch.map((m) => ({ id: m.id, username: m.username, name: m.name })));
|
|
232
|
+
if (batch.length < 100) {
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
page += 1;
|
|
236
|
+
if (page > 50) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return members;
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (error instanceof GitLabError) {
|
|
244
|
+
throw new GitLabError(`Failed to list GitLab project members: ${error.message}`);
|
|
245
|
+
}
|
|
246
|
+
throw new GitLabError(`Failed to list GitLab project members: ${error.message}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Maps usernames to GitLab user IDs (the MR API takes IDs), warning about and skipping unknown ones.
|
|
251
|
+
function usernamesToIds(usernames, memberList, role) {
|
|
252
|
+
const ids = [];
|
|
253
|
+
const missing = [];
|
|
254
|
+
for (const username of usernames) {
|
|
255
|
+
const match = memberList.find((m) => m.username.toLowerCase() === username.toLowerCase());
|
|
256
|
+
if (match) {
|
|
257
|
+
ids.push(match.id);
|
|
258
|
+
} else {
|
|
259
|
+
missing.push(username);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (missing.length > 0) {
|
|
263
|
+
logger.warn(`${role}(s) not found in project members (skipped): ${missing.join(', ')}`);
|
|
264
|
+
}
|
|
265
|
+
return ids;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function createMergeRequest(
|
|
269
|
+
config,
|
|
270
|
+
{ sourceBranch, targetBranch, title, description, reviewers = [], assignees = [], squash = true, removeSourceBranch = true, members = null }
|
|
271
|
+
) {
|
|
272
|
+
try {
|
|
273
|
+
const projectId = await getProjectPathId(config);
|
|
274
|
+
|
|
275
|
+
let memberList = members;
|
|
276
|
+
if (!memberList && (reviewers.length > 0 || assignees.length > 0)) {
|
|
277
|
+
memberList = await getProjectMembers(config);
|
|
278
|
+
}
|
|
279
|
+
const reviewerIds = reviewers.length > 0 ? usernamesToIds(reviewers, memberList, 'Reviewer') : [];
|
|
280
|
+
const assigneeIds = assignees.length > 0 ? usernamesToIds(assignees, memberList, 'Assignee') : [];
|
|
281
|
+
|
|
282
|
+
const body = {
|
|
283
|
+
source_branch: sourceBranch,
|
|
284
|
+
target_branch: targetBranch,
|
|
285
|
+
title,
|
|
286
|
+
description,
|
|
287
|
+
squash,
|
|
288
|
+
remove_source_branch: removeSourceBranch
|
|
289
|
+
};
|
|
290
|
+
if (reviewerIds.length > 0) {
|
|
291
|
+
body.reviewer_ids = reviewerIds;
|
|
292
|
+
}
|
|
293
|
+
if (assigneeIds.length > 0) {
|
|
294
|
+
body.assignee_ids = assigneeIds;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const mr = await apiRequest(config, `/projects/${projectId}/merge_requests`, {
|
|
298
|
+
method: 'POST',
|
|
299
|
+
body
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const url = mr && mr.web_url;
|
|
303
|
+
if (!url) {
|
|
304
|
+
throw new GitLabError('GitLab MR created but no web_url in response');
|
|
305
|
+
}
|
|
306
|
+
return { url, raw: JSON.stringify(mr) };
|
|
307
|
+
} catch (error) {
|
|
308
|
+
if (error instanceof GitLabError) {
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
throw new GitLabError(`Failed to create merge request: ${error.message}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
module.exports = {
|
|
316
|
+
checkAuthStatus,
|
|
317
|
+
ensureAuthenticated,
|
|
318
|
+
getProjectMembers,
|
|
319
|
+
createMergeRequest,
|
|
320
|
+
getApiBase,
|
|
321
|
+
getToken,
|
|
322
|
+
parseRemoteUrl,
|
|
323
|
+
normalizeGitlabHost
|
|
324
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const logger = require('../utils/logger');
|
|
4
|
+
const { GitLabError } = require('../utils/errors');
|
|
5
|
+
const gitlab = require('./client');
|
|
6
|
+
const { generateMRTitleAndDescription } = require('./ai-description');
|
|
7
|
+
|
|
8
|
+
function buildFallbackTitle(config, taskId, description) {
|
|
9
|
+
const format = (config.release && config.release.mrTitleFormat) || '[{taskId}] {description}';
|
|
10
|
+
return format.replace('{taskId}', taskId).replace('{description}', description);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function buildFallbackDescription(taskId, description, commits) {
|
|
14
|
+
let mrDescription = `## ${taskId}: ${description}\n\n### Commits incluidos:\n\n`;
|
|
15
|
+
for (const commit of commits) {
|
|
16
|
+
mrDescription += `- ${commit.hash}: ${commit.message}\n`;
|
|
17
|
+
}
|
|
18
|
+
return mrDescription;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function createMR(config, { sourceBranch, targetBranch, taskId, description, commits = [], reviewers = [], members = null }) {
|
|
22
|
+
let title = buildFallbackTitle(config, taskId, description);
|
|
23
|
+
let mrDescription = buildFallbackDescription(taskId, description, commits);
|
|
24
|
+
|
|
25
|
+
const aiResult = await generateMRTitleAndDescription(config, taskId, description, commits);
|
|
26
|
+
if (aiResult) {
|
|
27
|
+
title = aiResult.title;
|
|
28
|
+
mrDescription = aiResult.description;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const result = await gitlab.createMergeRequest(config, {
|
|
33
|
+
sourceBranch,
|
|
34
|
+
targetBranch,
|
|
35
|
+
title,
|
|
36
|
+
description: mrDescription,
|
|
37
|
+
reviewers,
|
|
38
|
+
assignees: config.release.defaultAssignees || [],
|
|
39
|
+
squash: config.release.mrSquash !== false,
|
|
40
|
+
removeSourceBranch: config.release.mrRemoveSourceBranch !== false,
|
|
41
|
+
members
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
logger.success(`MR created: ${result.url}`);
|
|
45
|
+
return result;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new GitLabError(`Failed to create MR for ${taskId}: ${error.message}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
createMR,
|
|
53
|
+
buildFallbackTitle,
|
|
54
|
+
buildFallbackDescription
|
|
55
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const inquirer = require('inquirer');
|
|
4
|
+
const logger = require('../utils/logger');
|
|
5
|
+
|
|
6
|
+
// Members to preselect as reviewers: those listed in release.defaultReviewers or, if that list is
|
|
7
|
+
// empty, those matching the legacy release.defaultReviewerPattern regex (older config files).
|
|
8
|
+
function findDefaultReviewers(members, { defaultReviewers = [], defaultReviewerPattern } = {}) {
|
|
9
|
+
if (defaultReviewers.length > 0) {
|
|
10
|
+
const wanted = new Set(defaultReviewers.map(u => u.toLowerCase()));
|
|
11
|
+
return members.filter(m => wanted.has(m.username.toLowerCase()));
|
|
12
|
+
}
|
|
13
|
+
if (defaultReviewerPattern) {
|
|
14
|
+
const re = new RegExp(defaultReviewerPattern, 'i');
|
|
15
|
+
return members.filter(m => re.test(m.username));
|
|
16
|
+
}
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function selectReviewer(members, releaseConfig = {}) {
|
|
21
|
+
if (members.length === 0) {
|
|
22
|
+
logger.warn('No GitLab project members found');
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const defaults = findDefaultReviewers(members, releaseConfig);
|
|
27
|
+
const missing = (releaseConfig.defaultReviewers || []).filter(
|
|
28
|
+
u => !members.some(m => m.username.toLowerCase() === u.toLowerCase())
|
|
29
|
+
);
|
|
30
|
+
if (missing.length > 0) {
|
|
31
|
+
logger.warn(`Default reviewer(s) not found among project members: ${missing.join(', ')}`);
|
|
32
|
+
}
|
|
33
|
+
const defaultUsernames = new Set(defaults.map(m => m.username));
|
|
34
|
+
|
|
35
|
+
const { reviewerUsernames } = await inquirer.prompt([
|
|
36
|
+
{
|
|
37
|
+
type: 'checkbox',
|
|
38
|
+
name: 'reviewerUsernames',
|
|
39
|
+
message: 'Select MR reviewer(s):',
|
|
40
|
+
pageSize: 15,
|
|
41
|
+
choices: members.map((m) => ({
|
|
42
|
+
name: `${m.name} (@${m.username})`,
|
|
43
|
+
value: m.username,
|
|
44
|
+
checked: defaultUsernames.has(m.username)
|
|
45
|
+
}))
|
|
46
|
+
}
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
return reviewerUsernames;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = { findDefaultReviewers, selectReviewer };
|
package/src/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const { createProgram } = require('./cli');
|
|
6
|
+
const { runRelease } = require('./workflow/release');
|
|
7
|
+
const { setupWizard } = require('./config/setup');
|
|
8
|
+
const { loadConfig, getConfigPath } = require('./config/loader');
|
|
9
|
+
const logger = require('./utils/logger');
|
|
10
|
+
const { maskSecret } = require('./utils/secrets');
|
|
11
|
+
|
|
12
|
+
const program = createProgram();
|
|
13
|
+
|
|
14
|
+
program
|
|
15
|
+
.command('release')
|
|
16
|
+
.description('Start the release process')
|
|
17
|
+
.option('-f, --file <path>', 'Path to branch list file')
|
|
18
|
+
.option('-b, --branches <branches>', 'Comma-separated list of branches')
|
|
19
|
+
.option('-l, --list-branches', 'Skip cherry-pick: create empty release branches from staging, open each MR from the source branch instead, and list the release branches created at the end')
|
|
20
|
+
.action(async (options) => {
|
|
21
|
+
try {
|
|
22
|
+
await runRelease(options);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
logger.error(error.message);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
program
|
|
30
|
+
.command('config')
|
|
31
|
+
.description('Configure release-cherry-pick settings')
|
|
32
|
+
.option('--init', 'Initialize configuration')
|
|
33
|
+
.option('--show', 'Show current configuration')
|
|
34
|
+
.action(async (options) => {
|
|
35
|
+
try {
|
|
36
|
+
if (options.init) {
|
|
37
|
+
await setupWizard();
|
|
38
|
+
} else if (options.show) {
|
|
39
|
+
const config = loadConfig();
|
|
40
|
+
if (config) {
|
|
41
|
+
logger.info(`Current configuration (${getConfigPath()}):`);
|
|
42
|
+
const shown = JSON.parse(JSON.stringify(config));
|
|
43
|
+
shown.gitlab.token = maskSecret(shown.gitlab.token);
|
|
44
|
+
shown.ai.apiKey = maskSecret(shown.ai.apiKey);
|
|
45
|
+
console.log(JSON.stringify(shown, null, 2));
|
|
46
|
+
} else {
|
|
47
|
+
logger.warn(`No configuration found for this project (expected at ${getConfigPath()})`);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
await setupWizard();
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
logger.error(error.message);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const logger = require('../utils/logger');
|
|
5
|
+
|
|
6
|
+
function generateSummary(releaseStatus, outputPath = null) {
|
|
7
|
+
const summary = releaseStatus.getSummary();
|
|
8
|
+
|
|
9
|
+
const summaryContent = {
|
|
10
|
+
timestamp: new Date().toISOString(),
|
|
11
|
+
summary: {
|
|
12
|
+
total: summary.total,
|
|
13
|
+
procede: summary.procede,
|
|
14
|
+
noProcede: summary.noProcede,
|
|
15
|
+
conflict: summary.conflict,
|
|
16
|
+
skipped: summary.skipped
|
|
17
|
+
},
|
|
18
|
+
results: summary.results.map(r => ({
|
|
19
|
+
taskId: r.taskId,
|
|
20
|
+
branch: r.branch,
|
|
21
|
+
status: r.status,
|
|
22
|
+
mrLink: r.mrLink,
|
|
23
|
+
conflicts: r.conflicts,
|
|
24
|
+
reason: r.reason,
|
|
25
|
+
notes: r.notes
|
|
26
|
+
}))
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (outputPath) {
|
|
30
|
+
saveSummaryToFile(summaryContent, outputPath);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return summaryContent;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function saveSummaryToFile(summary, outputPath) {
|
|
37
|
+
const content = JSON.stringify(summary, null, 2);
|
|
38
|
+
fs.writeFileSync(outputPath, content, 'utf8');
|
|
39
|
+
logger.info(`Summary saved to: ${outputPath}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function generateMarkdownSummary(releaseStatus) {
|
|
43
|
+
const summary = releaseStatus.getSummary();
|
|
44
|
+
|
|
45
|
+
let markdown = `# Release Summary\n\n`;
|
|
46
|
+
markdown += `**Date:** ${new Date().toLocaleString('es-ES')}\n\n`;
|
|
47
|
+
markdown += `## Statistics\n\n`;
|
|
48
|
+
markdown += `| Metric | Value |\n`;
|
|
49
|
+
markdown += `|--------|-------|\n`;
|
|
50
|
+
markdown += `| Total | ${summary.total} |\n`;
|
|
51
|
+
markdown += `| PROCEDE | ${summary.procede} |\n`;
|
|
52
|
+
markdown += `| NO PROCEDE | ${summary.noProcede} |\n`;
|
|
53
|
+
markdown += `| CONFLICT | ${summary.conflict} |\n`;
|
|
54
|
+
markdown += `| SKIPPED | ${summary.skipped} |\n\n`;
|
|
55
|
+
|
|
56
|
+
markdown += `## Results\n\n`;
|
|
57
|
+
|
|
58
|
+
for (const result of summary.results) {
|
|
59
|
+
const statusIcon = result.status === 'PROCEDE' ? '✅' : (result.status === 'CONFLICT' ? '⚠️' : (result.status === 'SKIPPED' ? 'ℹ️' : '❌'));
|
|
60
|
+
markdown += `### ${statusIcon} ${result.taskId}\n\n`;
|
|
61
|
+
markdown += `- **Branch:** ${result.branch}\n`;
|
|
62
|
+
markdown += `- **Status:** ${result.status}\n`;
|
|
63
|
+
|
|
64
|
+
if (result.mrLink) {
|
|
65
|
+
markdown += `- **MR:** [View MR](${result.mrLink})\n`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (result.status === 'CONFLICT') {
|
|
69
|
+
markdown += `- **Needs manual resolution by the user.**\n`;
|
|
70
|
+
markdown += `- **Conflicting files:** ${result.conflicts.join(', ')}\n`;
|
|
71
|
+
} else if (result.status === 'SKIPPED') {
|
|
72
|
+
markdown += `- **${result.reason || 'Nothing to release — no action needed.'}**\n`;
|
|
73
|
+
} else if (result.status === 'NO PROCEDE' && result.reason) {
|
|
74
|
+
markdown += `- **Reason:** ${result.reason}\n`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (const note of result.notes || []) {
|
|
78
|
+
markdown += `- ⚠️ ${note}\n`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
markdown += `\n`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return markdown;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = {
|
|
88
|
+
generateSummary,
|
|
89
|
+
generateMarkdownSummary,
|
|
90
|
+
saveSummaryToFile
|
|
91
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class AppError extends Error {
|
|
4
|
+
constructor(message, code = 'UNKNOWN_ERROR') {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'AppError';
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class ConfigError extends AppError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message, 'CONFIG_ERROR');
|
|
14
|
+
this.name = 'ConfigError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class GitError extends AppError {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message, 'GIT_ERROR');
|
|
21
|
+
this.name = 'GitError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class GitLabError extends AppError {
|
|
26
|
+
constructor(message) {
|
|
27
|
+
super(message, 'GITLAB_ERROR');
|
|
28
|
+
this.name = 'GitLabError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function handleError(error) {
|
|
33
|
+
if (error instanceof AppError) {
|
|
34
|
+
console.error(`Error [${error.code}]:`, error.message);
|
|
35
|
+
} else {
|
|
36
|
+
console.error('Unexpected error:', error.message);
|
|
37
|
+
}
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = {
|
|
42
|
+
AppError,
|
|
43
|
+
ConfigError,
|
|
44
|
+
GitError,
|
|
45
|
+
GitLabError,
|
|
46
|
+
handleError
|
|
47
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
|
|
5
|
+
const logger = {
|
|
6
|
+
info(message) {
|
|
7
|
+
console.log(chalk.green('✓'), message);
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
warn(message) {
|
|
11
|
+
console.log(chalk.yellow('⚠'), message);
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
error(message) {
|
|
15
|
+
console.log(chalk.red('✖'), message);
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
success(message) {
|
|
19
|
+
console.log(chalk.green.bold('✓'), message);
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
log(message) {
|
|
23
|
+
console.log(message);
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
header(message) {
|
|
27
|
+
console.log(chalk.bold.cyan('\n' + message));
|
|
28
|
+
console.log(chalk.cyan('─'.repeat(50)));
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
table(data) {
|
|
32
|
+
console.table(data);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
module.exports = logger;
|