bdy 1.25.43-dev-pr → 1.25.44-dev
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/distTs/package.json +6 -5
- package/distTs/src/api/client.js +1 -191
- package/distTs/src/cliError.js +0 -5
- package/distTs/src/cliIndex.js +0 -3
- package/distTs/src/command/login.js +1 -1
- package/distTs/src/output/pipeline.js +56 -54
- package/distTs/src/output.js +22 -85
- package/distTs/src/texts.js +1 -510
- package/distTs/src/tunnel/output/interactive/tunnel.js +10 -14
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +1 -3
- package/distTs/src/utils.js +6 -142
- package/package.json +6 -5
- package/distTs/src/autocomplete.js +0 -90
- package/distTs/src/command/artifact/downloadDir.js +0 -110
- package/distTs/src/command/autocomplete/install.js +0 -16
- package/distTs/src/command/autocomplete/uninstall.js +0 -16
- package/distTs/src/command/autocomplete.js +0 -14
- package/distTs/src/command/environment/resolve.js +0 -39
- package/distTs/src/command/package/create.js +0 -64
- package/distTs/src/command/package/delete.js +0 -38
- package/distTs/src/command/package/docker/login.js +0 -26
- package/distTs/src/command/package/docker.js +0 -11
- package/distTs/src/command/package/download.js +0 -138
- package/distTs/src/command/package/get.js +0 -36
- package/distTs/src/command/package/list.js +0 -31
- package/distTs/src/command/package/publish.js +0 -241
- package/distTs/src/command/package/version/delete.js +0 -39
- package/distTs/src/command/package/version/get.js +0 -45
- package/distTs/src/command/package/version/list.js +0 -47
- package/distTs/src/command/package/version.js +0 -16
- package/distTs/src/command/package.js +0 -26
- package/distTs/src/command/pipeline/run/apply.js +0 -62
- package/distTs/src/command/pr/comment/add.js +0 -66
- package/distTs/src/command/pr/comment/list.js +0 -167
- package/distTs/src/command/pr/comment/status.js +0 -50
- package/distTs/src/command/pr/comment.js +0 -19
- package/distTs/src/command/pr/create.js +0 -44
- package/distTs/src/command/pr/diff.js +0 -337
- package/distTs/src/command/pr/file/list.js +0 -139
- package/distTs/src/command/pr/file/mark.js +0 -45
- package/distTs/src/command/pr/file.js +0 -16
- package/distTs/src/command/pr/get.js +0 -29
- package/distTs/src/command/pr/list.js +0 -79
- package/distTs/src/command/pr/merge.js +0 -67
- package/distTs/src/command/pr/review/request.js +0 -30
- package/distTs/src/command/pr/review/start.js +0 -29
- package/distTs/src/command/pr/review/verdict.js +0 -81
- package/distTs/src/command/pr/review.js +0 -18
- package/distTs/src/command/pr/shared.js +0 -704
- package/distTs/src/command/pr/state.js +0 -38
- package/distTs/src/command/pr/summary.js +0 -341
- package/distTs/src/command/pr/update.js +0 -56
- package/distTs/src/command/pr/updateBranch.js +0 -22
- package/distTs/src/command/pr/versions.js +0 -42
- package/distTs/src/command/pr.js +0 -39
- package/distTs/src/command/scrape/validation.js +0 -154
- package/distTs/src/command/scrape.js +0 -144
- package/distTs/src/command/suiteLink.js +0 -14
- package/distTs/src/command/tests/visual/result/download.js +0 -31
- package/distTs/src/command/tests/visual/result/get.js +0 -68
- package/distTs/src/command/tests/visual/result/list.js +0 -49
- package/distTs/src/command/tests/visual/result.js +0 -23
- package/distTs/src/command/tests/visual/session/get.js +0 -70
- package/distTs/src/command/tests/visual/session/list.js +0 -69
- package/distTs/src/command/tests/visual/session/open.js +0 -22
- package/distTs/src/command/tests/visual/session/reviewUrl.js +0 -37
- package/distTs/src/command/tests/visual/session/update.js +0 -26
- package/distTs/src/command/tests/visual/shared/context.js +0 -144
- package/distTs/src/command/tests/visual/shared/diffRegions.js +0 -172
- package/distTs/src/command/tests/visual/shared/format.js +0 -21
- package/distTs/src/command/tests/visual/shared/lookup.js +0 -107
- package/distTs/src/command/tests/visual/shared/options.js +0 -90
- package/distTs/src/command/tests/visual/shared/review.js +0 -146
- package/distTs/src/command/tests/visual/shared/reviewUrl.js +0 -62
- package/distTs/src/command/tests/visual/shared/session.js +0 -217
- package/distTs/src/command/tests/visual/snapshot/get.js +0 -46
- package/distTs/src/command/tests/visual/snapshot/list.js +0 -68
- package/distTs/src/command/tests/visual/snapshot/open.js +0 -26
- package/distTs/src/command/tests/visual/snapshot/reviewUrl.js +0 -48
- package/distTs/src/command/tests/visual/snapshot.js +0 -28
- package/distTs/src/command/tests/visual/suite/create.js +0 -38
- package/distTs/src/command/tests/visual/suite/delete.js +0 -29
- package/distTs/src/command/tests/visual/suite/get.js +0 -43
- package/distTs/src/command/tests/visual/suite/list.js +0 -35
- package/distTs/src/command/tests/visual/suite/open.js +0 -20
- package/distTs/src/command/tests/visual/suite/update.js +0 -47
- package/distTs/src/command/tests/visual/suite.js +0 -30
- package/distTs/src/command/ut/upload.js +0 -86
- package/distTs/src/command/ut.js +0 -12
- package/distTs/src/command/vt/close.js +0 -27
- package/distTs/src/command/vt/compare/validation.js +0 -46
- package/distTs/src/command/vt/compare.js +0 -100
- package/distTs/src/command/vt/exec.js +0 -82
- package/distTs/src/command/vt/installBrowser.js +0 -20
- package/distTs/src/command/vt/shared/validation.js +0 -145
- package/distTs/src/command/vt/storybook.js +0 -138
- package/distTs/src/command/vt.js +0 -20
- package/distTs/src/command/yaml/agents.js +0 -88
- package/distTs/src/command/yaml/init.js +0 -110
- package/distTs/src/main.js +0 -190
- package/distTs/src/types/options.js +0 -2
- package/distTs/src/types/scrape.js +0 -2
- package/distTs/src/types/visualTests.js +0 -2
|
@@ -1,337 +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
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
const texts_1 = require("../../texts");
|
|
8
|
-
const output_1 = __importDefault(require("../../output"));
|
|
9
|
-
const cliError_1 = __importDefault(require("../../cliError"));
|
|
10
|
-
const shared_1 = require("./shared");
|
|
11
|
-
const commandPrDiff = (0, utils_1.newCommand)('diff', texts_1.DESC_COMMAND_PR_DIFF, {
|
|
12
|
-
requiredScopes: [utils_1.REST_API_SCOPE.REPOSITORY_READ],
|
|
13
|
-
examples: texts_1.EXAMPLE_PR_DIFF,
|
|
14
|
-
});
|
|
15
|
-
(0, shared_1.addPrOptions)(commandPrDiff, true);
|
|
16
|
-
commandPrDiff.option('--full', texts_1.OPTION_PR_DIFF_FULL);
|
|
17
|
-
commandPrDiff.option('--from <version>', texts_1.OPTION_PR_DIFF_FROM);
|
|
18
|
-
commandPrDiff.option('--batch <k>', texts_1.OPTION_PR_DIFF_BATCH);
|
|
19
|
-
commandPrDiff.option('--no-mark-viewed', texts_1.OPTION_PR_DIFF_NO_MARK_VIEWED);
|
|
20
|
-
// variadic so N can be left out: `[N] <path...>` is split in the action
|
|
21
|
-
commandPrDiff.argument('[path...]', texts_1.OPTION_PR_DIFF_PATH);
|
|
22
|
-
commandPrDiff.usage('[options] [N] <path...>');
|
|
23
|
-
// diffs fetched at once; a batch holds dozens of files
|
|
24
|
-
const CONCURRENCY = 8;
|
|
25
|
-
// the API takes up to 500 paths per viewed request
|
|
26
|
-
const VIEWED_CHUNK = 500;
|
|
27
|
-
const mapLimit = async (items, limit, fn) => {
|
|
28
|
-
const results = new Array(items.length);
|
|
29
|
-
let next = 0;
|
|
30
|
-
const worker = async () => {
|
|
31
|
-
while (next < items.length) {
|
|
32
|
-
const index = next;
|
|
33
|
-
next += 1;
|
|
34
|
-
results[index] = await fn(items[index]);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
38
|
-
return results;
|
|
39
|
-
};
|
|
40
|
-
/** `[N] <path...>`, or `[N]` alone with --batch. */
|
|
41
|
-
const parseArgs = (args, batch) => {
|
|
42
|
-
if (!batch) {
|
|
43
|
-
const { number, rest } = (0, shared_1.splitNumberArgs)(args);
|
|
44
|
-
if (rest.length === 0)
|
|
45
|
-
throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_DIFF_ARGS)(args.join(' ')));
|
|
46
|
-
// a lone number is N without a path; after N it is a path (`pr diff 12 2024`)
|
|
47
|
-
if (args.length === 1 && /^\d+$/.test(args[0])) {
|
|
48
|
-
throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_DIFF_LONE_NUMBER)(args[0]));
|
|
49
|
-
}
|
|
50
|
-
return { number, paths: rest };
|
|
51
|
-
}
|
|
52
|
-
if (args.length === 0)
|
|
53
|
-
return { number: undefined, paths: [] };
|
|
54
|
-
if (args.length === 1 && /^\d+$/.test(args[0]))
|
|
55
|
-
return { number: args[0], paths: [] };
|
|
56
|
-
throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_DIFF_ARGS)(args.join(' ')));
|
|
57
|
-
};
|
|
58
|
-
/** The paths of batch k of the MUST_REVIEW list, cut as pr get and pr file ls --batch cut it. */
|
|
59
|
-
const batchPaths = async (scope, number, version, batch) => {
|
|
60
|
-
const mustReview = await (0, shared_1.fetchMustReview)(scope, number, version);
|
|
61
|
-
const files = mustReview.files || [];
|
|
62
|
-
const batches = (0, shared_1.buildBatches)(files);
|
|
63
|
-
if (batches.length === 0) {
|
|
64
|
-
const tokens = files.reduce((sum, f) => sum + (0, shared_1.tokensOf)(f), 0);
|
|
65
|
-
throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_NO_BATCHES)(files.length, tokens));
|
|
66
|
-
}
|
|
67
|
-
if (batch > batches.length) {
|
|
68
|
-
throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_BATCH_RANGE)(batch, batches.length));
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
version: mustReview.version ?? version,
|
|
72
|
-
paths: batches[batch - 1].files.map((f) => f.file_name),
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
/** A thread under its line: the same header as in pr get, then the whole conversation. */
|
|
76
|
-
const printThread = (thread, origin, indent = ' ') => {
|
|
77
|
-
const bar = output_1.default.getYellowColor(`${indent}┃`);
|
|
78
|
-
const extra = origin ? `, ${(0, texts_1.TXT_PR_MOVED_FROM)((0, shared_1.positionText)(origin))}` : '';
|
|
79
|
-
output_1.default.normal(`${bar} ${(0, shared_1.threadHeader)(thread, extra)}`);
|
|
80
|
-
const message = (who, date, text) => {
|
|
81
|
-
const lines = (text || '').split('\n');
|
|
82
|
-
output_1.default.normal(`${bar} ${output_1.default.getMutedColor(`${(0, shared_1.memberName)(who)} ${(0, shared_1.formatDate)(date)}:`)} ${lines[0]}`);
|
|
83
|
-
lines.slice(1).forEach((line) => output_1.default.normal(`${bar} ${line}`));
|
|
84
|
-
};
|
|
85
|
-
message(thread.author, thread.create_date, thread.comment);
|
|
86
|
-
for (const reply of thread.comments || [])
|
|
87
|
-
message(reply.user, reply.create_date, reply.comment);
|
|
88
|
-
const duplicates = thread.duplicates || [];
|
|
89
|
-
if (duplicates.length > 0) {
|
|
90
|
-
output_1.default.normal(`${bar} ${output_1.default.getMutedColor((0, texts_1.TXT_PR_SAME_CHANGE)(duplicates.map((d) => `${d.path}:${d.new_start}`).join(', ')))}`);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const hunkHasThread = (hunk, threads) => hunk.lines.some((line) => threads.some((t) => (t.position?.new_line && t.position.new_line === line.newLine) ||
|
|
94
|
-
(t.position?.old_line && t.position.old_line === line.oldLine)));
|
|
95
|
-
/** A file's diff: header, hunks with the threads under their lines, removed hunks, then threads not placed and threads whose code is gone. */
|
|
96
|
-
const printFile = (diff, file, threadList, gone, origins, pr, options) => {
|
|
97
|
-
const shown = diff.version;
|
|
98
|
-
const name = diff.file_name;
|
|
99
|
-
// header: the file with its status and priority, then one fact per line
|
|
100
|
-
const title = [
|
|
101
|
-
output_1.default.getLabelColor(diff.previous_file_name ? `${name} ← ${diff.previous_file_name}` : name),
|
|
102
|
-
(0, shared_1.fileStatusText)(diff.status),
|
|
103
|
-
(0, shared_1.filePriorityText)(file?.triage?.review_priority),
|
|
104
|
-
].filter(Boolean);
|
|
105
|
-
output_1.default.normal(title.join(' '));
|
|
106
|
-
const versionText = `v${shown}${pr?.version === shown ? ` ${texts_1.TXT_PR_DIFF_CURRENT}` : ''}`;
|
|
107
|
-
// a full diff without --full collapses cosmetic and repeated hunks (not those with a thread)
|
|
108
|
-
const hunks = (0, shared_1.parsePatch)(diff.patch);
|
|
109
|
-
const collapse = diff.mode === utils_1.PR_DIFF_MODE.FULL && !options.full;
|
|
110
|
-
const collapsedKind = (hunk, index) => {
|
|
111
|
-
const meta = diff.hunks?.[index];
|
|
112
|
-
if (!collapse || !meta || hunkHasThread(hunk, threadList))
|
|
113
|
-
return null;
|
|
114
|
-
if (meta.type === utils_1.PR_HUNK_TYPE.COSMETIC)
|
|
115
|
-
return 'cosmetic';
|
|
116
|
-
if (meta.duplicate_of)
|
|
117
|
-
return 'duplicate';
|
|
118
|
-
return null;
|
|
119
|
-
};
|
|
120
|
-
const collapsedCount = hunks.filter((hunk, index) => collapsedKind(hunk, index)).length;
|
|
121
|
-
const mode = diff.mode === utils_1.PR_DIFF_MODE.INTERDIFF
|
|
122
|
-
? (0, texts_1.TXT_PR_DIFF_MODE_INTERDIFF)(diff.from_version, !options.fromGiven)
|
|
123
|
-
: options.full
|
|
124
|
-
? (0, texts_1.TXT_PR_DIFF_MODE_FULL)(pr?.base)
|
|
125
|
-
: (0, texts_1.TXT_PR_DIFF_MODE_DEFAULT)(pr?.base, collapsedCount);
|
|
126
|
-
output_1.default.normal(` ${(0, shared_1.field)(texts_1.TXT_PR_DIFF_FIELD_VERSION, versionText)} · ${mode}`);
|
|
127
|
-
if (file?.analysis) {
|
|
128
|
-
output_1.default.normal(` ${output_1.default.getMutedColor(texts_1.TXT_PR_DIFF_FIELD_TYPE)} ${(0, shared_1.changeTypeText)(file.analysis.change_type)} · ${output_1.default.getLabelColor(`${(0, shared_1.fileSizeText)(file)} tokens`)}`);
|
|
129
|
-
}
|
|
130
|
-
const symbols = file?.analysis?.changed_symbols || [];
|
|
131
|
-
if (symbols.length > 0) {
|
|
132
|
-
output_1.default.normal(` ${output_1.default.getMutedColor(texts_1.TXT_PR_DIFF_FIELD_SYMBOLS)}`);
|
|
133
|
-
(0, shared_1.symbolLines)(symbols).forEach((line) => output_1.default.normal(` ${line}`));
|
|
134
|
-
}
|
|
135
|
-
output_1.default.newline();
|
|
136
|
-
if (diff.binary)
|
|
137
|
-
output_1.default.muted(texts_1.TXT_PR_DIFF_BINARY);
|
|
138
|
-
if (diff.truncated)
|
|
139
|
-
output_1.default.warning(texts_1.TXT_PR_DIFF_TRUNCATED);
|
|
140
|
-
if (!diff.binary && !diff.truncated && hunks.length === 0) {
|
|
141
|
-
output_1.default.muted(texts_1.TXT_PR_DIFF_EMPTY);
|
|
142
|
-
}
|
|
143
|
-
const width = (0, shared_1.patchColumnWidth)(hunks);
|
|
144
|
-
// where the +/- sign and the code start, for collapsed hunks and threads
|
|
145
|
-
const indent = ' '.repeat(width * 2 + 2);
|
|
146
|
-
const placed = new Set();
|
|
147
|
-
hunks.forEach((hunk, index) => {
|
|
148
|
-
const meta = diff.hunks?.[index];
|
|
149
|
-
output_1.default.normal((0, shared_1.hunkHeaderText)(hunk.header, width));
|
|
150
|
-
const kind = collapsedKind(hunk, index);
|
|
151
|
-
if (kind === 'cosmetic') {
|
|
152
|
-
output_1.default.muted(`${indent}${(0, texts_1.TXT_PR_DIFF_COSMETIC)(hunk.lines.length)}`);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (kind === 'duplicate') {
|
|
156
|
-
output_1.default.muted(`${indent}${(0, texts_1.TXT_PR_DIFF_DUPLICATE)(`${meta.duplicate_of.path}:${meta.duplicate_of.new_start}`, meta.duplicate_count)}`);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
for (const line of hunk.lines) {
|
|
160
|
-
output_1.default.normal(line.type === 'meta' ? line.text : (0, shared_1.formatPatchLine)(line, width));
|
|
161
|
-
// a thread on a range sits under its last line
|
|
162
|
-
for (const thread of threadList) {
|
|
163
|
-
if (placed.has(thread.id))
|
|
164
|
-
continue;
|
|
165
|
-
const p = thread.position || {};
|
|
166
|
-
const onNew = p.new_line && line.newLine === p.new_line && line.type !== 'del';
|
|
167
|
-
const onOld = p.old_line && line.oldLine === p.old_line && line.type !== 'add';
|
|
168
|
-
if (onNew || onOld) {
|
|
169
|
-
printThread(thread, origins.get(thread.id), indent);
|
|
170
|
-
placed.add(thread.id);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
const removed = diff.removed_hunks || [];
|
|
176
|
-
if (removed.length > 0) {
|
|
177
|
-
output_1.default.newline();
|
|
178
|
-
output_1.default.label((0, texts_1.TXT_PR_DIFF_REMOVED)(diff.from_version, shown));
|
|
179
|
-
for (const hunk of removed) {
|
|
180
|
-
// the text of a removed hunk, with its header when the API sends none
|
|
181
|
-
const text = hunk.patch || '';
|
|
182
|
-
const patch = text.startsWith('@@')
|
|
183
|
-
? text
|
|
184
|
-
: `@@ -${hunk.old_start} +${hunk.new_start} @@\n${text}`;
|
|
185
|
-
for (const parsed of (0, shared_1.parsePatch)(patch)) {
|
|
186
|
-
output_1.default.normal((0, shared_1.hunkHeaderText)(parsed.header, width));
|
|
187
|
-
parsed.lines.forEach((line) => output_1.default.normal((0, shared_1.formatPatchLine)(line, width)));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
const unplaced = threadList.filter((t) => !placed.has(t.id));
|
|
192
|
-
if (unplaced.length > 0) {
|
|
193
|
-
output_1.default.newline();
|
|
194
|
-
output_1.default.label(texts_1.TXT_PR_SECTION_THREADS);
|
|
195
|
-
unplaced.forEach((t) => {
|
|
196
|
-
output_1.default.muted(` ${(0, shared_1.positionText)(t.position)}`);
|
|
197
|
-
printThread(t, origins.get(t.id));
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
if (gone.length > 0) {
|
|
201
|
-
output_1.default.newline();
|
|
202
|
-
output_1.default.label(texts_1.TXT_PR_DIFF_GONE);
|
|
203
|
-
gone.forEach(({ thread, origin }) => {
|
|
204
|
-
output_1.default.muted(` ${(0, texts_1.TXT_PR_OPENED_AT)((0, shared_1.positionText)(origin), thread.created_version)}`);
|
|
205
|
-
printThread(thread, null);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
commandPrDiff.action(async (args, options) => {
|
|
210
|
-
let batch;
|
|
211
|
-
if (options.batch !== undefined) {
|
|
212
|
-
if (!/^[1-9]\d*$/.test(options.batch))
|
|
213
|
-
throw new cliError_1.default('usage_error', texts_1.ERR_PR_BATCH);
|
|
214
|
-
batch = Number(options.batch);
|
|
215
|
-
}
|
|
216
|
-
const { number: n, paths: given } = parseArgs(args, batch !== undefined);
|
|
217
|
-
let version = (0, shared_1.parseRev)(options.rev);
|
|
218
|
-
const fromVersion = (0, shared_1.parseRev)(options.from);
|
|
219
|
-
const json = options.format === 'json';
|
|
220
|
-
const scope = (0, shared_1.prScope)(options);
|
|
221
|
-
const number = await (0, shared_1.resolveNumber)(scope, n);
|
|
222
|
-
const { client, workspace, project } = scope;
|
|
223
|
-
let paths = [...new Set(given)];
|
|
224
|
-
let pr = null;
|
|
225
|
-
if (batch !== undefined) {
|
|
226
|
-
const result = await batchPaths(scope, number, version, batch);
|
|
227
|
-
paths = result.paths;
|
|
228
|
-
version = result.version;
|
|
229
|
-
}
|
|
230
|
-
if (version === undefined) {
|
|
231
|
-
// one version for every file, the threads and the viewed marks: a push
|
|
232
|
-
// between the requests would otherwise mix two versions in one output
|
|
233
|
-
pr = await client.getPullRequest(workspace, project, number);
|
|
234
|
-
version = pr.version;
|
|
235
|
-
}
|
|
236
|
-
// a file that fails (gone, too big, a server error) does not take the others down with it
|
|
237
|
-
const results = await mapLimit(paths, CONCURRENCY, async (path) => {
|
|
238
|
-
try {
|
|
239
|
-
const diff = await client.getPullRequestDiff(workspace, project, number, {
|
|
240
|
-
path,
|
|
241
|
-
version,
|
|
242
|
-
from_version: fromVersion,
|
|
243
|
-
full: options.full ? true : undefined,
|
|
244
|
-
});
|
|
245
|
-
return { path, diff };
|
|
246
|
-
}
|
|
247
|
-
catch (error) {
|
|
248
|
-
return { path, error };
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
const failed = results.filter((r) => r.error !== undefined);
|
|
252
|
-
// one path asked for: its error as it is, as before
|
|
253
|
-
if (results.length === 1 && failed.length === 1 && batch === undefined)
|
|
254
|
-
throw failed[0].error;
|
|
255
|
-
const shown = version;
|
|
256
|
-
const ok = results.filter((r) => r.diff);
|
|
257
|
-
const names = ok.map((r) => r.diff.file_name || r.path);
|
|
258
|
-
// in a pipe (an agent) showing a file is reading it: mark it viewed in the version shown, unless asked not to
|
|
259
|
-
const markViewed = !output_1.default.isStdOutTTY() && options.markViewed !== false && names.length > 0;
|
|
260
|
-
let viewedError = false;
|
|
261
|
-
if (markViewed) {
|
|
262
|
-
try {
|
|
263
|
-
for (let i = 0; i < names.length; i += VIEWED_CHUNK) {
|
|
264
|
-
await client.markPullRequestFilesViewed(workspace, project, number, {
|
|
265
|
-
paths: names.slice(i, i + VIEWED_CHUNK),
|
|
266
|
-
viewed: true,
|
|
267
|
-
version: shown,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
catch {
|
|
272
|
-
viewedError = true;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (json) {
|
|
276
|
-
// one path: the API object as it is; several or a batch: an array, a failed file as { file_name, error }
|
|
277
|
-
if (results.length === 1 && batch === undefined)
|
|
278
|
-
output_1.default.json(results[0].diff);
|
|
279
|
-
else
|
|
280
|
-
output_1.default.json(results.map((r) => r.diff ?? { file_name: r.path, error: cliError_1.default.details(r.error) }));
|
|
281
|
-
// the failures are in the array: stdout stays one JSON document, the exit code says some failed
|
|
282
|
-
if (failed.length > 0)
|
|
283
|
-
output_1.default.exitCode(output_1.default.errorExitCode);
|
|
284
|
-
output_1.default.exitNormal();
|
|
285
|
-
}
|
|
286
|
-
const [current, info, threads] = await Promise.all([
|
|
287
|
-
pr ? Promise.resolve(pr) : client.getPullRequest(workspace, project, number),
|
|
288
|
-
// one file: only its entry; more: the whole version at once
|
|
289
|
-
(0, shared_1.fetchAllFiles)(scope, number, names.length === 1 ? { version: shown, path_prefix: names[0] } : { version: shown }),
|
|
290
|
-
(0, shared_1.fetchAllThreads)(scope, number, { version: shown }),
|
|
291
|
-
]);
|
|
292
|
-
pr = current;
|
|
293
|
-
(0, shared_1.noteVersionBehind)(pr?.version, shown);
|
|
294
|
-
const allThreads = threads.threads || [];
|
|
295
|
-
const fileByName = new Map((info.files || []).map((f) => [f.file_name, f]));
|
|
296
|
-
const onFiles = allThreads.filter((t) => names.includes(t.position?.path));
|
|
297
|
-
const gone = allThreads.filter((t) => t.position?.anchor_state === utils_1.PR_ANCHOR_STATE.GONE);
|
|
298
|
-
const origins = new Map();
|
|
299
|
-
await mapLimit([...onFiles, ...gone], CONCURRENCY, async (thread) => {
|
|
300
|
-
const origin = await (0, shared_1.threadOrigin)(scope, number, thread);
|
|
301
|
-
if (origin)
|
|
302
|
-
origins.set(thread.id, origin);
|
|
303
|
-
});
|
|
304
|
-
results.forEach((result, index) => {
|
|
305
|
-
if (index > 0)
|
|
306
|
-
output_1.default.newline();
|
|
307
|
-
if (!result.diff) {
|
|
308
|
-
// in its place in the list, so the reader sees which file is missing
|
|
309
|
-
output_1.default.normal(`${output_1.default.getLabelColor(result.path)} ${output_1.default.getRedColor(cliError_1.default.details(result.error).message)}`);
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
const diff = result.diff;
|
|
313
|
-
const name = diff.file_name || result.path;
|
|
314
|
-
const sides = [name, diff.previous_file_name].filter(Boolean);
|
|
315
|
-
printFile(diff, fileByName.get(name), onFiles.filter((t) => t.position?.path === name), gone
|
|
316
|
-
.filter((t) => sides.includes(origins.get(t.id)?.path))
|
|
317
|
-
.map((t) => ({ thread: t, origin: origins.get(t.id) })), origins, pr, { full: options.full, fromGiven: fromVersion !== undefined });
|
|
318
|
-
});
|
|
319
|
-
output_1.default.newline();
|
|
320
|
-
if (markViewed) {
|
|
321
|
-
if (viewedError)
|
|
322
|
-
output_1.default.noteWarning(texts_1.TXT_PR_DIFF_VIEW_FAILED);
|
|
323
|
-
else
|
|
324
|
-
output_1.default.muted(names.length === 1 ? (0, texts_1.TXT_PR_DIFF_VIEWED)(shown) : (0, texts_1.TXT_PR_DIFF_VIEWED_MANY)(names.length, shown));
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
const unviewed = names.filter((name) => !fileByName.get(name)?.viewed);
|
|
328
|
-
if (unviewed.length > 0) {
|
|
329
|
-
output_1.default.muted((0, texts_1.TXT_PR_DIFF_VIEW_HINT)(scope.cmd(`file viewed ${number} ${unviewed.join(' ')} --rev v${shown}`)));
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (failed.length > 0) {
|
|
333
|
-
throw new cliError_1.default('command_failed', (0, texts_1.ERR_PR_DIFF_FAILED)(failed.map((r) => r.path).join(', '), markViewed && !viewedError));
|
|
334
|
-
}
|
|
335
|
-
output_1.default.exitNormal();
|
|
336
|
-
});
|
|
337
|
-
exports.default = commandPrDiff;
|
|
@@ -1,139 +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
|
-
const utils_1 = require("../../../utils");
|
|
7
|
-
const texts_1 = require("../../../texts");
|
|
8
|
-
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
-
const cliError_1 = __importDefault(require("../../../cliError"));
|
|
10
|
-
const shared_1 = require("../shared");
|
|
11
|
-
const summary_1 = require("../summary");
|
|
12
|
-
const commandPrFileList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_PR_FILE_LIST, {
|
|
13
|
-
requiredScopes: [utils_1.REST_API_SCOPE.REPOSITORY_READ],
|
|
14
|
-
examples: texts_1.EXAMPLE_PR_FILE_LIST,
|
|
15
|
-
helpText: texts_1.HELP_PR_FILE_LIST,
|
|
16
|
-
});
|
|
17
|
-
commandPrFileList.alias('ls');
|
|
18
|
-
(0, shared_1.addPrOptions)(commandPrFileList, true);
|
|
19
|
-
commandPrFileList.option('--since-review', texts_1.OPTION_PR_FILES_SINCE_REVIEW);
|
|
20
|
-
commandPrFileList.option('--must-review', texts_1.OPTION_PR_FILES_MUST_REVIEW);
|
|
21
|
-
commandPrFileList.option('--unclear', texts_1.OPTION_PR_FILES_UNCLEAR);
|
|
22
|
-
commandPrFileList.option('--batch <k>', texts_1.OPTION_PR_FILES_BATCH);
|
|
23
|
-
commandPrFileList.option('--from <version>', texts_1.OPTION_PR_FILES_FROM);
|
|
24
|
-
commandPrFileList.argument('[N]', texts_1.OPTION_PR_NUMBER);
|
|
25
|
-
commandPrFileList.action(async (n, options) => {
|
|
26
|
-
const filters = [
|
|
27
|
-
options.sinceReview,
|
|
28
|
-
options.mustReview,
|
|
29
|
-
options.unclear,
|
|
30
|
-
options.batch !== undefined,
|
|
31
|
-
].filter(Boolean);
|
|
32
|
-
if (filters.length > 1)
|
|
33
|
-
throw new cliError_1.default('usage_error', texts_1.ERR_PR_FILE_FILTERS);
|
|
34
|
-
if (options.from !== undefined && options.batch !== undefined) {
|
|
35
|
-
throw new cliError_1.default('usage_error', texts_1.ERR_PR_FILE_FROM_BATCH);
|
|
36
|
-
}
|
|
37
|
-
let batch;
|
|
38
|
-
if (options.batch !== undefined) {
|
|
39
|
-
if (!/^[1-9]\d*$/.test(options.batch))
|
|
40
|
-
throw new cliError_1.default('usage_error', texts_1.ERR_PR_BATCH);
|
|
41
|
-
batch = Number(options.batch);
|
|
42
|
-
}
|
|
43
|
-
const version = (0, shared_1.parseRev)(options.rev);
|
|
44
|
-
// narrows any of the lists to the files whose change differs from that version
|
|
45
|
-
const fromVersion = (0, shared_1.parseRev)(options.from);
|
|
46
|
-
const scope = (0, shared_1.prScope)(options);
|
|
47
|
-
const number = await (0, shared_1.resolveNumber)(scope, n);
|
|
48
|
-
let result;
|
|
49
|
-
let files;
|
|
50
|
-
if (options.mustReview || batch !== undefined) {
|
|
51
|
-
result = options.mustReview && fromVersion !== undefined
|
|
52
|
-
? await (0, shared_1.fetchAllFiles)(scope, number, {
|
|
53
|
-
version,
|
|
54
|
-
from_version: fromVersion,
|
|
55
|
-
review_priority: utils_1.PR_REVIEW_PRIORITY.MUST_REVIEW,
|
|
56
|
-
sort: utils_1.PR_FILES_SORT.REVIEW_ORDER,
|
|
57
|
-
})
|
|
58
|
-
: await (0, shared_1.fetchMustReview)(scope, number, version);
|
|
59
|
-
files = result.files || [];
|
|
60
|
-
if (batch !== undefined) {
|
|
61
|
-
const batches = (0, shared_1.buildBatches)(files);
|
|
62
|
-
if (batches.length === 0) {
|
|
63
|
-
const tokens = files.reduce((sum, f) => sum + (0, shared_1.tokensOf)(f), 0);
|
|
64
|
-
throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_NO_BATCHES)(files.length, tokens));
|
|
65
|
-
}
|
|
66
|
-
if (batch > batches.length) {
|
|
67
|
-
throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_BATCH_RANGE)(batch, batches.length));
|
|
68
|
-
}
|
|
69
|
-
files = batches[batch - 1].files;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else if (options.unclear) {
|
|
73
|
-
result = await (0, shared_1.fetchAllFiles)(scope, number, {
|
|
74
|
-
version,
|
|
75
|
-
from_version: fromVersion,
|
|
76
|
-
review_priority: utils_1.PR_REVIEW_PRIORITY.UNCLEAR,
|
|
77
|
-
sort: utils_1.PR_FILES_SORT.REVIEW_ORDER,
|
|
78
|
-
});
|
|
79
|
-
files = result.files || [];
|
|
80
|
-
}
|
|
81
|
-
else if (options.sinceReview) {
|
|
82
|
-
result = await (0, shared_1.fetchAllFiles)(scope, number, { version, from_version: fromVersion, since_review: true });
|
|
83
|
-
files = result.files || [];
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
result = await (0, shared_1.fetchAllFiles)(scope, number, { version, from_version: fromVersion });
|
|
87
|
-
files = result.files || [];
|
|
88
|
-
}
|
|
89
|
-
if (options.format === 'json') {
|
|
90
|
-
output_1.default.json(files);
|
|
91
|
-
output_1.default.exitNormal();
|
|
92
|
-
}
|
|
93
|
-
if (version) {
|
|
94
|
-
const pr = await scope.client.getPullRequest(scope.workspace, scope.project, number);
|
|
95
|
-
(0, shared_1.noteVersionBehind)(pr?.version, result.version);
|
|
96
|
-
}
|
|
97
|
-
if (files.length === 0)
|
|
98
|
-
output_1.default.exitNormal(texts_1.TXT_PR_FILES_NOT_FOUND);
|
|
99
|
-
// the reason a file is on the since-review list needs the threads not CLOSED
|
|
100
|
-
let byPath = new Map();
|
|
101
|
-
if (options.sinceReview) {
|
|
102
|
-
const threads = await (0, shared_1.fetchAllThreads)(scope, number, { version: result.version });
|
|
103
|
-
byPath = (0, summary_1.threadsByPath)(threads.threads || []);
|
|
104
|
-
}
|
|
105
|
-
const data = [
|
|
106
|
-
['STATUS', '+/-', 'VIEWED', 'CHANGED', 'PRIORITY', 'TYPE', 'SIZE/TOKENS', 'PATH', 'SYMBOLS'],
|
|
107
|
-
];
|
|
108
|
-
const sorted = (0, shared_1.sortFilesForReading)(files);
|
|
109
|
-
for (const file of sorted) {
|
|
110
|
-
const symbols = file.analysis?.changed_symbols || [];
|
|
111
|
-
const flags = [];
|
|
112
|
-
if (file.analysis?.has_only_duplicated_hunks)
|
|
113
|
-
flags.push('only repeated changes');
|
|
114
|
-
if (options.sinceReview) {
|
|
115
|
-
const reason = (0, summary_1.sinceReviewReason)(file, byPath);
|
|
116
|
-
if (reason)
|
|
117
|
-
flags.push(reason);
|
|
118
|
-
}
|
|
119
|
-
const path = file.previous_file_name
|
|
120
|
-
? `${file.file_name} ← ${file.previous_file_name}`
|
|
121
|
-
: file.file_name;
|
|
122
|
-
data.push([
|
|
123
|
-
(0, shared_1.fileStatusText)(file.status),
|
|
124
|
-
`+${file.additions ?? 0}/-${file.deletions ?? 0}`,
|
|
125
|
-
file.viewed ? output_1.default.getGreenColor('yes') : 'no',
|
|
126
|
-
file.changed_since_review === null || file.changed_since_review === undefined
|
|
127
|
-
? '-'
|
|
128
|
-
: file.changed_since_review ? 'yes' : 'no',
|
|
129
|
-
(0, shared_1.filePriorityText)(file.triage?.review_priority, true),
|
|
130
|
-
(0, shared_1.changeTypeText)(file.analysis?.change_type),
|
|
131
|
-
(0, shared_1.fileSizeText)(file),
|
|
132
|
-
flags.length ? `${path} (${flags.join(', ')})` : path,
|
|
133
|
-
symbols.slice(0, 3).map((s) => s.name).join(', ') + (symbols.length > 3 ? ` +${symbols.length - 3}` : ''),
|
|
134
|
-
]);
|
|
135
|
-
}
|
|
136
|
-
output_1.default.tableOrRows(data, true);
|
|
137
|
-
output_1.default.exitNormal();
|
|
138
|
-
});
|
|
139
|
-
exports.default = commandPrFileList;
|
|
@@ -1,45 +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.commandPrFileUnviewed = exports.commandPrFileViewed = void 0;
|
|
7
|
-
const utils_1 = require("../../../utils");
|
|
8
|
-
const texts_1 = require("../../../texts");
|
|
9
|
-
const output_1 = __importDefault(require("../../../output"));
|
|
10
|
-
const cliError_1 = __importDefault(require("../../../cliError"));
|
|
11
|
-
const shared_1 = require("../shared");
|
|
12
|
-
// the API takes up to 500 paths per request
|
|
13
|
-
const CHUNK = 500;
|
|
14
|
-
const markCommand = (viewed) => {
|
|
15
|
-
const command = (0, utils_1.newCommand)(viewed ? 'viewed' : 'unviewed', viewed ? texts_1.DESC_COMMAND_PR_FILE_VIEWED : texts_1.DESC_COMMAND_PR_FILE_UNVIEWED, {
|
|
16
|
-
requiredScopes: [utils_1.REST_API_SCOPE.REPOSITORY_WRITE],
|
|
17
|
-
examples: viewed ? texts_1.EXAMPLE_PR_FILE_VIEWED : texts_1.EXAMPLE_PR_FILE_UNVIEWED,
|
|
18
|
-
});
|
|
19
|
-
(0, shared_1.addPrOptions)(command, true);
|
|
20
|
-
// `[N] <path...>`: N is split off in the action
|
|
21
|
-
command.argument('<paths...>', texts_1.OPTION_PR_FILE_PATHS);
|
|
22
|
-
command.usage('[options] [N] <path...>');
|
|
23
|
-
command.action(async (args, options) => {
|
|
24
|
-
const { number: n, rest: paths } = (0, shared_1.splitNumberArgs)(args);
|
|
25
|
-
if (paths.length === 0) {
|
|
26
|
-
throw new cliError_1.default('usage_error', (0, texts_1.ERR_PR_ARGS)('[N] <path...>', args.join(' ')));
|
|
27
|
-
}
|
|
28
|
-
const version = (0, shared_1.parseRev)(options.rev);
|
|
29
|
-
const scope = (0, shared_1.prScope)(options);
|
|
30
|
-
const number = await (0, shared_1.resolveNumber)(scope, n);
|
|
31
|
-
const files = [];
|
|
32
|
-
let shown = version;
|
|
33
|
-
for (let i = 0; i < paths.length; i += CHUNK) {
|
|
34
|
-
const result = await scope.client.markPullRequestFilesViewed(scope.workspace, scope.project, number, { paths: paths.slice(i, i + CHUNK), viewed, version });
|
|
35
|
-
shown = result?.version ?? shown;
|
|
36
|
-
files.push(...(result?.files || []));
|
|
37
|
-
}
|
|
38
|
-
output_1.default.exitResult(options.format === 'json', { version: shown, files }, viewed
|
|
39
|
-
? (0, texts_1.TXT_PR_FILES_VIEWED)(paths.length, shown)
|
|
40
|
-
: (0, texts_1.TXT_PR_FILES_UNVIEWED)(paths.length, shown));
|
|
41
|
-
});
|
|
42
|
-
return command;
|
|
43
|
-
};
|
|
44
|
-
exports.commandPrFileViewed = markCommand(true);
|
|
45
|
-
exports.commandPrFileUnviewed = markCommand(false);
|
|
@@ -1,16 +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
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
const texts_1 = require("../../texts");
|
|
8
|
-
const list_1 = __importDefault(require("./file/list"));
|
|
9
|
-
const mark_1 = require("./file/mark");
|
|
10
|
-
const commandPrFile = (0, utils_1.newCommand)('file', texts_1.DESC_COMMAND_PR_FILE, {
|
|
11
|
-
examples: texts_1.EXAMPLE_PR_FILE,
|
|
12
|
-
});
|
|
13
|
-
commandPrFile.addCommand(list_1.default);
|
|
14
|
-
commandPrFile.addCommand(mark_1.commandPrFileViewed);
|
|
15
|
-
commandPrFile.addCommand(mark_1.commandPrFileUnviewed);
|
|
16
|
-
exports.default = commandPrFile;
|
|
@@ -1,29 +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
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
const texts_1 = require("../../texts");
|
|
8
|
-
const output_1 = __importDefault(require("../../output"));
|
|
9
|
-
const shared_1 = require("./shared");
|
|
10
|
-
const summary_1 = require("./summary");
|
|
11
|
-
const commandPrGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_PR_GET, {
|
|
12
|
-
requiredScopes: [utils_1.REST_API_SCOPE.REPOSITORY_READ],
|
|
13
|
-
examples: texts_1.EXAMPLE_PR_GET,
|
|
14
|
-
});
|
|
15
|
-
(0, shared_1.addPrOptions)(commandPrGet, true);
|
|
16
|
-
commandPrGet.option('--since-review', texts_1.OPTION_PR_SINCE_REVIEW_GET);
|
|
17
|
-
commandPrGet.argument('[N]', texts_1.OPTION_PR_NUMBER);
|
|
18
|
-
commandPrGet.action(async (n, options) => {
|
|
19
|
-
const version = (0, shared_1.parseRev)(options.rev);
|
|
20
|
-
const scope = (0, shared_1.prScope)(options);
|
|
21
|
-
const number = await (0, shared_1.resolveNumber)(scope, n);
|
|
22
|
-
await (0, summary_1.printSummary)(scope, number, {
|
|
23
|
-
rev: version,
|
|
24
|
-
sinceReview: !!options.sinceReview,
|
|
25
|
-
json: options.format === 'json',
|
|
26
|
-
});
|
|
27
|
-
output_1.default.exitNormal();
|
|
28
|
-
});
|
|
29
|
-
exports.default = commandPrGet;
|
|
@@ -1,79 +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
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
const texts_1 = require("../../texts");
|
|
8
|
-
const output_1 = __importDefault(require("../../output"));
|
|
9
|
-
const input_1 = __importDefault(require("../../input"));
|
|
10
|
-
const cliError_1 = __importDefault(require("../../cliError"));
|
|
11
|
-
const shared_1 = require("./shared");
|
|
12
|
-
const commandPrList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_PR_LIST, {
|
|
13
|
-
requiredScopes: [utils_1.REST_API_SCOPE.REPOSITORY_READ],
|
|
14
|
-
examples: texts_1.EXAMPLE_PR_LIST,
|
|
15
|
-
});
|
|
16
|
-
commandPrList.alias('ls');
|
|
17
|
-
(0, shared_1.addPrOptions)(commandPrList);
|
|
18
|
-
commandPrList.option('--state <state>', texts_1.OPTION_PR_STATE);
|
|
19
|
-
commandPrList.option('--author <login|me>', texts_1.OPTION_PR_AUTHOR);
|
|
20
|
-
commandPrList.option('--reviewer <login|me>', texts_1.OPTION_PR_REVIEWER);
|
|
21
|
-
commandPrList.option('--head <branch>', texts_1.OPTION_PR_HEAD_FILTER);
|
|
22
|
-
commandPrList.option('--base <branch>', texts_1.OPTION_PR_BASE_FILTER);
|
|
23
|
-
commandPrList.option('--page <number>', texts_1.OPTION_REST_API_PAGE);
|
|
24
|
-
commandPrList.option('--per-page <number>', texts_1.OPTION_PR_PER_PAGE);
|
|
25
|
-
// `me` is the invoker; the API takes a username or an e-mail
|
|
26
|
-
const login = async (scope, value) => {
|
|
27
|
-
if (value !== 'me')
|
|
28
|
-
return value;
|
|
29
|
-
const user = await scope.client.getInvoker();
|
|
30
|
-
return user?.email;
|
|
31
|
-
};
|
|
32
|
-
commandPrList.action(async (options) => {
|
|
33
|
-
let state;
|
|
34
|
-
if (options.state) {
|
|
35
|
-
state = String(options.state).toUpperCase();
|
|
36
|
-
if (!Object.values(utils_1.PR_STATE).includes(state)) {
|
|
37
|
-
throw new cliError_1.default('usage_error', texts_1.ERR_PR_STATE);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const page = options.page ? input_1.default.restApiPage(options.page) : undefined;
|
|
41
|
-
const perPage = options.perPage
|
|
42
|
-
? input_1.default.restApiPerPage(options.perPage)
|
|
43
|
-
: undefined;
|
|
44
|
-
const scope = (0, shared_1.prScope)(options);
|
|
45
|
-
const result = await scope.client.getPullRequests(scope.workspace, scope.project, {
|
|
46
|
-
state,
|
|
47
|
-
author: await login(scope, options.author),
|
|
48
|
-
reviewer: await login(scope, options.reviewer),
|
|
49
|
-
head: options.head,
|
|
50
|
-
base: options.base,
|
|
51
|
-
page,
|
|
52
|
-
per_page: perPage,
|
|
53
|
-
});
|
|
54
|
-
const prs = result?.pull_requests || [];
|
|
55
|
-
if (options.format === 'json') {
|
|
56
|
-
output_1.default.json(prs);
|
|
57
|
-
output_1.default.exitNormal();
|
|
58
|
-
}
|
|
59
|
-
if (prs.length === 0)
|
|
60
|
-
output_1.default.exitNormal(texts_1.TXT_PR_NOT_FOUND);
|
|
61
|
-
const data = [
|
|
62
|
-
['#', 'TITLE', 'STATE', 'MERGEABLE', 'BRANCHES', 'AUTHOR', 'VERSION', 'UPDATED'],
|
|
63
|
-
];
|
|
64
|
-
for (const pr of prs) {
|
|
65
|
-
data.push([
|
|
66
|
-
String(pr.number ?? '-'),
|
|
67
|
-
pr.title || '-',
|
|
68
|
-
(0, shared_1.prStateText)(pr),
|
|
69
|
-
(0, shared_1.mergeableText)(pr.mergeable),
|
|
70
|
-
pr.head ? `${pr.base} ← ${pr.head}` : '-',
|
|
71
|
-
pr.author ? (0, shared_1.memberName)(pr.author) : '-',
|
|
72
|
-
pr.version ? `v${pr.version}` : '-',
|
|
73
|
-
(0, shared_1.formatDate)(pr.last_update_date || pr.create_date),
|
|
74
|
-
]);
|
|
75
|
-
}
|
|
76
|
-
output_1.default.tableOrRows(data, true);
|
|
77
|
-
output_1.default.exitNormal();
|
|
78
|
-
});
|
|
79
|
-
exports.default = commandPrList;
|