bdy 1.25.38-dev-pr → 1.25.38-master

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 (103) hide show
  1. package/distTs/package.json +1 -2
  2. package/distTs/src/api/client.js +1 -191
  3. package/distTs/src/cliError.js +0 -5
  4. package/distTs/src/cliIndex.js +0 -3
  5. package/distTs/src/command/login.js +1 -1
  6. package/distTs/src/output/pipeline.js +56 -54
  7. package/distTs/src/output.js +22 -72
  8. package/distTs/src/texts.js +1 -450
  9. package/distTs/src/tunnel/output/interactive/tunnel.js +10 -14
  10. package/distTs/src/tunnel/output/noninteractive/tunnel.js +1 -3
  11. package/distTs/src/utils.js +3 -133
  12. package/package.json +1 -2
  13. package/distTs/src/autocomplete.js +0 -90
  14. package/distTs/src/command/artifact/downloadDir.js +0 -110
  15. package/distTs/src/command/autocomplete/install.js +0 -16
  16. package/distTs/src/command/autocomplete/uninstall.js +0 -16
  17. package/distTs/src/command/autocomplete.js +0 -14
  18. package/distTs/src/command/environment/resolve.js +0 -39
  19. package/distTs/src/command/package/create.js +0 -64
  20. package/distTs/src/command/package/delete.js +0 -38
  21. package/distTs/src/command/package/docker/login.js +0 -26
  22. package/distTs/src/command/package/docker.js +0 -11
  23. package/distTs/src/command/package/download.js +0 -138
  24. package/distTs/src/command/package/get.js +0 -36
  25. package/distTs/src/command/package/list.js +0 -31
  26. package/distTs/src/command/package/publish.js +0 -241
  27. package/distTs/src/command/package/version/delete.js +0 -39
  28. package/distTs/src/command/package/version/get.js +0 -45
  29. package/distTs/src/command/package/version/list.js +0 -47
  30. package/distTs/src/command/package/version.js +0 -16
  31. package/distTs/src/command/package.js +0 -26
  32. package/distTs/src/command/pipeline/run/apply.js +0 -62
  33. package/distTs/src/command/pr/comment/add.js +0 -66
  34. package/distTs/src/command/pr/comment/list.js +0 -169
  35. package/distTs/src/command/pr/comment/status.js +0 -48
  36. package/distTs/src/command/pr/comment.js +0 -19
  37. package/distTs/src/command/pr/create.js +0 -43
  38. package/distTs/src/command/pr/diff.js +0 -227
  39. package/distTs/src/command/pr/file/list.js +0 -124
  40. package/distTs/src/command/pr/file/mark.js +0 -45
  41. package/distTs/src/command/pr/file.js +0 -16
  42. package/distTs/src/command/pr/get.js +0 -29
  43. package/distTs/src/command/pr/list.js +0 -79
  44. package/distTs/src/command/pr/merge.js +0 -66
  45. package/distTs/src/command/pr/review/request.js +0 -29
  46. package/distTs/src/command/pr/review/start.js +0 -29
  47. package/distTs/src/command/pr/review/verdict.js +0 -81
  48. package/distTs/src/command/pr/review.js +0 -18
  49. package/distTs/src/command/pr/shared.js +0 -595
  50. package/distTs/src/command/pr/state.js +0 -38
  51. package/distTs/src/command/pr/summary.js +0 -316
  52. package/distTs/src/command/pr/update.js +0 -54
  53. package/distTs/src/command/pr/updateBranch.js +0 -22
  54. package/distTs/src/command/pr/versions.js +0 -42
  55. package/distTs/src/command/pr.js +0 -39
  56. package/distTs/src/command/scrape/validation.js +0 -154
  57. package/distTs/src/command/scrape.js +0 -144
  58. package/distTs/src/command/suiteLink.js +0 -14
  59. package/distTs/src/command/tests/visual/result/download.js +0 -31
  60. package/distTs/src/command/tests/visual/result/get.js +0 -68
  61. package/distTs/src/command/tests/visual/result/list.js +0 -49
  62. package/distTs/src/command/tests/visual/result.js +0 -23
  63. package/distTs/src/command/tests/visual/session/get.js +0 -70
  64. package/distTs/src/command/tests/visual/session/list.js +0 -69
  65. package/distTs/src/command/tests/visual/session/open.js +0 -22
  66. package/distTs/src/command/tests/visual/session/reviewUrl.js +0 -37
  67. package/distTs/src/command/tests/visual/session/update.js +0 -26
  68. package/distTs/src/command/tests/visual/shared/context.js +0 -144
  69. package/distTs/src/command/tests/visual/shared/diffRegions.js +0 -172
  70. package/distTs/src/command/tests/visual/shared/format.js +0 -21
  71. package/distTs/src/command/tests/visual/shared/lookup.js +0 -107
  72. package/distTs/src/command/tests/visual/shared/options.js +0 -90
  73. package/distTs/src/command/tests/visual/shared/review.js +0 -146
  74. package/distTs/src/command/tests/visual/shared/reviewUrl.js +0 -62
  75. package/distTs/src/command/tests/visual/shared/session.js +0 -217
  76. package/distTs/src/command/tests/visual/snapshot/get.js +0 -46
  77. package/distTs/src/command/tests/visual/snapshot/list.js +0 -68
  78. package/distTs/src/command/tests/visual/snapshot/open.js +0 -26
  79. package/distTs/src/command/tests/visual/snapshot/reviewUrl.js +0 -48
  80. package/distTs/src/command/tests/visual/snapshot.js +0 -28
  81. package/distTs/src/command/tests/visual/suite/create.js +0 -38
  82. package/distTs/src/command/tests/visual/suite/delete.js +0 -29
  83. package/distTs/src/command/tests/visual/suite/get.js +0 -43
  84. package/distTs/src/command/tests/visual/suite/list.js +0 -35
  85. package/distTs/src/command/tests/visual/suite/open.js +0 -20
  86. package/distTs/src/command/tests/visual/suite/update.js +0 -47
  87. package/distTs/src/command/tests/visual/suite.js +0 -30
  88. package/distTs/src/command/ut/upload.js +0 -86
  89. package/distTs/src/command/ut.js +0 -12
  90. package/distTs/src/command/vt/close.js +0 -27
  91. package/distTs/src/command/vt/compare/validation.js +0 -46
  92. package/distTs/src/command/vt/compare.js +0 -100
  93. package/distTs/src/command/vt/exec.js +0 -82
  94. package/distTs/src/command/vt/installBrowser.js +0 -20
  95. package/distTs/src/command/vt/shared/validation.js +0 -145
  96. package/distTs/src/command/vt/storybook.js +0 -138
  97. package/distTs/src/command/vt.js +0 -20
  98. package/distTs/src/command/yaml/agents.js +0 -88
  99. package/distTs/src/command/yaml/init.js +0 -110
  100. package/distTs/src/main.js +0 -190
  101. package/distTs/src/types/options.js +0 -2
  102. package/distTs/src/types/scrape.js +0 -2
  103. package/distTs/src/types/visualTests.js +0 -2
@@ -1,595 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.formatPatchLine = exports.hunkHeaderText = exports.patchColumnWidth = exports.codeAround = exports.parsePatch = exports.conflictVersion = exports.isVersionConflict = exports.noteVersionBehind = exports.threadOrigin = exports.threadHeader = exports.threadState = exports.threadStatusWithResolution = exports.resolutionText = exports.threadStatusText = exports.positionText = exports.anchorText = exports.versionKind = exports.firstLine = exports.sameMember = exports.memberName = exports.verdictText = exports.mergeableText = exports.processingStatusText = exports.prStateText = exports.formatDate = exports.shortSha = exports.rev = exports.fetchMustReview = exports.sortFilesForReading = exports.buildBatches = exports.fileSizeText = exports.changeTypeText = exports.fileStatusText = exports.filePriorityText = exports.tokensOf = exports.symbolLines = exports.field = exports.fetchAllThreads = exports.fetchAllFiles = exports.requireMyReview = exports.getMyReview = exports.readText = exports.splitNumberArgs = exports.resolveNumber = exports.parseRev = exports.parseLine = exports.currentGitBranch = exports.prScope = exports.addPrOptions = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = require("node:path");
9
- const node_child_process_1 = require("node:child_process");
10
- const cliError_1 = __importDefault(require("../../cliError"));
11
- const input_1 = __importDefault(require("../../input"));
12
- const output_1 = __importDefault(require("../../output"));
13
- const utils_1 = require("../../utils");
14
- const texts_1 = require("../../texts");
15
- /** Options every pr command takes; --rev only where the command works on a version. */
16
- const addPrOptions = (command, rev = false) => {
17
- command.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
18
- command.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
19
- if (rev)
20
- command.option('--rev <vK>', texts_1.OPTION_PR_REV);
21
- command.option('--format <text|json>', texts_1.OPTION_FORMAT);
22
- };
23
- exports.addPrOptions = addPrOptions;
24
- const prScope = (options) => {
25
- const workspace = input_1.default.restApiWorkspace(options.workspace);
26
- const project = input_1.default.restApiProject(options.project);
27
- const client = input_1.default.restApiTokenClient();
28
- // only what came as a flag: a linked or default project needs no flag in the next command either
29
- const flags = [
30
- options.workspace ? ` -w ${options.workspace}` : '',
31
- options.project ? ` -p ${options.project}` : '',
32
- ].join('');
33
- return { client, workspace, project, cmd: (args) => `bdy pr ${args}${flags}` };
34
- };
35
- exports.prScope = prScope;
36
- const currentGitBranch = () => {
37
- try {
38
- // symbolic-ref works before the first commit too (rev-parse HEAD does not)
39
- // and fails on a detached HEAD, which has no branch
40
- const branch = (0, node_child_process_1.execFileSync)('git', ['symbolic-ref', '--short', '-q', 'HEAD'], {
41
- encoding: 'utf8',
42
- stdio: ['ignore', 'pipe', 'ignore'],
43
- }).trim();
44
- return branch || null;
45
- }
46
- catch {
47
- return null;
48
- }
49
- };
50
- exports.currentGitBranch = currentGitBranch;
51
- const parsePositive = (value, error) => {
52
- if (!/^[1-9]\d*$/.test(value) || !Number.isSafeInteger(Number(value))) {
53
- throw new cliError_1.default('usage_error', error);
54
- }
55
- return Number(value);
56
- };
57
- const parseLine = (value, option) => value === undefined ? undefined : parsePositive(value, (0, texts_1.ERR_PR_LINE)(option));
58
- exports.parseLine = parseLine;
59
- /** `v3` or `3` -> 3; undefined stays undefined (the current version). */
60
- const parseRev = (rev) => {
61
- if (rev === undefined)
62
- return undefined;
63
- const match = /^v?([1-9]\d*)$/i.exec(rev.trim());
64
- if (!match)
65
- throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_REV)(rev));
66
- return Number(match[1]);
67
- };
68
- exports.parseRev = parseRev;
69
- /**
70
- * The pull request number: the one given, or the open pull request of the
71
- * current git branch.
72
- */
73
- const resolveNumber = async (scope, number) => {
74
- if (number !== undefined)
75
- return parsePositive(number, texts_1.ERR_PR_NUMBER);
76
- const branch = (0, exports.currentGitBranch)();
77
- if (!branch)
78
- throw new cliError_1.default('usage_error', texts_1.ERR_PR_NO_BRANCH);
79
- const result = await scope.client.getPullRequests(scope.workspace, scope.project, { state: utils_1.PR_STATE.OPEN, head: branch, per_page: 100 });
80
- const prs = result?.pull_requests || [];
81
- if (prs.length === 0) {
82
- throw new cliError_1.default('not_found', (0, texts_1.ERR_PR_NOT_FOUND_FOR_BRANCH)(branch));
83
- }
84
- if (prs.length > 1) {
85
- throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_MANY_FOR_BRANCH)(branch, prs.map((pr) => `#${pr.number}`).join(', ')));
86
- }
87
- return prs[0].number;
88
- };
89
- exports.resolveNumber = resolveNumber;
90
- /**
91
- * `[N] <x...>` arguments: the first one is the number only when it is an
92
- * integer and more arguments follow, so a lone argument is always the path
93
- * or login.
94
- */
95
- const splitNumberArgs = (args) => {
96
- if (args.length > 1 && /^\d+$/.test(args[0])) {
97
- return { number: args[0], rest: args.slice(1) };
98
- }
99
- return { rest: args };
100
- };
101
- exports.splitNumberArgs = splitNumberArgs;
102
- /** -m <text|@path|->: the text itself, a file, or stdin. */
103
- const readText = (value, required = true) => {
104
- if (value === undefined || value === '') {
105
- if (required)
106
- throw new cliError_1.default('usage_error', texts_1.ERR_PR_MESSAGE_REQUIRED);
107
- return undefined;
108
- }
109
- if (value === '-')
110
- return node_fs_1.default.readFileSync(0, 'utf8');
111
- if (value.startsWith('@')) {
112
- const path = (0, node_path_1.resolve)(value.slice(1));
113
- if (!node_fs_1.default.existsSync(path)) {
114
- throw new cliError_1.default('file_not_found', (0, texts_1.ERR_PR_MESSAGE_FILE)(path));
115
- }
116
- return node_fs_1.default.readFileSync(path, 'utf8');
117
- }
118
- return value;
119
- };
120
- exports.readText = readText;
121
- /** The caller's review, or null when they have none (404). */
122
- const getMyReview = async (scope, number) => {
123
- try {
124
- return await scope.client.getPullRequestReview(scope.workspace, scope.project, number);
125
- }
126
- catch (err) {
127
- if (err instanceof cliError_1.default && err.status === 404)
128
- return null;
129
- throw err;
130
- }
131
- };
132
- exports.getMyReview = getMyReview;
133
- const requireMyReview = async (scope, number) => {
134
- const review = await (0, exports.getMyReview)(scope, number);
135
- if (!review)
136
- throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_NO_REVIEW)(scope.cmd, number));
137
- return review;
138
- };
139
- exports.requireMyReview = requireMyReview;
140
- /** Every page of the files of a version. */
141
- const fetchAllFiles = async (scope, number, query) => {
142
- const perPage = 500;
143
- const files = [];
144
- let first = null;
145
- for (let page = 1;; page += 1) {
146
- const result = await scope.client.getPullRequestFiles(scope.workspace, scope.project, number, { ...query, page, per_page: perPage });
147
- if (!first)
148
- first = result;
149
- const items = result?.files || [];
150
- files.push(...items);
151
- const total = Number(result?.total ?? files.length);
152
- if (items.length < perPage || files.length >= total)
153
- break;
154
- }
155
- return { ...first, files };
156
- };
157
- exports.fetchAllFiles = fetchAllFiles;
158
- /** Every page of the threads of a version. */
159
- const fetchAllThreads = async (scope, number, query) => {
160
- const perPage = 100;
161
- const threads = [];
162
- let first = null;
163
- for (let page = 1;; page += 1) {
164
- const result = await scope.client.getPullRequestThreads(scope.workspace, scope.project, number, { ...query, page, per_page: perPage });
165
- if (!first)
166
- first = result;
167
- const items = result?.threads || [];
168
- threads.push(...items);
169
- const total = Number(result?.total ?? threads.length);
170
- if (items.length < perPage || threads.length >= total)
171
- break;
172
- }
173
- return { ...first, threads };
174
- };
175
- exports.fetchAllThreads = fetchAllThreads;
176
- /** `name value` with the name in a darker grey than the value, so the values stand out. */
177
- const field = (name, value) => `${output_1.default.getMutedColor(name)} ${output_1.default.getLabelColor(value)}`;
178
- exports.field = field;
179
- /**
180
- * One line per changed symbol, `name change` with the change in color (added
181
- * green, modified yellow, removed red); a class or interface whose members are
182
- * listed too is left out.
183
- */
184
- const symbolLines = (symbols) => {
185
- const shown = symbols.filter((s) => !symbols.some((o) => o !== s && String(o.name).startsWith(`${s.name}.`)));
186
- const width = Math.max(...shown.map((s) => String(s.name).length));
187
- return shown.map((s) => {
188
- const change = String(s.change || '').toLowerCase();
189
- const colored = change === 'added'
190
- ? output_1.default.getGreenColor(change)
191
- : change === 'removed'
192
- ? output_1.default.getRedColor(change)
193
- : output_1.default.getYellowColor(change);
194
- return `${String(s.name).padEnd(width)} ${colored}`;
195
- });
196
- };
197
- exports.symbolLines = symbolLines;
198
- const tokensOf = (file) => Math.ceil(Number(file?.analysis?.diff_size || 0) / 4);
199
- exports.tokensOf = tokensOf;
200
- /** must review (yellow) / safe to skip; an unclear or untriaged file has none. Same in pr get and pr file ls. */
201
- const filePriorityText = (priority) => {
202
- switch (priority) {
203
- case utils_1.PR_REVIEW_PRIORITY.MUST_REVIEW:
204
- return output_1.default.getYellowColor(texts_1.TXT_PR_FILE_MUST_REVIEW);
205
- case utils_1.PR_REVIEW_PRIORITY.SKIP:
206
- return output_1.default.getMutedColor(texts_1.TXT_PR_FILE_SKIP);
207
- default:
208
- return null;
209
- }
210
- };
211
- exports.filePriorityText = filePriorityText;
212
- /** ADDED green, DELETED red, RENAMED blue, MODIFIED as is. */
213
- const fileStatusText = (status) => {
214
- if (status === utils_1.PR_FILE_STATUS.ADDED)
215
- return output_1.default.getGreenColor(status);
216
- if (status === utils_1.PR_FILE_STATUS.DELETED)
217
- return output_1.default.getRedColor(status);
218
- if (status === utils_1.PR_FILE_STATUS.RENAMED)
219
- return output_1.default.getBlueColor(status);
220
- return status || '-';
221
- };
222
- exports.fileStatusText = fileStatusText;
223
- /**
224
- * change_type by group: a change of code (CODE, ADDED, DELETED) as is, no
225
- * change of behaviour (FORMATTING_ONLY, IMPORTS_ONLY, RENAME_ONLY) grey, not
226
- * analyzed (NOT_PARSED, BINARY) purple, PARSE_ERROR red.
227
- */
228
- const changeTypeText = (type) => {
229
- switch (type) {
230
- case utils_1.PR_CHANGE_TYPE.FORMATTING_ONLY:
231
- case utils_1.PR_CHANGE_TYPE.IMPORTS_ONLY:
232
- case utils_1.PR_CHANGE_TYPE.RENAME_ONLY:
233
- return output_1.default.getMutedColor(type);
234
- case utils_1.PR_CHANGE_TYPE.NOT_PARSED:
235
- case utils_1.PR_CHANGE_TYPE.BINARY:
236
- return output_1.default.getPurpleColor(type);
237
- case utils_1.PR_CHANGE_TYPE.PARSE_ERROR:
238
- return output_1.default.getRedColor(type);
239
- default:
240
- return type || '-';
241
- }
242
- };
243
- exports.changeTypeText = changeTypeText;
244
- /** `3kB/~56`: the patch size and its estimate in tokens; `-` until the version is analyzed. */
245
- const fileSizeText = (file) => {
246
- const size = Number(file?.analysis?.diff_size || 0);
247
- if (!file?.analysis)
248
- return '-';
249
- return `${(0, utils_1.formatBytes)(size)}/~${(0, exports.tokensOf)(file)}`;
250
- };
251
- exports.fileSizeText = fileSizeText;
252
- /**
253
- * Batches of the MUST_REVIEW files for subagents: in path order, up to
254
- * PR_BATCH_MAX_TOKENS each, made only from PR_BATCH_MIN_FILES files or
255
- * PR_BATCH_MIN_TOKENS tokens on. Empty when the list is small enough for one
256
- * agent.
257
- */
258
- const buildBatches = (mustReview) => {
259
- const total = mustReview.reduce((sum, file) => sum + (0, exports.tokensOf)(file), 0);
260
- if (mustReview.length < utils_1.PR_BATCH_MIN_FILES && total < utils_1.PR_BATCH_MIN_TOKENS) {
261
- return [];
262
- }
263
- const sorted = [...mustReview].sort((a, b) => a.file_name < b.file_name ? -1 : a.file_name > b.file_name ? 1 : 0);
264
- const batches = [];
265
- let current = null;
266
- for (const file of sorted) {
267
- const tokens = (0, exports.tokensOf)(file);
268
- if (!current || (current.files.length > 0 && current.tokens + tokens > utils_1.PR_BATCH_MAX_TOKENS)) {
269
- current = { batch: batches.length + 1, files: [], tokens: 0 };
270
- batches.push(current);
271
- }
272
- current.files.push(file);
273
- current.tokens += tokens;
274
- }
275
- return batches;
276
- };
277
- exports.buildBatches = buildBatches;
278
- /**
279
- * The order `pr file ls` lists files in, what is left to read first: unviewed
280
- * before viewed; within each MUST_REVIEW, UNCLEAR, files without triage, SKIP
281
- * last; then the triage's review order, and the smallest first where there is none.
282
- */
283
- const sortFilesForReading = (files) => {
284
- const rank = (file) => {
285
- switch (file.triage?.review_priority) {
286
- case utils_1.PR_REVIEW_PRIORITY.MUST_REVIEW:
287
- return 0;
288
- case utils_1.PR_REVIEW_PRIORITY.UNCLEAR:
289
- return 1;
290
- case utils_1.PR_REVIEW_PRIORITY.SKIP:
291
- return 3;
292
- default:
293
- return 2;
294
- }
295
- };
296
- const order = (file) => file.triage?.review_order ?? Number.MAX_SAFE_INTEGER;
297
- return [...files].sort((a, b) => Number(!!a.viewed) - Number(!!b.viewed) ||
298
- rank(a) - rank(b) ||
299
- order(a) - order(b) ||
300
- Number(a.analysis?.diff_size || 0) - Number(b.analysis?.diff_size || 0));
301
- };
302
- exports.sortFilesForReading = sortFilesForReading;
303
- /** Every MUST_REVIEW file of a version, in review order. */
304
- const fetchMustReview = async (scope, number, version) => (0, exports.fetchAllFiles)(scope, number, {
305
- version,
306
- review_priority: utils_1.PR_REVIEW_PRIORITY.MUST_REVIEW,
307
- sort: utils_1.PR_FILES_SORT.REVIEW_ORDER,
308
- });
309
- exports.fetchMustReview = fetchMustReview;
310
- const rev = (version) => `v${version}`;
311
- exports.rev = rev;
312
- const shortSha = (sha) => (sha ? sha.slice(0, 7) : '-');
313
- exports.shortSha = shortSha;
314
- const formatDate = (date) => {
315
- if (!date)
316
- return '-';
317
- const d = new Date(date);
318
- if (Number.isNaN(d.getTime()))
319
- return date;
320
- return d.toISOString().replace('T', ' ').slice(0, 16);
321
- };
322
- exports.formatDate = formatDate;
323
- /** OPEN green, MERGED purple, CLOSED red; a draft adds a muted `draft`. */
324
- const prStateText = (pr) => {
325
- const state = String(pr?.state || '-');
326
- const colored = state === utils_1.PR_STATE.OPEN
327
- ? output_1.default.getGreenColor(state)
328
- : state === utils_1.PR_STATE.MERGED
329
- ? output_1.default.getPurpleColor(state)
330
- : state === utils_1.PR_STATE.CLOSED
331
- ? output_1.default.getRedColor(state)
332
- : state;
333
- return pr?.draft ? `${colored} ${output_1.default.getMutedColor(texts_1.TXT_PR_DRAFT)}` : colored;
334
- };
335
- exports.prStateText = prStateText;
336
- /** Analysis / triage status: READY green, PENDING yellow, FAILED red. */
337
- const processingStatusText = (status) => {
338
- if (status === utils_1.PR_PROCESSING_STATUS.READY)
339
- return output_1.default.getGreenColor(status);
340
- if (status === utils_1.PR_PROCESSING_STATUS.PENDING)
341
- return output_1.default.getYellowColor(status);
342
- if (status === utils_1.PR_PROCESSING_STATUS.FAILED)
343
- return output_1.default.getRedColor(status);
344
- return status || '-';
345
- };
346
- exports.processingStatusText = processingStatusText;
347
- /** MERGEABLE green, CONFLICTING red, UNKNOWN yellow. */
348
- const mergeableText = (mergeable) => {
349
- if (!mergeable)
350
- return '-';
351
- if (mergeable === utils_1.PR_MERGEABLE.MERGEABLE)
352
- return output_1.default.getGreenColor(mergeable);
353
- if (mergeable === utils_1.PR_MERGEABLE.CONFLICTING)
354
- return output_1.default.getRedColor(mergeable);
355
- return output_1.default.getYellowColor(mergeable);
356
- };
357
- exports.mergeableText = mergeableText;
358
- /** APPROVED green, CHANGE_REQUESTED red, PENDING yellow. */
359
- const verdictText = (verdict) => {
360
- if (!verdict)
361
- return '-';
362
- if (verdict === utils_1.PR_VERDICT.APPROVED)
363
- return output_1.default.getGreenColor(verdict);
364
- if (verdict === utils_1.PR_VERDICT.CHANGE_REQUESTED)
365
- return output_1.default.getRedColor(verdict);
366
- return output_1.default.getYellowColor(verdict);
367
- };
368
- exports.verdictText = verdictText;
369
- const memberName = (member) => member?.name || member?.email || (member?.id !== undefined ? `#${member.id}` : '-');
370
- exports.memberName = memberName;
371
- const sameMember = (a, b) => !!a && !!b && a.id !== undefined && a.id === b.id;
372
- exports.sameMember = sameMember;
373
- const firstLine = (text) => (text || '').split('\n').find((line) => line.trim() !== '')?.trim() || '';
374
- exports.firstLine = firstLine;
375
- /** `rebase` / `force` for a version that was not a plain push, else null. */
376
- const versionKind = (forced) => forced === utils_1.PR_VERSION_FORCED.REBASE
377
- ? texts_1.TXT_PR_VERSION_KIND_REBASE
378
- : forced === utils_1.PR_VERSION_FORCED.REWRITE
379
- ? texts_1.TXT_PR_VERSION_KIND_REWRITE
380
- : null;
381
- exports.versionKind = versionKind;
382
- const anchorText = (state) => {
383
- switch (state) {
384
- case utils_1.PR_ANCHOR_STATE.INTACT:
385
- return texts_1.TXT_PR_ANCHOR_INTACT;
386
- case utils_1.PR_ANCHOR_STATE.TOUCHED:
387
- return texts_1.TXT_PR_ANCHOR_TOUCHED;
388
- case utils_1.PR_ANCHOR_STATE.MOVED:
389
- return texts_1.TXT_PR_ANCHOR_MOVED;
390
- case utils_1.PR_ANCHOR_STATE.GONE:
391
- return texts_1.TXT_PR_ANCHOR_GONE;
392
- default:
393
- return null;
394
- }
395
- };
396
- exports.anchorText = anchorText;
397
- /** `path:42`, `path:-17` for a base-side line, or `-` when the code is gone. */
398
- const positionText = (position) => {
399
- if (!position?.path)
400
- return '-';
401
- if (position.new_line)
402
- return `${position.path}:${position.new_line}`;
403
- if (position.old_line)
404
- return `${position.path}:-${position.old_line}`;
405
- return position.path;
406
- };
407
- exports.positionText = positionText;
408
- /** "OPEN, code changed, no reply" / "RESOLVED (FIXED), code unchanged". */
409
- /** OPEN yellow (waits for someone), RESOLVED cyan (to be verified), CLOSED green (done). */
410
- const threadStatusText = (status) => {
411
- if (status === utils_1.PR_THREAD_STATUS.OPEN)
412
- return output_1.default.getYellowColor(status);
413
- if (status === utils_1.PR_THREAD_STATUS.RESOLVED)
414
- return output_1.default.getCyanColor(status);
415
- if (status === utils_1.PR_THREAD_STATUS.CLOSED)
416
- return output_1.default.getGreenColor(status);
417
- return status || '-';
418
- };
419
- exports.threadStatusText = threadStatusText;
420
- /** FIXED green, BY_DESIGN blue, WONTFIX grey. */
421
- const resolutionText = (resolution) => {
422
- if (resolution === utils_1.PR_THREAD_RESOLUTION.FIXED)
423
- return output_1.default.getGreenColor(resolution);
424
- if (resolution === utils_1.PR_THREAD_RESOLUTION.BY_DESIGN)
425
- return output_1.default.getBlueColor(resolution);
426
- if (resolution === utils_1.PR_THREAD_RESOLUTION.WONTFIX)
427
- return output_1.default.getMutedColor(resolution);
428
- return resolution || '';
429
- };
430
- exports.resolutionText = resolutionText;
431
- /** `STATUS (RESOLUTION)` in colors; the resolution only when there is one. */
432
- const threadStatusWithResolution = (status, resolution) => resolution
433
- ? `${(0, exports.threadStatusText)(status)} (${(0, exports.resolutionText)(resolution)})`
434
- : (0, exports.threadStatusText)(status);
435
- exports.threadStatusWithResolution = threadStatusWithResolution;
436
- const threadState = (thread) => {
437
- const parts = [(0, exports.threadStatusWithResolution)(thread.status, thread.resolution)];
438
- const anchor = (0, exports.anchorText)(thread.position?.anchor_state);
439
- if (anchor)
440
- parts.push(anchor);
441
- const replies = thread.comments || [];
442
- if (replies.length === 0)
443
- parts.push(texts_1.TXT_PR_NO_REPLY);
444
- else {
445
- const last = replies[replies.length - 1];
446
- parts.push((0, texts_1.TXT_PR_LAST_REPLY)((0, exports.memberName)(last.user), (0, exports.formatDate)(last.create_date)));
447
- }
448
- return parts.join(', ');
449
- };
450
- exports.threadState = threadState;
451
- /**
452
- * `path:line symbol - state` of a thread, its id last and muted: the id is
453
- * what --thread takes, the path is what a reader looks for.
454
- */
455
- const threadHeader = (thread, extra = '') => {
456
- const symbol = thread.position?.symbol ? ` ${thread.position.symbol}` : '';
457
- // a thread whose code is gone has no position: it starts with its state
458
- const where = thread.position?.path ? `${(0, exports.positionText)(thread.position)}${symbol} - ` : '';
459
- return `${where}${(0, exports.threadState)(thread)}${extra} ${output_1.default.getMutedColor(`· ${thread.id}`)}`;
460
- };
461
- exports.threadHeader = threadHeader;
462
- /**
463
- * Where a MOVED or GONE thread was opened: its position in the version it was
464
- * created in (the thread view carries only the position in the version asked
465
- * for). Null for other threads or when it cannot be read.
466
- */
467
- const threadOrigin = async (scope, number, thread) => {
468
- const state = thread.position?.anchor_state;
469
- if (state !== utils_1.PR_ANCHOR_STATE.MOVED && state !== utils_1.PR_ANCHOR_STATE.GONE)
470
- return null;
471
- if (!thread.created_version)
472
- return null;
473
- try {
474
- const origin = await scope.client.getPullRequestThread(scope.workspace, scope.project, number, thread.id, thread.created_version);
475
- return origin?.position || null;
476
- }
477
- catch {
478
- return null;
479
- }
480
- };
481
- exports.threadOrigin = threadOrigin;
482
- /** Prints that the pull request moved on when the command works on an older version. */
483
- const noteVersionBehind = (current, working) => {
484
- if (current && working && current !== working) {
485
- output_1.default.noteWarning((0, texts_1.TXT_PR_VERSION_BEHIND)(current, working));
486
- }
487
- };
488
- exports.noteVersionBehind = noteVersionBehind;
489
- const isVersionConflict = (err) => err instanceof cliError_1.default && err.status === 409;
490
- exports.isVersionConflict = isVersionConflict;
491
- const conflictVersion = (err) => {
492
- const value = err.body?.current_version;
493
- return typeof value === 'number' ? value : undefined;
494
- };
495
- exports.conflictVersion = conflictVersion;
496
- /** Splits a unified patch into hunks with the old and new line number of every line. */
497
- const parsePatch = (patch) => {
498
- if (!patch)
499
- return [];
500
- const hunks = [];
501
- let hunk = null;
502
- let oldLine = 0;
503
- let newLine = 0;
504
- const lines = patch.split('\n');
505
- if (lines.length > 0 && lines[lines.length - 1] === '')
506
- lines.pop();
507
- for (const text of lines) {
508
- const header = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(text);
509
- if (header) {
510
- oldLine = Number(header[1]);
511
- newLine = Number(header[2]);
512
- hunk = { header: text, oldStart: oldLine, newStart: newLine, lines: [] };
513
- hunks.push(hunk);
514
- continue;
515
- }
516
- if (!hunk)
517
- continue;
518
- if (text.startsWith('+')) {
519
- hunk.lines.push({ type: 'add', text: text.slice(1), newLine });
520
- newLine += 1;
521
- }
522
- else if (text.startsWith('-')) {
523
- hunk.lines.push({ type: 'del', text: text.slice(1), oldLine });
524
- oldLine += 1;
525
- }
526
- else if (text.startsWith('\\')) {
527
- hunk.lines.push({ type: 'meta', text });
528
- }
529
- else {
530
- hunk.lines.push({ type: 'context', text: text.slice(1), oldLine, newLine });
531
- oldLine += 1;
532
- newLine += 1;
533
- }
534
- }
535
- return hunks;
536
- };
537
- exports.parsePatch = parsePatch;
538
- /** A few lines of the patch around a line of one side, for a thread listing. */
539
- const codeAround = (hunks, position, radius = 2) => {
540
- const side = position?.new_line ? 'newLine' : 'oldLine';
541
- const line = position?.new_line || position?.old_line;
542
- if (!line)
543
- return [];
544
- for (const hunk of hunks) {
545
- const index = hunk.lines.findIndex((l) => l[side] === line);
546
- if (index >= 0) {
547
- return hunk.lines.slice(Math.max(0, index - radius), index + radius + 1);
548
- }
549
- }
550
- return [];
551
- };
552
- exports.codeAround = codeAround;
553
- /** Width of the line number columns: the longest number in the hunks, at least `old`. */
554
- const patchColumnWidth = (hunks) => {
555
- let max = 0;
556
- for (const hunk of hunks) {
557
- for (const line of hunk.lines)
558
- max = Math.max(max, line.oldLine ?? 0, line.newLine ?? 0);
559
- }
560
- return Math.max(texts_1.TXT_PR_DIFF_COLUMN_OLD.length, texts_1.TXT_PR_DIFF_COLUMN_NEW.length, String(max).length);
561
- };
562
- exports.patchColumnWidth = patchColumnWidth;
563
- /**
564
- * A hunk separator instead of `@@ -25,19 +30,9 @@ export class UserService {`:
565
- * ` old new ── 25–43 → 30–38 ── export class UserService {`, with `old` and
566
- * `new` right above the line number columns of that width.
567
- */
568
- const hunkHeaderText = (header, width = 5) => {
569
- const match = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@ ?(.*)$/.exec(header);
570
- const columns = output_1.default.getMutedColor(`${texts_1.TXT_PR_DIFF_COLUMN_OLD.padStart(width)} ${texts_1.TXT_PR_DIFF_COLUMN_NEW.padStart(width)}`);
571
- if (!match)
572
- return `${columns} ${output_1.default.getCyanColor(header)}`;
573
- const range = (start, count) => {
574
- const from = Number(start);
575
- const n = count === undefined ? 1 : Number(count);
576
- if (n === 0)
577
- return '-';
578
- return n === 1 ? String(from) : `${from}–${from + n - 1}`;
579
- };
580
- const lines = `${range(match[1], match[2])} → ${range(match[3], match[4])}`;
581
- const context = match[5] ? ` ${output_1.default.getLabelColor(match[5].trim())}` : '';
582
- return `${columns} ${output_1.default.getCyanColor(`── ${lines} ──`)}${context}`;
583
- };
584
- exports.hunkHeaderText = hunkHeaderText;
585
- const formatPatchLine = (line, width = 5) => {
586
- const num = (n) => (n === undefined ? '' : String(n)).padStart(width);
587
- const sign = line.type === 'add' ? '+' : line.type === 'del' ? '-' : ' ';
588
- const text = `${num(line.oldLine)} ${num(line.newLine)} ${sign} ${line.text}`;
589
- if (line.type === 'add')
590
- return output_1.default.getGreenColor(text);
591
- if (line.type === 'del')
592
- return output_1.default.getRedColor(text);
593
- return text;
594
- };
595
- exports.formatPatchLine = formatPatchLine;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.commandPrDraft = exports.commandPrReady = exports.commandPrReopen = exports.commandPrClose = void 0;
7
- const utils_1 = require("../../utils");
8
- const texts_1 = require("../../texts");
9
- const output_1 = __importDefault(require("../../output"));
10
- const shared_1 = require("./shared");
11
- /** A command that changes one field of the pull request: close, reopen, ready, draft. */
12
- const stateCommand = (name, description, examples, body, done) => {
13
- const command = (0, utils_1.newCommand)(name, description, {
14
- requiredScopes: [utils_1.REST_API_SCOPE.REPOSITORY_WRITE],
15
- examples,
16
- });
17
- (0, shared_1.addPrOptions)(command);
18
- command.argument('[N]', texts_1.OPTION_PR_NUMBER);
19
- command.action(async (n, options) => {
20
- const scope = (0, shared_1.prScope)(options);
21
- const number = await (0, shared_1.resolveNumber)(scope, n);
22
- const before = await scope.client.getPullRequest(scope.workspace, scope.project, number);
23
- const pr = await scope.client.updatePullRequest(scope.workspace, scope.project, number, body);
24
- if (options.format === 'json')
25
- output_1.default.exitResult(true, pr);
26
- // a reopen after changes in the branches makes a new version
27
- if (pr?.version && before?.version && pr.version !== before.version) {
28
- output_1.default.noteWarning((0, texts_1.TXT_PR_NEW_VERSION)(pr.version));
29
- }
30
- output_1.default.exitSuccess(done(number));
31
- });
32
- return command;
33
- };
34
- // the number of a closed pull request has to be given: the branch lookup finds only open ones
35
- exports.commandPrClose = stateCommand('close', texts_1.DESC_COMMAND_PR_CLOSE, texts_1.EXAMPLE_PR_CLOSE, { state: utils_1.PR_STATE.CLOSED }, texts_1.TXT_PR_CLOSED);
36
- exports.commandPrReopen = stateCommand('reopen', texts_1.DESC_COMMAND_PR_REOPEN, texts_1.EXAMPLE_PR_REOPEN, { state: utils_1.PR_STATE.OPEN }, texts_1.TXT_PR_REOPENED);
37
- exports.commandPrReady = stateCommand('ready', texts_1.DESC_COMMAND_PR_READY, texts_1.EXAMPLE_PR_READY, { draft: false }, texts_1.TXT_PR_READY);
38
- exports.commandPrDraft = stateCommand('draft', texts_1.DESC_COMMAND_PR_DRAFT, texts_1.EXAMPLE_PR_DRAFT, { draft: true }, texts_1.TXT_PR_DRAFTED);