bdy 1.25.39-dev → 1.25.39-dev-pr
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 +2 -1
- package/distTs/src/api/client.js +191 -1
- package/distTs/src/autocomplete.js +90 -0
- package/distTs/src/cliError.js +5 -0
- package/distTs/src/cliIndex.js +3 -0
- package/distTs/src/command/artifact/downloadDir.js +110 -0
- package/distTs/src/command/autocomplete/install.js +16 -0
- package/distTs/src/command/autocomplete/uninstall.js +16 -0
- package/distTs/src/command/autocomplete.js +14 -0
- package/distTs/src/command/environment/resolve.js +39 -0
- package/distTs/src/command/login.js +1 -1
- package/distTs/src/command/package/create.js +64 -0
- package/distTs/src/command/package/delete.js +38 -0
- package/distTs/src/command/package/docker/login.js +26 -0
- package/distTs/src/command/package/docker.js +11 -0
- package/distTs/src/command/package/download.js +138 -0
- package/distTs/src/command/package/get.js +36 -0
- package/distTs/src/command/package/list.js +31 -0
- package/distTs/src/command/package/publish.js +241 -0
- package/distTs/src/command/package/version/delete.js +39 -0
- package/distTs/src/command/package/version/get.js +45 -0
- package/distTs/src/command/package/version/list.js +47 -0
- package/distTs/src/command/package/version.js +16 -0
- package/distTs/src/command/package.js +26 -0
- package/distTs/src/command/pipeline/run/apply.js +62 -0
- package/distTs/src/command/pr/comment/add.js +66 -0
- package/distTs/src/command/pr/comment/list.js +167 -0
- package/distTs/src/command/pr/comment/status.js +50 -0
- package/distTs/src/command/pr/comment.js +19 -0
- package/distTs/src/command/pr/create.js +44 -0
- package/distTs/src/command/pr/diff.js +337 -0
- package/distTs/src/command/pr/file/list.js +139 -0
- package/distTs/src/command/pr/file/mark.js +45 -0
- package/distTs/src/command/pr/file.js +16 -0
- package/distTs/src/command/pr/get.js +29 -0
- package/distTs/src/command/pr/list.js +79 -0
- package/distTs/src/command/pr/merge.js +67 -0
- package/distTs/src/command/pr/review/request.js +30 -0
- package/distTs/src/command/pr/review/start.js +29 -0
- package/distTs/src/command/pr/review/verdict.js +81 -0
- package/distTs/src/command/pr/review.js +18 -0
- package/distTs/src/command/pr/shared.js +704 -0
- package/distTs/src/command/pr/state.js +38 -0
- package/distTs/src/command/pr/summary.js +341 -0
- package/distTs/src/command/pr/update.js +56 -0
- package/distTs/src/command/pr/updateBranch.js +22 -0
- package/distTs/src/command/pr/versions.js +42 -0
- package/distTs/src/command/pr.js +39 -0
- package/distTs/src/command/scrape/validation.js +154 -0
- package/distTs/src/command/scrape.js +144 -0
- package/distTs/src/command/suiteLink.js +14 -0
- package/distTs/src/command/tests/visual/result/download.js +31 -0
- package/distTs/src/command/tests/visual/result/get.js +68 -0
- package/distTs/src/command/tests/visual/result/list.js +49 -0
- package/distTs/src/command/tests/visual/result.js +23 -0
- package/distTs/src/command/tests/visual/session/get.js +70 -0
- package/distTs/src/command/tests/visual/session/list.js +69 -0
- package/distTs/src/command/tests/visual/session/open.js +22 -0
- package/distTs/src/command/tests/visual/session/reviewUrl.js +37 -0
- package/distTs/src/command/tests/visual/session/update.js +26 -0
- package/distTs/src/command/tests/visual/shared/context.js +144 -0
- package/distTs/src/command/tests/visual/shared/diffRegions.js +172 -0
- package/distTs/src/command/tests/visual/shared/format.js +21 -0
- package/distTs/src/command/tests/visual/shared/lookup.js +107 -0
- package/distTs/src/command/tests/visual/shared/options.js +90 -0
- package/distTs/src/command/tests/visual/shared/review.js +146 -0
- package/distTs/src/command/tests/visual/shared/reviewUrl.js +62 -0
- package/distTs/src/command/tests/visual/shared/session.js +217 -0
- package/distTs/src/command/tests/visual/snapshot/get.js +46 -0
- package/distTs/src/command/tests/visual/snapshot/list.js +68 -0
- package/distTs/src/command/tests/visual/snapshot/open.js +26 -0
- package/distTs/src/command/tests/visual/snapshot/reviewUrl.js +48 -0
- package/distTs/src/command/tests/visual/snapshot.js +28 -0
- package/distTs/src/command/tests/visual/suite/create.js +38 -0
- package/distTs/src/command/tests/visual/suite/delete.js +29 -0
- package/distTs/src/command/tests/visual/suite/get.js +43 -0
- package/distTs/src/command/tests/visual/suite/list.js +35 -0
- package/distTs/src/command/tests/visual/suite/open.js +20 -0
- package/distTs/src/command/tests/visual/suite/update.js +47 -0
- package/distTs/src/command/tests/visual/suite.js +30 -0
- package/distTs/src/command/ut/upload.js +86 -0
- package/distTs/src/command/ut.js +12 -0
- package/distTs/src/command/vt/close.js +27 -0
- package/distTs/src/command/vt/compare/validation.js +46 -0
- package/distTs/src/command/vt/compare.js +100 -0
- package/distTs/src/command/vt/exec.js +82 -0
- package/distTs/src/command/vt/installBrowser.js +20 -0
- package/distTs/src/command/vt/shared/validation.js +145 -0
- package/distTs/src/command/vt/storybook.js +138 -0
- package/distTs/src/command/vt.js +20 -0
- package/distTs/src/command/yaml/agents.js +88 -0
- package/distTs/src/command/yaml/init.js +110 -0
- package/distTs/src/main.js +190 -0
- package/distTs/src/output/pipeline.js +54 -56
- package/distTs/src/output.js +85 -22
- package/distTs/src/texts.js +509 -1
- package/distTs/src/tunnel/output/interactive/tunnel.js +14 -10
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +3 -1
- package/distTs/src/types/options.js +2 -0
- package/distTs/src/types/scrape.js +2 -0
- package/distTs/src/types/visualTests.js +2 -0
- package/distTs/src/utils.js +142 -6
- package/package.json +2 -1
package/distTs/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bdy",
|
|
3
3
|
"preferGlobal": false,
|
|
4
|
-
"version": "1.25.39-dev",
|
|
4
|
+
"version": "1.25.39-dev-pr",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://buddy.works/docs/cli",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"e2e:target": "vitest run --config e2e/vitest.config.mts e2e/modules/target/",
|
|
33
33
|
"e2e:environment": "vitest run --config e2e/vitest.config.mts e2e/modules/environment/",
|
|
34
34
|
"e2e:yaml": "vitest run --config e2e/vitest.config.mts e2e/modules/yaml/",
|
|
35
|
+
"e2e:pr": "vitest run --config e2e/vitest.config.mts e2e/modules/pr/",
|
|
35
36
|
"unit": "vitest run --config vitest.config.mts"
|
|
36
37
|
},
|
|
37
38
|
"files": [
|
package/distTs/src/api/client.js
CHANGED
|
@@ -254,6 +254,7 @@ class ApiClient {
|
|
|
254
254
|
else {
|
|
255
255
|
let message;
|
|
256
256
|
let nonJsonBody = false;
|
|
257
|
+
let errorBody;
|
|
257
258
|
try {
|
|
258
259
|
const json = await responseBody.json();
|
|
259
260
|
logger_1.default.debug('API CLIENT PARSED RESPONSE:');
|
|
@@ -262,6 +263,7 @@ class ApiClient {
|
|
|
262
263
|
const value = json?.errors?.[0]?.message ?? json?.error_description ?? json?.error;
|
|
263
264
|
if (typeof value === 'string')
|
|
264
265
|
message = value;
|
|
266
|
+
errorBody = json;
|
|
265
267
|
}
|
|
266
268
|
catch (err) {
|
|
267
269
|
nonJsonBody = true;
|
|
@@ -270,7 +272,10 @@ class ApiClient {
|
|
|
270
272
|
// Edge/WAF throttling uses 403 with an HTML body. Preserve the legacy
|
|
271
273
|
// rate-limit classification; JSON 403 responses still report API errors.
|
|
272
274
|
const error = (0, texts_1.ERR_API_DETAILS)(status === 403 && nonJsonBody ? 429 : status, message, path, this.baseUrl, rateLimitReset);
|
|
273
|
-
|
|
275
|
+
const cliError = new cliError_1.default(error.code, error.message, error.hint);
|
|
276
|
+
cliError.status = status;
|
|
277
|
+
cliError.body = errorBody;
|
|
278
|
+
throw cliError;
|
|
274
279
|
}
|
|
275
280
|
}
|
|
276
281
|
// Set by the CLI bootstrap (Input.restApiTokenClient); the transport layer
|
|
@@ -812,6 +817,191 @@ class ApiClient {
|
|
|
812
817
|
parseResponseBody: false,
|
|
813
818
|
});
|
|
814
819
|
}
|
|
820
|
+
// Pull request methods (Buddy-hosted repositories)
|
|
821
|
+
pullsPath(workspace, project, number) {
|
|
822
|
+
const base = `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/repository/pulls`;
|
|
823
|
+
return number === undefined ? base : `${base}/${encodeURIComponent(number)}`;
|
|
824
|
+
}
|
|
825
|
+
static compactQuery(query) {
|
|
826
|
+
const result = {};
|
|
827
|
+
for (const [key, value] of Object.entries(query)) {
|
|
828
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
829
|
+
result[key] = String(value);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return result;
|
|
833
|
+
}
|
|
834
|
+
async getPullRequests(workspace, project, query = {}) {
|
|
835
|
+
return await this.request({
|
|
836
|
+
method: 'GET',
|
|
837
|
+
path: this.pullsPath(workspace, project),
|
|
838
|
+
query: ApiClient.compactQuery(query),
|
|
839
|
+
parseResponseBody: true,
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
async getPullRequest(workspace, project, number) {
|
|
843
|
+
return await this.request({
|
|
844
|
+
method: 'GET',
|
|
845
|
+
path: this.pullsPath(workspace, project, number),
|
|
846
|
+
parseResponseBody: true,
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
async createPullRequest(workspace, project, body) {
|
|
850
|
+
return await this.request({
|
|
851
|
+
method: 'POST',
|
|
852
|
+
path: this.pullsPath(workspace, project),
|
|
853
|
+
body,
|
|
854
|
+
parseResponseBody: true,
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
async updatePullRequest(workspace, project, number, body) {
|
|
858
|
+
return await this.request({
|
|
859
|
+
method: 'PATCH',
|
|
860
|
+
path: this.pullsPath(workspace, project, number),
|
|
861
|
+
body,
|
|
862
|
+
parseResponseBody: true,
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
async mergePullRequest(workspace, project, number, body) {
|
|
866
|
+
return await this.request({
|
|
867
|
+
method: 'PUT',
|
|
868
|
+
path: `${this.pullsPath(workspace, project, number)}/merge`,
|
|
869
|
+
body,
|
|
870
|
+
parseResponseBody: true,
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
async updatePullRequestBranch(workspace, project, number) {
|
|
874
|
+
return await this.request({
|
|
875
|
+
method: 'PUT',
|
|
876
|
+
path: `${this.pullsPath(workspace, project, number)}/update-branch`,
|
|
877
|
+
parseResponseBody: true,
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
async getPullRequestVersions(workspace, project, number) {
|
|
881
|
+
return await this.request({
|
|
882
|
+
method: 'GET',
|
|
883
|
+
path: `${this.pullsPath(workspace, project, number)}/versions`,
|
|
884
|
+
parseResponseBody: true,
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
async getPullRequestFiles(workspace, project, number, query = {}) {
|
|
888
|
+
return await this.request({
|
|
889
|
+
method: 'GET',
|
|
890
|
+
path: `${this.pullsPath(workspace, project, number)}/files`,
|
|
891
|
+
query: ApiClient.compactQuery(query),
|
|
892
|
+
parseResponseBody: true,
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
async markPullRequestFilesViewed(workspace, project, number, body) {
|
|
896
|
+
return await this.request({
|
|
897
|
+
method: 'POST',
|
|
898
|
+
path: `${this.pullsPath(workspace, project, number)}/files/viewed`,
|
|
899
|
+
body,
|
|
900
|
+
parseResponseBody: true,
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
async getPullRequestDiff(workspace, project, number, query) {
|
|
904
|
+
return await this.request({
|
|
905
|
+
method: 'GET',
|
|
906
|
+
path: `${this.pullsPath(workspace, project, number)}/diff`,
|
|
907
|
+
query: ApiClient.compactQuery(query),
|
|
908
|
+
parseResponseBody: true,
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
async getPullRequestReview(workspace, project, number) {
|
|
912
|
+
return await this.request({
|
|
913
|
+
method: 'GET',
|
|
914
|
+
path: `${this.pullsPath(workspace, project, number)}/review`,
|
|
915
|
+
parseResponseBody: true,
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
async startPullRequestReview(workspace, project, number, version) {
|
|
919
|
+
return await this.request({
|
|
920
|
+
method: 'POST',
|
|
921
|
+
path: `${this.pullsPath(workspace, project, number)}/review`,
|
|
922
|
+
body: { version },
|
|
923
|
+
parseResponseBody: true,
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
async submitPullRequestVerdict(workspace, project, number, body) {
|
|
927
|
+
return await this.request({
|
|
928
|
+
method: 'PUT',
|
|
929
|
+
path: `${this.pullsPath(workspace, project, number)}/review`,
|
|
930
|
+
body,
|
|
931
|
+
parseResponseBody: true,
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
async getPullRequestReviews(workspace, project, number) {
|
|
935
|
+
return await this.request({
|
|
936
|
+
method: 'GET',
|
|
937
|
+
path: `${this.pullsPath(workspace, project, number)}/reviews`,
|
|
938
|
+
parseResponseBody: true,
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
async requestPullRequestReview(workspace, project, number, reviewers) {
|
|
942
|
+
return await this.request({
|
|
943
|
+
method: 'POST',
|
|
944
|
+
path: `${this.pullsPath(workspace, project, number)}/reviewers`,
|
|
945
|
+
body: { reviewers },
|
|
946
|
+
parseResponseBody: true,
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
async getPullRequestActivity(workspace, project, number, since) {
|
|
950
|
+
return await this.request({
|
|
951
|
+
method: 'GET',
|
|
952
|
+
path: `${this.pullsPath(workspace, project, number)}/activity`,
|
|
953
|
+
query: ApiClient.compactQuery({ since }),
|
|
954
|
+
parseResponseBody: true,
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
async addPullRequestComment(workspace, project, number, comment) {
|
|
958
|
+
return await this.request({
|
|
959
|
+
method: 'POST',
|
|
960
|
+
path: `${this.pullsPath(workspace, project, number)}/comments`,
|
|
961
|
+
body: { comment },
|
|
962
|
+
parseResponseBody: true,
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
async getPullRequestThreads(workspace, project, number, query = {}) {
|
|
966
|
+
return await this.request({
|
|
967
|
+
method: 'GET',
|
|
968
|
+
path: `${this.pullsPath(workspace, project, number)}/threads`,
|
|
969
|
+
query: ApiClient.compactQuery(query),
|
|
970
|
+
parseResponseBody: true,
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
async getPullRequestThread(workspace, project, number, threadId, version) {
|
|
974
|
+
return await this.request({
|
|
975
|
+
method: 'GET',
|
|
976
|
+
path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}`,
|
|
977
|
+
query: ApiClient.compactQuery({ version }),
|
|
978
|
+
parseResponseBody: true,
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
async addPullRequestThread(workspace, project, number, body) {
|
|
982
|
+
return await this.request({
|
|
983
|
+
method: 'POST',
|
|
984
|
+
path: `${this.pullsPath(workspace, project, number)}/threads`,
|
|
985
|
+
body,
|
|
986
|
+
parseResponseBody: true,
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
async addPullRequestThreadComment(workspace, project, number, threadId, comment) {
|
|
990
|
+
return await this.request({
|
|
991
|
+
method: 'POST',
|
|
992
|
+
path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}/comments`,
|
|
993
|
+
body: { comment },
|
|
994
|
+
parseResponseBody: true,
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
async updatePullRequestThread(workspace, project, number, threadId, body) {
|
|
998
|
+
return await this.request({
|
|
999
|
+
method: 'PATCH',
|
|
1000
|
+
path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}`,
|
|
1001
|
+
body,
|
|
1002
|
+
parseResponseBody: true,
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
815
1005
|
// Environment methods
|
|
816
1006
|
async getEnvironments(workspace, project) {
|
|
817
1007
|
const query = {};
|
|
@@ -0,0 +1,90 @@
|
|
|
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 logger_1 = __importDefault(require("./logger"));
|
|
7
|
+
class Autocomplete {
|
|
8
|
+
getCommandsMap(command) {
|
|
9
|
+
const commands = {};
|
|
10
|
+
command.commands.forEach((c) => {
|
|
11
|
+
const map = this.getCommandsMap(c);
|
|
12
|
+
const name = c.name() || 'bdy';
|
|
13
|
+
commands[name] = map;
|
|
14
|
+
c.aliases().forEach((a) => {
|
|
15
|
+
commands[a] = map;
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
command.options.forEach((o) => {
|
|
19
|
+
const name = `--${o.name()}`;
|
|
20
|
+
commands[name] = {};
|
|
21
|
+
});
|
|
22
|
+
let lastArg = commands;
|
|
23
|
+
command.registeredArguments.forEach((a) => {
|
|
24
|
+
logger_1.default.info(a);
|
|
25
|
+
let name;
|
|
26
|
+
if (a.required) {
|
|
27
|
+
name = `<${a.name()}>`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
name = `[${a.name()}]`;
|
|
31
|
+
}
|
|
32
|
+
name = name.replaceAll(':', '꞉'); // U+A789 MODIFIER LETTER COLON - looks like : but doesn't trigger tabtab delimiter
|
|
33
|
+
lastArg[name] = {};
|
|
34
|
+
lastArg = lastArg[name];
|
|
35
|
+
});
|
|
36
|
+
return commands;
|
|
37
|
+
}
|
|
38
|
+
init(rootCommand) {
|
|
39
|
+
// COMP_LINE is set by all shells (bash natively, zsh/fish via tabtab scripts) when invoking completion
|
|
40
|
+
if (!process.env.COMP_LINE)
|
|
41
|
+
return false;
|
|
42
|
+
const tabtab = require('tabtab');
|
|
43
|
+
const env = tabtab.parseEnv(process.env);
|
|
44
|
+
if (!env.complete)
|
|
45
|
+
return false;
|
|
46
|
+
let map = {
|
|
47
|
+
bdy: this.getCommandsMap(rootCommand)
|
|
48
|
+
};
|
|
49
|
+
const s = (env.partial || '').trim().split(' ').filter((n) => !n.startsWith('--'));
|
|
50
|
+
const last = s[s.length - 1];
|
|
51
|
+
for (let i = 0; i < s.length - 1; i += 1) {
|
|
52
|
+
const name = s[i];
|
|
53
|
+
if (!map[name]) {
|
|
54
|
+
const arg = Object.keys(map).find((k) => k.startsWith('<') || k.startsWith('['));
|
|
55
|
+
if (arg) {
|
|
56
|
+
map = map[arg];
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
map = map[name];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (map[last])
|
|
67
|
+
map = map[last];
|
|
68
|
+
else {
|
|
69
|
+
const arg = Object.keys(map).find((k) => k.startsWith('<') || k.startsWith('['));
|
|
70
|
+
if (arg)
|
|
71
|
+
map = map[arg];
|
|
72
|
+
}
|
|
73
|
+
tabtab.log(Object.keys(map));
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
async install() {
|
|
77
|
+
const tabtab = require('tabtab');
|
|
78
|
+
await tabtab.install({
|
|
79
|
+
name: process.title,
|
|
80
|
+
completer: process.title
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async uninstall() {
|
|
84
|
+
const tabtab = require('tabtab');
|
|
85
|
+
await tabtab.uninstall({
|
|
86
|
+
name: process.title
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.default = new Autocomplete();
|
package/distTs/src/cliError.js
CHANGED
|
@@ -13,6 +13,11 @@ var SemanticExitCode;
|
|
|
13
13
|
class CliError extends Error {
|
|
14
14
|
code;
|
|
15
15
|
hint;
|
|
16
|
+
// Set by ApiClient for API errors: the HTTP status and the parsed JSON body,
|
|
17
|
+
// so a command can read fields the API sends next to `errors` (e.g. the
|
|
18
|
+
// current version in a 409 of a pull request verdict).
|
|
19
|
+
status;
|
|
20
|
+
body;
|
|
16
21
|
constructor(code, message, hint = null, options) {
|
|
17
22
|
super(message, options);
|
|
18
23
|
this.code = code;
|
package/distTs/src/cliIndex.js
CHANGED
|
@@ -33,6 +33,7 @@ const register_1 = __importDefault(require("./command/register"));
|
|
|
33
33
|
const mcp_1 = __importDefault(require("./command/mcp"));
|
|
34
34
|
const discover_1 = __importDefault(require("./command/discover"));
|
|
35
35
|
const context_1 = __importDefault(require("./command/context"));
|
|
36
|
+
const pr_1 = __importDefault(require("./command/pr"));
|
|
36
37
|
const input_1 = __importDefault(require("./input"));
|
|
37
38
|
const cliCommand_1 = __importDefault(require("./cliCommand"));
|
|
38
39
|
const client_1 = __importDefault(require("./api/client"));
|
|
@@ -50,6 +51,7 @@ function cliIndex() {
|
|
|
50
51
|
program.hook('preAction', pre_1.default);
|
|
51
52
|
program.configureHelp({
|
|
52
53
|
formatHelp: utils_1.formatHelp,
|
|
54
|
+
subcommandTerm: utils_1.subcommandTerm,
|
|
53
55
|
});
|
|
54
56
|
// root options must come before the subcommand, so -v here can't
|
|
55
57
|
// shadow subcommand flags like `sandbox create -v <variable>`
|
|
@@ -76,6 +78,7 @@ function cliIndex() {
|
|
|
76
78
|
program.addCommand(logout_1.default);
|
|
77
79
|
program.addCommand(workspace_1.default);
|
|
78
80
|
program.addCommand(project_1.default);
|
|
81
|
+
program.addCommand(pr_1.default);
|
|
79
82
|
program.addCommand(yaml_1.default);
|
|
80
83
|
program.addCommand(api_1.default);
|
|
81
84
|
program.addCommand(mcp_1.default);
|
|
@@ -0,0 +1,110 @@
|
|
|
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.prepareDownloadDirectory = prepareDownloadDirectory;
|
|
7
|
+
exports.downloadArtifactVersionToDirectory = downloadArtifactVersionToDirectory;
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const texts_1 = require("../../texts");
|
|
10
|
+
const output_1 = __importDefault(require("../../output"));
|
|
11
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
const promises_1 = __importDefault(require("node:stream/promises"));
|
|
15
|
+
/**
|
|
16
|
+
* Makes sure `path` is a directory the artifact can be unpacked into: created
|
|
17
|
+
* when missing, wiped with `replace`, and otherwise required to be empty
|
|
18
|
+
* unless `merge` is set. Returns the absolute path.
|
|
19
|
+
*/
|
|
20
|
+
function prepareDownloadDirectory(path, options) {
|
|
21
|
+
const dirPath = (0, path_1.resolve)(path);
|
|
22
|
+
const exists = fs_1.default.existsSync(dirPath);
|
|
23
|
+
if (!exists) {
|
|
24
|
+
try {
|
|
25
|
+
fs_1.default.mkdirSync(dirPath, {
|
|
26
|
+
recursive: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
logger_1.default.error(err);
|
|
31
|
+
output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_MKDIR)(dirPath));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (options.replace) {
|
|
35
|
+
try {
|
|
36
|
+
fs_1.default.rmSync(dirPath, {
|
|
37
|
+
recursive: true,
|
|
38
|
+
force: true,
|
|
39
|
+
});
|
|
40
|
+
fs_1.default.mkdirSync(dirPath, {
|
|
41
|
+
recursive: true,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
logger_1.default.error(err);
|
|
46
|
+
output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_REPLACE)(dirPath));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const stat = fs_1.default.statSync(dirPath);
|
|
51
|
+
if (!stat.isDirectory()) {
|
|
52
|
+
output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_IS_FILE)(dirPath));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
logger_1.default.error(err);
|
|
57
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
58
|
+
}
|
|
59
|
+
let empty = true;
|
|
60
|
+
try {
|
|
61
|
+
const entries = fs_1.default.readdirSync(dirPath);
|
|
62
|
+
empty = !entries.length;
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
logger_1.default.error(err);
|
|
66
|
+
output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_READDIR)(dirPath));
|
|
67
|
+
}
|
|
68
|
+
if (!empty && !options.merge) {
|
|
69
|
+
output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_NOT_EMPTY_DIR)(dirPath));
|
|
70
|
+
}
|
|
71
|
+
return dirPath;
|
|
72
|
+
}
|
|
73
|
+
// Returns the number of files unpacked.
|
|
74
|
+
async function downloadArtifactVersionToDirectory(client, workspace, artifactId, versionId, dirPath, quiet = false) {
|
|
75
|
+
const { v4 } = require('uuid');
|
|
76
|
+
const ArchiverExtract = require('../../unzipper').default;
|
|
77
|
+
const { UNZIPPER_FORMAT } = require('../../unzipper');
|
|
78
|
+
const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${v4()}.zip`);
|
|
79
|
+
const clearZip = () => {
|
|
80
|
+
try {
|
|
81
|
+
fs_1.default.rmSync(zipPath);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// do nothing
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
// Progress rewrites the previous line, which only works on a terminal; a
|
|
88
|
+
// piped stdout would otherwise get one line per extracted file.
|
|
89
|
+
const say = output_1.default.progress(quiet || !output_1.default.isStdOutTTY());
|
|
90
|
+
say(texts_1.TXT_ARTIFACT_DOWNLOADING_ZIP);
|
|
91
|
+
const body = await client.downloadArtifactVersion(workspace, artifactId, versionId);
|
|
92
|
+
let count = 0;
|
|
93
|
+
try {
|
|
94
|
+
await promises_1.default.pipeline(body, fs_1.default.createWriteStream(zipPath));
|
|
95
|
+
say(texts_1.TXT_ARTIFACT_DOWNLOADED_ZIP, true, true);
|
|
96
|
+
say(texts_1.TXT_ARTIFACT_UNZIPPING);
|
|
97
|
+
await ArchiverExtract.extract(UNZIPPER_FORMAT.ZIP, zipPath, dirPath, async () => {
|
|
98
|
+
count += 1;
|
|
99
|
+
say((0, texts_1.TXT_ARTIFACT_UNZIPPING_COUNT)(count), true, true);
|
|
100
|
+
});
|
|
101
|
+
clearZip();
|
|
102
|
+
say(texts_1.TXT_ARTIFACT_UNZIPPED, true, true);
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
logger_1.default.error(err);
|
|
106
|
+
clearZip();
|
|
107
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
108
|
+
}
|
|
109
|
+
return count;
|
|
110
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 autocomplete_1 = __importDefault(require("../../autocomplete"));
|
|
8
|
+
const texts_1 = require("../../texts");
|
|
9
|
+
const output_1 = __importDefault(require("../../output"));
|
|
10
|
+
const commandAutocompleteInstall = (0, utils_1.newCommand)('install', texts_1.DESC_COMMAND_AUTOCOMPLETE_INSTALL);
|
|
11
|
+
commandAutocompleteInstall.alias('i');
|
|
12
|
+
commandAutocompleteInstall.action(async () => {
|
|
13
|
+
await autocomplete_1.default.install();
|
|
14
|
+
output_1.default.exitSuccess(texts_1.TXT_AUTOCOMPLETE_INSTALLED);
|
|
15
|
+
});
|
|
16
|
+
exports.default = commandAutocompleteInstall;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 autocomplete_1 = __importDefault(require("../../autocomplete"));
|
|
8
|
+
const texts_1 = require("../../texts");
|
|
9
|
+
const output_1 = __importDefault(require("../../output"));
|
|
10
|
+
const commandAutocompleteUninstall = (0, utils_1.newCommand)('uninstall', texts_1.DESC_COMMAND_AUTOCOMPLETE_UNINSTALL);
|
|
11
|
+
commandAutocompleteUninstall.alias('u');
|
|
12
|
+
commandAutocompleteUninstall.action(async () => {
|
|
13
|
+
await autocomplete_1.default.uninstall();
|
|
14
|
+
output_1.default.exitSuccess(texts_1.TXT_AUTOCOMPLETE_UNINSTALLED);
|
|
15
|
+
});
|
|
16
|
+
exports.default = commandAutocompleteUninstall;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 install_1 = __importDefault(require("./autocomplete/install"));
|
|
8
|
+
const uninstall_1 = __importDefault(require("./autocomplete/uninstall"));
|
|
9
|
+
const texts_1 = require("../texts");
|
|
10
|
+
const commandAutocomplete = (0, utils_1.newCommand)('autocomplete', texts_1.DESC_COMMAND_AUTOCOMPLETE);
|
|
11
|
+
commandAutocomplete.alias('ac');
|
|
12
|
+
commandAutocomplete.addCommand(install_1.default);
|
|
13
|
+
commandAutocomplete.addCommand(uninstall_1.default);
|
|
14
|
+
exports.default = commandAutocomplete;
|
|
@@ -0,0 +1,39 @@
|
|
|
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.resolveEnvironmentId = void 0;
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../input"));
|
|
10
|
+
// Shared resolve preamble for commands taking an environment identifier:
|
|
11
|
+
// project context from flags/env -> /identifiers -> hash id, exiting on a
|
|
12
|
+
// miss. Without a project the identifier resolves as a workspace
|
|
13
|
+
// environment; with one, along the project line.
|
|
14
|
+
//
|
|
15
|
+
// strictProject is for mutating commands (update/delete): an explicit -p is
|
|
16
|
+
// a statement "the environment of this project", so the resolved environment
|
|
17
|
+
// must actually live there. Without it /identifiers silently falls back to
|
|
18
|
+
// the workspace environment of the same identifier and the write lands on a
|
|
19
|
+
// workspace-wide resource. Reads keep the fallback - that is how workspace
|
|
20
|
+
// environments stay addressable from inside a project context.
|
|
21
|
+
const resolveEnvironmentId = async (client, workspace, identifier, options, strictProject = false) => {
|
|
22
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
23
|
+
const resolved = await client.getEnvironmentByIdentifier(workspace, identifier, project);
|
|
24
|
+
// A nonexistent project is rejected by the API client
|
|
25
|
+
// (getResourceByIdentifier); here only the environment itself can miss.
|
|
26
|
+
if (!resolved.environment_id) {
|
|
27
|
+
output_1.default.exitError(texts_1.ERR_ENVIRONMENT_NOT_FOUND);
|
|
28
|
+
}
|
|
29
|
+
if (strictProject && options.project) {
|
|
30
|
+
const environment = await client.getEnvironment(workspace, resolved.environment_id);
|
|
31
|
+
// a workspace environment carries no project, so this also fails the
|
|
32
|
+
// workspace-fallback case
|
|
33
|
+
if (environment.project?.name !== resolved.project_identifier) {
|
|
34
|
+
output_1.default.exitError(texts_1.ERR_ENVIRONMENT_NOT_FOUND);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return resolved.environment_id;
|
|
38
|
+
};
|
|
39
|
+
exports.resolveEnvironmentId = resolveEnvironmentId;
|
|
@@ -172,7 +172,7 @@ async function oauthServer(api, clientId, clientSecret, forceRegisterEmail, forc
|
|
|
172
172
|
else {
|
|
173
173
|
output_1.default.dim(isRegister ? texts_1.TXT_REGISTER_OPEN_URL : texts_1.TXT_LOGIN_OPEN_URL);
|
|
174
174
|
output_1.default.normal('');
|
|
175
|
-
output_1.default.dim(url
|
|
175
|
+
output_1.default.dim(url);
|
|
176
176
|
output_1.default.normal('');
|
|
177
177
|
}
|
|
178
178
|
for (;;) {
|
|
@@ -0,0 +1,64 @@
|
|
|
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 input_1 = __importDefault(require("../../input"));
|
|
9
|
+
const output_1 = __importDefault(require("../../output"));
|
|
10
|
+
const commandPackageCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMAND_PACKAGE_CREATE);
|
|
11
|
+
commandPackageCreate.alias('add');
|
|
12
|
+
commandPackageCreate.option('-i, --identifier <identifier>', texts_1.OPT_COMMAND_PACKAGE_CREATE_IDENTIFIER);
|
|
13
|
+
commandPackageCreate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
14
|
+
commandPackageCreate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
15
|
+
commandPackageCreate.option('-t, --type <type>', texts_1.OPT_COMMAND_PACKAGE_TYPE, utils_1.PACKAGE_TYPE.FILE);
|
|
16
|
+
commandPackageCreate.option('-b, --buddy', texts_1.OPTION_HTTP_AUTH_BUDDY);
|
|
17
|
+
commandPackageCreate.option('-a, --auth <user:pass>', texts_1.OPTION_HTTP_AUTH);
|
|
18
|
+
commandPackageCreate.argument('[name]', texts_1.OPT_COMMAND_PACKAGE_NAME);
|
|
19
|
+
commandPackageCreate.addHelpText('after', texts_1.EXAMPLE_PACKAGE_CREATE);
|
|
20
|
+
commandPackageCreate.action(async (name, options) => {
|
|
21
|
+
const humanId = require('human-id').default;
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
24
|
+
const client = input_1.default.restApiTokenClient();
|
|
25
|
+
const type = input_1.default.packageType(options.type);
|
|
26
|
+
const scope = input_1.default.packageScope(project);
|
|
27
|
+
if (!name) {
|
|
28
|
+
if (options.identifier)
|
|
29
|
+
name = options.identifier;
|
|
30
|
+
else
|
|
31
|
+
name = humanId({ separator: '-', capitalize: false });
|
|
32
|
+
}
|
|
33
|
+
const data = {
|
|
34
|
+
name,
|
|
35
|
+
type,
|
|
36
|
+
scope,
|
|
37
|
+
authorization: {
|
|
38
|
+
type: utils_1.PACKAGE_AUTH_TYPE.NONE,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
if (project) {
|
|
42
|
+
data.project = {
|
|
43
|
+
name: project,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (options.identifier)
|
|
47
|
+
data.identifier = options.identifier;
|
|
48
|
+
if (options.auth) {
|
|
49
|
+
const { password, login } = input_1.default.auth(options.auth);
|
|
50
|
+
data.authorization = {
|
|
51
|
+
type: utils_1.PACKAGE_AUTH_TYPE.BASIC,
|
|
52
|
+
user: login,
|
|
53
|
+
password,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else if (options.buddy) {
|
|
57
|
+
data.authorization = {
|
|
58
|
+
type: utils_1.PACKAGE_AUTH_TYPE.BUDDY,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const result = await client.createPackage(workspace, data);
|
|
62
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_CREATED)(client.baseUrl, workspace, result));
|
|
63
|
+
});
|
|
64
|
+
exports.default = commandPackageCreate;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 input_1 = __importDefault(require("../../input"));
|
|
9
|
+
const output_1 = __importDefault(require("../../output"));
|
|
10
|
+
const commandPackageDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_PACKAGE_DELETE);
|
|
11
|
+
commandPackageDelete.alias('rm');
|
|
12
|
+
commandPackageDelete.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
13
|
+
commandPackageDelete.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
14
|
+
commandPackageDelete.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
|
|
15
|
+
commandPackageDelete.argument('<identifier>', texts_1.OPT_COMMAND_PACKAGE_IDENTIFIER);
|
|
16
|
+
commandPackageDelete.addHelpText('after', texts_1.EXAMPLE_PACKAGE_DELETE);
|
|
17
|
+
commandPackageDelete.action(async (identifier, options) => {
|
|
18
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
19
|
+
const project = input_1.default.restApiProject(options.project);
|
|
20
|
+
const client = input_1.default.restApiTokenClient();
|
|
21
|
+
const data = await client.getPackageVersionByIdentifier(workspace, project, identifier);
|
|
22
|
+
if (!data || !data.domain) {
|
|
23
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
|
|
24
|
+
}
|
|
25
|
+
if (!data.pkg_id) {
|
|
26
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_NOT_FOUND);
|
|
27
|
+
}
|
|
28
|
+
const confirmed = options.force ||
|
|
29
|
+
(await output_1.default.confirm((0, texts_1.TXT_PACKAGE_DELETE_CONFIRM)(identifier)));
|
|
30
|
+
if (confirmed) {
|
|
31
|
+
await client.deletePackage(workspace, data.pkg_id);
|
|
32
|
+
output_1.default.exitSuccess(texts_1.TXT_PACKAGE_DELETED);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
output_1.default.exitNormal();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
exports.default = commandPackageDelete;
|