@yadsh/dsh-qa-integrations 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +617 -0
- package/compatibility.json +10 -0
- package/cordis.patch.yml +5 -0
- package/lib/broker.js +239 -0
- package/lib/broker.js.map +1 -0
- package/lib/client/bitrix24.js +33 -0
- package/lib/client/bitrix24.js.map +1 -0
- package/lib/client/card.js +33 -0
- package/lib/client/card.js.map +1 -0
- package/lib/client/confluence.js +148 -0
- package/lib/client/confluence.js.map +1 -0
- package/lib/client/copy.js +18 -0
- package/lib/client/copy.js.map +1 -0
- package/lib/client/gitlab.js +64 -0
- package/lib/client/gitlab.js.map +1 -0
- package/lib/client/index.js +71 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/integrations.js +34 -0
- package/lib/client/integrations.js.map +1 -0
- package/lib/client/jira.js +150 -0
- package/lib/client/jira.js.map +1 -0
- package/lib/client/provider-card.js +143 -0
- package/lib/client/provider-card.js.map +1 -0
- package/lib/client/styles.js +35 -0
- package/lib/client/styles.js.map +1 -0
- package/lib/client/teamcity.js +55 -0
- package/lib/client/teamcity.js.map +1 -0
- package/lib/client.js +8069 -0
- package/lib/client.js.map +1 -0
- package/lib/coerce.js +69 -0
- package/lib/coerce.js.map +1 -0
- package/lib/config.js +51 -0
- package/lib/config.js.map +1 -0
- package/lib/errors.js +14 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.js +510 -0
- package/lib/index.js.map +1 -0
- package/lib/providers/bitrix24/catalog.js +245 -0
- package/lib/providers/bitrix24/catalog.js.map +1 -0
- package/lib/providers/bitrix24/config.js +40 -0
- package/lib/providers/bitrix24/config.js.map +1 -0
- package/lib/providers/bitrix24/index.js +128 -0
- package/lib/providers/bitrix24/index.js.map +1 -0
- package/lib/providers/bitrix24/operations.js +491 -0
- package/lib/providers/bitrix24/operations.js.map +1 -0
- package/lib/providers/bitrix24/tools.js +1035 -0
- package/lib/providers/bitrix24/tools.js.map +1 -0
- package/lib/providers/bitrix24/transport.js +142 -0
- package/lib/providers/bitrix24/transport.js.map +1 -0
- package/lib/providers/confluence/adf.js +348 -0
- package/lib/providers/confluence/adf.js.map +1 -0
- package/lib/providers/confluence/catalog.js +135 -0
- package/lib/providers/confluence/catalog.js.map +1 -0
- package/lib/providers/confluence/config.js +196 -0
- package/lib/providers/confluence/config.js.map +1 -0
- package/lib/providers/confluence/cql.js +78 -0
- package/lib/providers/confluence/cql.js.map +1 -0
- package/lib/providers/confluence/index.js +319 -0
- package/lib/providers/confluence/index.js.map +1 -0
- package/lib/providers/confluence/operations.js +653 -0
- package/lib/providers/confluence/operations.js.map +1 -0
- package/lib/providers/confluence/tools.js +282 -0
- package/lib/providers/confluence/tools.js.map +1 -0
- package/lib/providers/confluence/transport.js +247 -0
- package/lib/providers/confluence/transport.js.map +1 -0
- package/lib/providers/contract.js +2 -0
- package/lib/providers/contract.js.map +1 -0
- package/lib/providers/gitlab/catalog.js +171 -0
- package/lib/providers/gitlab/catalog.js.map +1 -0
- package/lib/providers/gitlab/config.js +141 -0
- package/lib/providers/gitlab/config.js.map +1 -0
- package/lib/providers/gitlab/index.js +227 -0
- package/lib/providers/gitlab/index.js.map +1 -0
- package/lib/providers/gitlab/operations.js +794 -0
- package/lib/providers/gitlab/operations.js.map +1 -0
- package/lib/providers/gitlab/tools.js +859 -0
- package/lib/providers/gitlab/tools.js.map +1 -0
- package/lib/providers/gitlab/transport.js +140 -0
- package/lib/providers/gitlab/transport.js.map +1 -0
- package/lib/providers/jira/adf.js +235 -0
- package/lib/providers/jira/adf.js.map +1 -0
- package/lib/providers/jira/catalog.js +145 -0
- package/lib/providers/jira/catalog.js.map +1 -0
- package/lib/providers/jira/config.js +198 -0
- package/lib/providers/jira/config.js.map +1 -0
- package/lib/providers/jira/index.js +301 -0
- package/lib/providers/jira/index.js.map +1 -0
- package/lib/providers/jira/jql.js +299 -0
- package/lib/providers/jira/jql.js.map +1 -0
- package/lib/providers/jira/operations.js +617 -0
- package/lib/providers/jira/operations.js.map +1 -0
- package/lib/providers/jira/tools.js +341 -0
- package/lib/providers/jira/tools.js.map +1 -0
- package/lib/providers/jira/transport.js +227 -0
- package/lib/providers/jira/transport.js.map +1 -0
- package/lib/providers/registry.js +21 -0
- package/lib/providers/registry.js.map +1 -0
- package/lib/providers/shared/account.js +20 -0
- package/lib/providers/shared/account.js.map +1 -0
- package/lib/providers/shared/host.js +15 -0
- package/lib/providers/shared/host.js.map +1 -0
- package/lib/providers/shared/http.js +148 -0
- package/lib/providers/shared/http.js.map +1 -0
- package/lib/providers/teamcity/artifacts.js +155 -0
- package/lib/providers/teamcity/artifacts.js.map +1 -0
- package/lib/providers/teamcity/catalog.js +155 -0
- package/lib/providers/teamcity/catalog.js.map +1 -0
- package/lib/providers/teamcity/config.js +262 -0
- package/lib/providers/teamcity/config.js.map +1 -0
- package/lib/providers/teamcity/index.js +228 -0
- package/lib/providers/teamcity/index.js.map +1 -0
- package/lib/providers/teamcity/locators.js +95 -0
- package/lib/providers/teamcity/locators.js.map +1 -0
- package/lib/providers/teamcity/logs.js +113 -0
- package/lib/providers/teamcity/logs.js.map +1 -0
- package/lib/providers/teamcity/network.js +160 -0
- package/lib/providers/teamcity/network.js.map +1 -0
- package/lib/providers/teamcity/operations.js +625 -0
- package/lib/providers/teamcity/operations.js.map +1 -0
- package/lib/providers/teamcity/tools.js +480 -0
- package/lib/providers/teamcity/tools.js.map +1 -0
- package/lib/providers/teamcity/transport.js +126 -0
- package/lib/providers/teamcity/transport.js.map +1 -0
- package/lib/redaction.js +38 -0
- package/lib/redaction.js.map +1 -0
- package/lib/repository.js +414 -0
- package/lib/repository.js.map +1 -0
- package/lib/secrets/key-provider.js +76 -0
- package/lib/secrets/key-provider.js.map +1 -0
- package/lib/secrets/secret-store.js +93 -0
- package/lib/secrets/secret-store.js.map +1 -0
- package/lib/shared/settings.js +19 -0
- package/lib/shared/settings.js.map +1 -0
- package/lib/tool-kit.js +55 -0
- package/lib/tool-kit.js.map +1 -0
- package/lib/tools.js +28 -0
- package/lib/tools.js.map +1 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +1689 -0
- package/lib/typert.remote-client.d.ts +84 -0
- package/lib/typert.remote-client.js +1429 -0
- package/lib/types/broker.d.ts +30 -0
- package/lib/types/client/bitrix24.d.ts +18 -0
- package/lib/types/client/card.d.ts +13 -0
- package/lib/types/client/confluence.d.ts +17 -0
- package/lib/types/client/copy.d.ts +7 -0
- package/lib/types/client/gitlab.d.ts +15 -0
- package/lib/types/client/index.d.ts +13 -0
- package/lib/types/client/integrations.d.ts +28 -0
- package/lib/types/client/jira.d.ts +17 -0
- package/lib/types/client/provider-card.d.ts +63 -0
- package/lib/types/client/styles.d.ts +7 -0
- package/lib/types/client/teamcity.d.ts +19 -0
- package/lib/types/coerce.d.ts +18 -0
- package/lib/types/config.d.ts +48 -0
- package/lib/types/errors.d.ts +26 -0
- package/lib/types/index.d.ts +170 -0
- package/lib/types/providers/bitrix24/catalog.d.ts +48 -0
- package/lib/types/providers/bitrix24/config.d.ts +43 -0
- package/lib/types/providers/bitrix24/index.d.ts +31 -0
- package/lib/types/providers/bitrix24/operations.d.ts +13 -0
- package/lib/types/providers/bitrix24/tools.d.ts +9 -0
- package/lib/types/providers/bitrix24/transport.d.ts +26 -0
- package/lib/types/providers/confluence/adf.d.ts +22 -0
- package/lib/types/providers/confluence/catalog.d.ts +59 -0
- package/lib/types/providers/confluence/config.d.ts +68 -0
- package/lib/types/providers/confluence/cql.d.ts +43 -0
- package/lib/types/providers/confluence/index.d.ts +73 -0
- package/lib/types/providers/confluence/operations.d.ts +92 -0
- package/lib/types/providers/confluence/tools.d.ts +15 -0
- package/lib/types/providers/confluence/transport.d.ts +77 -0
- package/lib/types/providers/contract.d.ts +33 -0
- package/lib/types/providers/gitlab/catalog.d.ts +49 -0
- package/lib/types/providers/gitlab/config.d.ts +50 -0
- package/lib/types/providers/gitlab/index.d.ts +49 -0
- package/lib/types/providers/gitlab/operations.d.ts +40 -0
- package/lib/types/providers/gitlab/tools.d.ts +15 -0
- package/lib/types/providers/gitlab/transport.d.ts +52 -0
- package/lib/types/providers/jira/adf.d.ts +27 -0
- package/lib/types/providers/jira/catalog.d.ts +74 -0
- package/lib/types/providers/jira/config.d.ts +73 -0
- package/lib/types/providers/jira/index.d.ts +79 -0
- package/lib/types/providers/jira/jql.d.ts +51 -0
- package/lib/types/providers/jira/operations.d.ts +58 -0
- package/lib/types/providers/jira/tools.d.ts +17 -0
- package/lib/types/providers/jira/transport.d.ts +65 -0
- package/lib/types/providers/registry.d.ts +9 -0
- package/lib/types/providers/shared/account.d.ts +10 -0
- package/lib/types/providers/shared/host.d.ts +9 -0
- package/lib/types/providers/shared/http.d.ts +51 -0
- package/lib/types/providers/teamcity/artifacts.d.ts +45 -0
- package/lib/types/providers/teamcity/catalog.d.ts +55 -0
- package/lib/types/providers/teamcity/config.d.ts +66 -0
- package/lib/types/providers/teamcity/index.d.ts +62 -0
- package/lib/types/providers/teamcity/locators.d.ts +47 -0
- package/lib/types/providers/teamcity/logs.d.ts +31 -0
- package/lib/types/providers/teamcity/network.d.ts +32 -0
- package/lib/types/providers/teamcity/operations.d.ts +84 -0
- package/lib/types/providers/teamcity/tools.d.ts +15 -0
- package/lib/types/providers/teamcity/transport.d.ts +53 -0
- package/lib/types/redaction.d.ts +3 -0
- package/lib/types/repository.d.ts +48 -0
- package/lib/types/secrets/key-provider.d.ts +30 -0
- package/lib/types/secrets/secret-store.d.ts +12 -0
- package/lib/types/shared/settings.d.ts +19 -0
- package/lib/types/tool-kit.d.ts +26 -0
- package/lib/types/tools.d.ts +16 -0
- package/lib/types/types.d.ts +138 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +143 -0
|
@@ -0,0 +1,794 @@
|
|
|
1
|
+
import { optionalBoolean, optionalInteger, optionalText, requiredInteger, requiredStringList, requiredText, } from "../../coerce.js";
|
|
2
|
+
import { IntegrationError } from "../../errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Name of a GitLab project as it appears in a path segment: either the numeric
|
|
5
|
+
* id or a `namespace/project` path. Both are passed through URL-encoded, and
|
|
6
|
+
* neither may carry a traversal or an extra segment, because this value ends up
|
|
7
|
+
* inside the REST path.
|
|
8
|
+
*/
|
|
9
|
+
const PROJECT_PATH = /^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/u;
|
|
10
|
+
const GROUP_PATH = /^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/u;
|
|
11
|
+
const REF_NAME = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,254}$/u;
|
|
12
|
+
const COMMIT_SHA = /^[0-9a-fA-F]{7,40}$/u;
|
|
13
|
+
function invalid(field) {
|
|
14
|
+
throw new IntegrationError("InvalidRequest", `${field} is invalid`);
|
|
15
|
+
}
|
|
16
|
+
function hasTraversal(value) {
|
|
17
|
+
return value
|
|
18
|
+
.split("/")
|
|
19
|
+
.some((segment) => segment === ".." || segment === ".");
|
|
20
|
+
}
|
|
21
|
+
/** A project id or path, canonicalized into one URL path segment. */
|
|
22
|
+
export function projectRef(value, field = "project") {
|
|
23
|
+
if (typeof value === "number") {
|
|
24
|
+
return String(requiredInteger(value, field));
|
|
25
|
+
}
|
|
26
|
+
if (typeof value !== "string")
|
|
27
|
+
invalid(field);
|
|
28
|
+
const normalized = value.trim().replace(/^\/+|\/+$/gu, "");
|
|
29
|
+
if (normalized === "" ||
|
|
30
|
+
normalized.length > 255 ||
|
|
31
|
+
!PROJECT_PATH.test(normalized) ||
|
|
32
|
+
hasTraversal(normalized)) {
|
|
33
|
+
invalid(field);
|
|
34
|
+
}
|
|
35
|
+
return encodeURIComponent(normalized);
|
|
36
|
+
}
|
|
37
|
+
export function groupRef(value, field = "group") {
|
|
38
|
+
if (typeof value === "number") {
|
|
39
|
+
return String(requiredInteger(value, field));
|
|
40
|
+
}
|
|
41
|
+
if (typeof value !== "string")
|
|
42
|
+
invalid(field);
|
|
43
|
+
const normalized = value.trim().replace(/^\/+|\/+$/gu, "");
|
|
44
|
+
if (normalized === "" ||
|
|
45
|
+
normalized.length > 255 ||
|
|
46
|
+
!GROUP_PATH.test(normalized) ||
|
|
47
|
+
hasTraversal(normalized)) {
|
|
48
|
+
invalid(field);
|
|
49
|
+
}
|
|
50
|
+
return encodeURIComponent(normalized);
|
|
51
|
+
}
|
|
52
|
+
/** Branch, tag or commit-ish; validated, never a path of its own. */
|
|
53
|
+
function refName(value, field = "ref") {
|
|
54
|
+
const normalized = requiredText(value, field, 1, 255);
|
|
55
|
+
if (!REF_NAME.test(normalized) ||
|
|
56
|
+
hasTraversal(normalized) ||
|
|
57
|
+
normalized.includes("//")) {
|
|
58
|
+
invalid(field);
|
|
59
|
+
}
|
|
60
|
+
return normalized;
|
|
61
|
+
}
|
|
62
|
+
function commitSha(value, field = "sha") {
|
|
63
|
+
const normalized = requiredText(value, field, 7, 40);
|
|
64
|
+
if (!COMMIT_SHA.test(normalized))
|
|
65
|
+
invalid(field);
|
|
66
|
+
return normalized;
|
|
67
|
+
}
|
|
68
|
+
/** Repository path: the whole thing is one REST segment, so it is encoded. */
|
|
69
|
+
function filePath(value, field = "path") {
|
|
70
|
+
const normalized = requiredText(value, field, 1, 512);
|
|
71
|
+
if (normalized.startsWith("/") ||
|
|
72
|
+
hasTraversal(normalized) ||
|
|
73
|
+
// eslint-disable-next-line no-control-regex
|
|
74
|
+
/[\u0000-\u001f\u007f\\]/u.test(normalized)) {
|
|
75
|
+
invalid(field);
|
|
76
|
+
}
|
|
77
|
+
return encodeURIComponent(normalized);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* GitLab timestamps are ISO 8601, but a date is what a person usually has. A
|
|
81
|
+
* bare date becomes midnight UTC, so "updated after 2026-09-01" is inclusive.
|
|
82
|
+
*/
|
|
83
|
+
function timestamp(value, field) {
|
|
84
|
+
if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/u.test(value.trim())) {
|
|
85
|
+
const parsed = Date.parse(`${value.trim()}T00:00:00Z`);
|
|
86
|
+
if (Number.isNaN(parsed))
|
|
87
|
+
invalid(field);
|
|
88
|
+
return `${value.trim()}T00:00:00Z`;
|
|
89
|
+
}
|
|
90
|
+
const normalized = requiredText(value, field, 10, 40);
|
|
91
|
+
if (Number.isNaN(Date.parse(normalized)))
|
|
92
|
+
invalid(field);
|
|
93
|
+
return normalized;
|
|
94
|
+
}
|
|
95
|
+
function optionalTimestamp(value, field) {
|
|
96
|
+
return value === undefined ? undefined : timestamp(value, field);
|
|
97
|
+
}
|
|
98
|
+
function labels(value, field = "labels") {
|
|
99
|
+
return requiredStringList(value, field, 20, 100).join(",");
|
|
100
|
+
}
|
|
101
|
+
function optionalLabels(value, field = "labels") {
|
|
102
|
+
return value === undefined ? undefined : labels(value, field);
|
|
103
|
+
}
|
|
104
|
+
function requiredIid(value, field) {
|
|
105
|
+
return requiredInteger(value, field);
|
|
106
|
+
}
|
|
107
|
+
/** Page and per-page, capped so one call can never ask for a whole instance. */
|
|
108
|
+
function pagination(input, maxPerPage) {
|
|
109
|
+
return {
|
|
110
|
+
page: optionalInteger(input["page"], "page", 1) ?? 1,
|
|
111
|
+
per_page: optionalInteger(input["perPage"], "perPage", 1, maxPerPage),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function withPagination(query, input, maxPerPage) {
|
|
115
|
+
return { ...query, ...pagination(input, maxPerPage) };
|
|
116
|
+
}
|
|
117
|
+
const LIST_MAX_PER_PAGE = 100;
|
|
118
|
+
/**
|
|
119
|
+
* Search scopes the model may name. GitLab spells code search `blobs`; the
|
|
120
|
+
* catalog only allows the scopes it can actually honour, so a request for
|
|
121
|
+
* advanced search degrades into a refusal instead of a broader search.
|
|
122
|
+
*/
|
|
123
|
+
export const SEARCH_SCOPES = Object.freeze([
|
|
124
|
+
"projects",
|
|
125
|
+
"issues",
|
|
126
|
+
"merge_requests",
|
|
127
|
+
"commits",
|
|
128
|
+
"blobs",
|
|
129
|
+
"notes",
|
|
130
|
+
"users",
|
|
131
|
+
]);
|
|
132
|
+
export const ISSUE_SCOPES = Object.freeze([
|
|
133
|
+
"created_by_me",
|
|
134
|
+
"assigned_to_me",
|
|
135
|
+
"all",
|
|
136
|
+
]);
|
|
137
|
+
export const MR_SCOPES = Object.freeze([
|
|
138
|
+
"created_by_me",
|
|
139
|
+
"assigned_to_me",
|
|
140
|
+
"all",
|
|
141
|
+
"reviews_for_me",
|
|
142
|
+
]);
|
|
143
|
+
function projectPath(template, project) {
|
|
144
|
+
return template.replace(":project", project);
|
|
145
|
+
}
|
|
146
|
+
export const GITLAB_HANDLERS = Object.freeze({
|
|
147
|
+
"connection.get": () => ({ path: "/user", query: {} }),
|
|
148
|
+
"projects.list": (input) => {
|
|
149
|
+
const archived = optionalBoolean(input["archived"], "archived");
|
|
150
|
+
return {
|
|
151
|
+
path: "/projects",
|
|
152
|
+
query: withPagination({
|
|
153
|
+
search: optionalText(input["search"], "search", 1, 200),
|
|
154
|
+
// GitLab only accepts the string "true" for this flag.
|
|
155
|
+
membership: optionalBoolean(input["membership"], "membership") === true
|
|
156
|
+
? "true"
|
|
157
|
+
: undefined,
|
|
158
|
+
archived: archived === undefined ? undefined : String(archived),
|
|
159
|
+
order_by: optionalText(input["orderBy"], "orderBy", 2, 32),
|
|
160
|
+
sort: optionalText(input["sort"], "sort", 3, 4),
|
|
161
|
+
}, input, LIST_MAX_PER_PAGE),
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
"projects.get": (input) => ({
|
|
165
|
+
path: projectPath("/projects/:project", projectRef(input["project"])),
|
|
166
|
+
query: {},
|
|
167
|
+
}),
|
|
168
|
+
"repository.tree": (input) => ({
|
|
169
|
+
path: projectPath("/projects/:project/repository/tree", projectRef(input["project"])),
|
|
170
|
+
query: withPagination({
|
|
171
|
+
path: optionalText(input["path"], "path", 1, 512),
|
|
172
|
+
ref: input["ref"] === undefined ? undefined : refName(input["ref"]),
|
|
173
|
+
// Recursion is allowed but stays paged: the model walks the tree
|
|
174
|
+
// instead of asking for a whole repository in one call.
|
|
175
|
+
recursive: optionalBoolean(input["recursive"], "recursive") === true
|
|
176
|
+
? "true"
|
|
177
|
+
: undefined,
|
|
178
|
+
}, input, LIST_MAX_PER_PAGE),
|
|
179
|
+
}),
|
|
180
|
+
"repository.file": (input) => ({
|
|
181
|
+
path: projectPath(`/projects/:project/repository/files/${filePath(input["path"])}`, projectRef(input["project"])),
|
|
182
|
+
// HEAD makes GitLab resolve the project's default branch itself.
|
|
183
|
+
query: {
|
|
184
|
+
ref: input["ref"] === undefined ? "HEAD" : refName(input["ref"]),
|
|
185
|
+
},
|
|
186
|
+
}),
|
|
187
|
+
"repository.commits": (input) => ({
|
|
188
|
+
path: projectPath("/projects/:project/repository/commits", projectRef(input["project"])),
|
|
189
|
+
query: withPagination({
|
|
190
|
+
ref_name: input["ref"] === undefined ? undefined : refName(input["ref"]),
|
|
191
|
+
path: optionalText(input["path"], "path", 1, 512),
|
|
192
|
+
since: optionalTimestamp(input["since"], "since"),
|
|
193
|
+
until: optionalTimestamp(input["until"], "until"),
|
|
194
|
+
author: optionalText(input["author"], "author", 1, 120),
|
|
195
|
+
}, input, LIST_MAX_PER_PAGE),
|
|
196
|
+
}),
|
|
197
|
+
"repository.commit": (input) => ({
|
|
198
|
+
path: projectPath(`/projects/:project/repository/commits/${commitSha(input["sha"])}`, projectRef(input["project"])),
|
|
199
|
+
query: {
|
|
200
|
+
stats: optionalBoolean(input["stats"], "stats") === false
|
|
201
|
+
? undefined
|
|
202
|
+
: "true",
|
|
203
|
+
},
|
|
204
|
+
}),
|
|
205
|
+
"repository.compare": (input) => ({
|
|
206
|
+
path: projectPath("/projects/:project/repository/compare", projectRef(input["project"])),
|
|
207
|
+
query: {
|
|
208
|
+
from: refName(input["from"], "from"),
|
|
209
|
+
to: refName(input["to"], "to"),
|
|
210
|
+
unidiff: optionalBoolean(input["unidiff"], "unidiff") === true
|
|
211
|
+
? "true"
|
|
212
|
+
: undefined,
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
"search.run": (input, context) => {
|
|
216
|
+
const scope = requiredText(input["scope"], "scope", 3, 32);
|
|
217
|
+
if (!SEARCH_SCOPES.includes(scope))
|
|
218
|
+
invalid("scope");
|
|
219
|
+
const project = input["project"];
|
|
220
|
+
const group = input["group"];
|
|
221
|
+
if (project !== undefined && group !== undefined) {
|
|
222
|
+
throw new IntegrationError("InvalidRequest", "search takes either project or group, not both");
|
|
223
|
+
}
|
|
224
|
+
const path = project !== undefined
|
|
225
|
+
? projectPath("/projects/:project/search", projectRef(project))
|
|
226
|
+
: group !== undefined
|
|
227
|
+
? `/groups/${groupRef(group)}/search`
|
|
228
|
+
: "/search";
|
|
229
|
+
if (scope === "blobs" && project === undefined && group === undefined) {
|
|
230
|
+
throw new IntegrationError("InvalidRequest", "code search needs a project or a group");
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
path,
|
|
234
|
+
query: withPagination({
|
|
235
|
+
scope,
|
|
236
|
+
search: requiredText(input["query"], "query", 1, 200),
|
|
237
|
+
ref: input["ref"] === undefined ? undefined : refName(input["ref"]),
|
|
238
|
+
}, input,
|
|
239
|
+
// Search is the one caller that can drown an answer in one call, so its
|
|
240
|
+
// page size is capped by the deployment switch, not only by GitLab.
|
|
241
|
+
Math.min(LIST_MAX_PER_PAGE, context.flags.maxSearchResults)),
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
"issues.list": (input) => {
|
|
245
|
+
const project = input["project"];
|
|
246
|
+
const scope = optionalText(input["scope"], "scope", 2, 32);
|
|
247
|
+
if (scope !== undefined && !ISSUE_SCOPES.includes(scope))
|
|
248
|
+
invalid("scope");
|
|
249
|
+
return {
|
|
250
|
+
path: project === undefined
|
|
251
|
+
? "/issues"
|
|
252
|
+
: projectPath("/projects/:project/issues", projectRef(project)),
|
|
253
|
+
query: withPagination({
|
|
254
|
+
state: optionalText(input["state"], "state", 3, 10),
|
|
255
|
+
// The global list defaults to "created by me", which hides the very
|
|
256
|
+
// issues a work question is about; the whole surface is "what this
|
|
257
|
+
// token may see" anyway.
|
|
258
|
+
scope: scope ?? (project === undefined ? "all" : undefined),
|
|
259
|
+
assignee_username: optionalText(input["assigneeUsername"], "assigneeUsername", 1, 120),
|
|
260
|
+
author_username: optionalText(input["authorUsername"], "authorUsername", 1, 120),
|
|
261
|
+
labels: optionalLabels(input["labels"]),
|
|
262
|
+
milestone: optionalText(input["milestone"], "milestone", 1, 120),
|
|
263
|
+
search: optionalText(input["search"], "search", 1, 200),
|
|
264
|
+
updated_after: optionalTimestamp(input["updatedAfter"], "updatedAfter"),
|
|
265
|
+
updated_before: optionalTimestamp(input["updatedBefore"], "updatedBefore"),
|
|
266
|
+
}, input, LIST_MAX_PER_PAGE),
|
|
267
|
+
};
|
|
268
|
+
},
|
|
269
|
+
"issues.get": (input) => ({
|
|
270
|
+
path: projectPath(`/projects/:project/issues/${requiredIid(input["iid"], "iid")}`, projectRef(input["project"])),
|
|
271
|
+
query: {},
|
|
272
|
+
}),
|
|
273
|
+
"issues.notes": (input) => ({
|
|
274
|
+
path: projectPath(`/projects/:project/issues/${requiredIid(input["iid"], "iid")}/notes`, projectRef(input["project"])),
|
|
275
|
+
query: withPagination({ sort: optionalText(input["sort"], "sort", 3, 4) }, input, LIST_MAX_PER_PAGE),
|
|
276
|
+
}),
|
|
277
|
+
"mergeRequests.list": (input) => {
|
|
278
|
+
const project = input["project"];
|
|
279
|
+
const scope = optionalText(input["scope"], "scope", 2, 32);
|
|
280
|
+
if (scope !== undefined && !MR_SCOPES.includes(scope))
|
|
281
|
+
invalid("scope");
|
|
282
|
+
return {
|
|
283
|
+
path: project === undefined
|
|
284
|
+
? "/merge_requests"
|
|
285
|
+
: projectPath("/projects/:project/merge_requests", projectRef(project)),
|
|
286
|
+
query: withPagination({
|
|
287
|
+
state: optionalText(input["state"], "state", 3, 10),
|
|
288
|
+
// As with issues: "created by me" is GitLab's default and almost
|
|
289
|
+
// never the question being asked.
|
|
290
|
+
scope: scope ?? (project === undefined ? "all" : undefined),
|
|
291
|
+
source_branch: optionalText(input["sourceBranch"], "sourceBranch", 1, 255),
|
|
292
|
+
target_branch: optionalText(input["targetBranch"], "targetBranch", 1, 255),
|
|
293
|
+
author_username: optionalText(input["authorUsername"], "authorUsername", 1, 120),
|
|
294
|
+
assignee_username: optionalText(input["assigneeUsername"], "assigneeUsername", 1, 120),
|
|
295
|
+
reviewer_username: optionalText(input["reviewerUsername"], "reviewerUsername", 1, 120),
|
|
296
|
+
labels: optionalLabels(input["labels"]),
|
|
297
|
+
search: optionalText(input["search"], "search", 1, 200),
|
|
298
|
+
draft: optionalBoolean(input["draft"], "draft"),
|
|
299
|
+
updated_after: optionalTimestamp(input["updatedAfter"], "updatedAfter"),
|
|
300
|
+
updated_before: optionalTimestamp(input["updatedBefore"], "updatedBefore"),
|
|
301
|
+
}, input, LIST_MAX_PER_PAGE),
|
|
302
|
+
};
|
|
303
|
+
},
|
|
304
|
+
"mergeRequests.get": (input) => ({
|
|
305
|
+
path: projectPath(`/projects/:project/merge_requests/${requiredIid(input["iid"], "iid")}`, projectRef(input["project"])),
|
|
306
|
+
query: {},
|
|
307
|
+
}),
|
|
308
|
+
"mergeRequests.changes": (input) => ({
|
|
309
|
+
path: projectPath(`/projects/:project/merge_requests/${requiredIid(input["iid"], "iid")}/diffs`, projectRef(input["project"])),
|
|
310
|
+
query: withPagination({
|
|
311
|
+
unidiff: optionalBoolean(input["unidiff"], "unidiff") === true
|
|
312
|
+
? "true"
|
|
313
|
+
: undefined,
|
|
314
|
+
}, input, LIST_MAX_PER_PAGE),
|
|
315
|
+
}),
|
|
316
|
+
"mergeRequests.discussions": (input) => ({
|
|
317
|
+
path: projectPath(`/projects/:project/merge_requests/${requiredIid(input["iid"], "iid")}/discussions`, projectRef(input["project"])),
|
|
318
|
+
query: withPagination({}, input, LIST_MAX_PER_PAGE),
|
|
319
|
+
}),
|
|
320
|
+
"mergeRequests.approvals": (input) => ({
|
|
321
|
+
path: projectPath(`/projects/:project/merge_requests/${requiredIid(input["iid"], "iid")}/approvals`, projectRef(input["project"])),
|
|
322
|
+
query: {},
|
|
323
|
+
}),
|
|
324
|
+
"mergeRequests.pipelines": (input) => ({
|
|
325
|
+
path: projectPath(`/projects/:project/merge_requests/${requiredIid(input["iid"], "iid")}/pipelines`, projectRef(input["project"])),
|
|
326
|
+
query: withPagination({}, input, LIST_MAX_PER_PAGE),
|
|
327
|
+
}),
|
|
328
|
+
"pipelines.list": (input) => ({
|
|
329
|
+
path: projectPath("/projects/:project/pipelines", projectRef(input["project"])),
|
|
330
|
+
query: withPagination({
|
|
331
|
+
ref: input["ref"] === undefined ? undefined : refName(input["ref"]),
|
|
332
|
+
status: optionalText(input["status"], "status", 3, 32),
|
|
333
|
+
source: optionalText(input["source"], "source", 3, 32),
|
|
334
|
+
username: optionalText(input["username"], "username", 1, 120),
|
|
335
|
+
updated_after: optionalTimestamp(input["updatedAfter"], "updatedAfter"),
|
|
336
|
+
updated_before: optionalTimestamp(input["updatedBefore"], "updatedBefore"),
|
|
337
|
+
}, input, LIST_MAX_PER_PAGE),
|
|
338
|
+
}),
|
|
339
|
+
"pipelines.get": (input) => ({
|
|
340
|
+
path: projectPath(`/projects/:project/pipelines/${requiredInteger(input["pipelineId"], "pipelineId")}`, projectRef(input["project"])),
|
|
341
|
+
query: {},
|
|
342
|
+
}),
|
|
343
|
+
"pipelines.jobs": (input) => ({
|
|
344
|
+
path: projectPath(`/projects/:project/pipelines/${requiredInteger(input["pipelineId"], "pipelineId")}/jobs`, projectRef(input["project"])),
|
|
345
|
+
query: withPagination({
|
|
346
|
+
// GitLab takes repeated `scope[]` values; one status is enough for a
|
|
347
|
+
// readable answer and keeps the query bounded.
|
|
348
|
+
"scope[]": input["status"] === undefined
|
|
349
|
+
? undefined
|
|
350
|
+
: requiredText(input["status"], "status", 3, 32),
|
|
351
|
+
include_retried: optionalBoolean(input["includeRetried"], "includeRetried") === true
|
|
352
|
+
? "true"
|
|
353
|
+
: undefined,
|
|
354
|
+
}, input, LIST_MAX_PER_PAGE),
|
|
355
|
+
}),
|
|
356
|
+
"jobs.get": (input) => ({
|
|
357
|
+
path: projectPath(`/projects/:project/jobs/${requiredInteger(input["jobId"], "jobId")}`, projectRef(input["project"])),
|
|
358
|
+
query: {},
|
|
359
|
+
}),
|
|
360
|
+
"jobs.log": (input) => ({
|
|
361
|
+
path: projectPath(`/projects/:project/jobs/${requiredInteger(input["jobId"], "jobId")}/trace`, projectRef(input["project"])),
|
|
362
|
+
query: {},
|
|
363
|
+
}),
|
|
364
|
+
});
|
|
365
|
+
/* ------------------------------------------------------------------ */
|
|
366
|
+
/* Response shaping */
|
|
367
|
+
/* ------------------------------------------------------------------ */
|
|
368
|
+
/** A NUL byte in the head of a body is the classic text/binary split. */
|
|
369
|
+
function looksBinary(bytes) {
|
|
370
|
+
for (const byte of bytes.subarray(0, 8_192)) {
|
|
371
|
+
if (byte === 0)
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
function recordOf(value) {
|
|
377
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
378
|
+
? value
|
|
379
|
+
: {};
|
|
380
|
+
}
|
|
381
|
+
function stringOf(source, key) {
|
|
382
|
+
const value = source[key];
|
|
383
|
+
return typeof value === "string" ? value : undefined;
|
|
384
|
+
}
|
|
385
|
+
function numberOf(source, key) {
|
|
386
|
+
const value = source[key];
|
|
387
|
+
return typeof value === "number" && Number.isFinite(value)
|
|
388
|
+
? value
|
|
389
|
+
: undefined;
|
|
390
|
+
}
|
|
391
|
+
function booleanOf(source, key) {
|
|
392
|
+
const value = source[key];
|
|
393
|
+
return typeof value === "boolean" ? value : undefined;
|
|
394
|
+
}
|
|
395
|
+
function arrayOf(source, key) {
|
|
396
|
+
const value = source[key];
|
|
397
|
+
return Array.isArray(value) ? value : [];
|
|
398
|
+
}
|
|
399
|
+
/** Drop unset keys so a projection never answers with `undefined` holes. */
|
|
400
|
+
function compact(source) {
|
|
401
|
+
return Object.fromEntries(Object.entries(source).filter(([, value]) => value !== undefined));
|
|
402
|
+
}
|
|
403
|
+
function userSummary(value) {
|
|
404
|
+
const source = recordOf(value);
|
|
405
|
+
const id = numberOf(source, "id");
|
|
406
|
+
if (id === undefined)
|
|
407
|
+
return undefined;
|
|
408
|
+
return compact({
|
|
409
|
+
id,
|
|
410
|
+
username: stringOf(source, "username"),
|
|
411
|
+
name: stringOf(source, "name"),
|
|
412
|
+
webUrl: stringOf(source, "web_url"),
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
function userSummaries(source, key) {
|
|
416
|
+
return arrayOf(source, key)
|
|
417
|
+
.map((item) => userSummary(item))
|
|
418
|
+
.filter((item) => item !== undefined);
|
|
419
|
+
}
|
|
420
|
+
function projectSummary(value) {
|
|
421
|
+
const source = recordOf(value);
|
|
422
|
+
return compact({
|
|
423
|
+
id: numberOf(source, "id"),
|
|
424
|
+
pathWithNamespace: stringOf(source, "path_with_namespace"),
|
|
425
|
+
name: stringOf(source, "name"),
|
|
426
|
+
description: stringOf(source, "description"),
|
|
427
|
+
defaultBranch: stringOf(source, "default_branch"),
|
|
428
|
+
archived: booleanOf(source, "archived"),
|
|
429
|
+
visibility: stringOf(source, "visibility"),
|
|
430
|
+
webUrl: stringOf(source, "web_url"),
|
|
431
|
+
lastActivityAt: stringOf(source, "last_activity_at"),
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
function issueSummary(value) {
|
|
435
|
+
const source = recordOf(value);
|
|
436
|
+
return compact({
|
|
437
|
+
projectId: numberOf(source, "project_id"),
|
|
438
|
+
iid: numberOf(source, "iid"),
|
|
439
|
+
title: stringOf(source, "title"),
|
|
440
|
+
state: stringOf(source, "state"),
|
|
441
|
+
confidential: booleanOf(source, "confidential"),
|
|
442
|
+
labels: arrayOf(source, "labels"),
|
|
443
|
+
author: userSummary(source["author"]),
|
|
444
|
+
assignees: userSummaries(source, "assignees"),
|
|
445
|
+
webUrl: stringOf(source, "web_url"),
|
|
446
|
+
createdAt: stringOf(source, "created_at"),
|
|
447
|
+
updatedAt: stringOf(source, "updated_at"),
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
function mergeRequestSummary(value) {
|
|
451
|
+
const source = recordOf(value);
|
|
452
|
+
return compact({
|
|
453
|
+
projectId: numberOf(source, "project_id"),
|
|
454
|
+
iid: numberOf(source, "iid"),
|
|
455
|
+
title: stringOf(source, "title"),
|
|
456
|
+
state: stringOf(source, "state"),
|
|
457
|
+
draft: booleanOf(source, "draft"),
|
|
458
|
+
sourceBranch: stringOf(source, "source_branch"),
|
|
459
|
+
targetBranch: stringOf(source, "target_branch"),
|
|
460
|
+
author: userSummary(source["author"]),
|
|
461
|
+
assignees: userSummaries(source, "assignees"),
|
|
462
|
+
reviewers: userSummaries(source, "reviewers"),
|
|
463
|
+
webUrl: stringOf(source, "web_url"),
|
|
464
|
+
createdAt: stringOf(source, "created_at"),
|
|
465
|
+
updatedAt: stringOf(source, "updated_at"),
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
function pipelineSummary(value) {
|
|
469
|
+
const source = recordOf(value);
|
|
470
|
+
return compact({
|
|
471
|
+
id: numberOf(source, "id"),
|
|
472
|
+
iid: numberOf(source, "iid"),
|
|
473
|
+
projectId: numberOf(source, "project_id"),
|
|
474
|
+
status: stringOf(source, "status"),
|
|
475
|
+
source: stringOf(source, "source"),
|
|
476
|
+
ref: stringOf(source, "ref"),
|
|
477
|
+
sha: stringOf(source, "sha"),
|
|
478
|
+
webUrl: stringOf(source, "web_url"),
|
|
479
|
+
createdAt: stringOf(source, "created_at"),
|
|
480
|
+
updatedAt: stringOf(source, "updated_at"),
|
|
481
|
+
username: stringOf(source, "username"),
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
function jobSummary(value) {
|
|
485
|
+
const source = recordOf(value);
|
|
486
|
+
return compact({
|
|
487
|
+
id: numberOf(source, "id"),
|
|
488
|
+
name: stringOf(source, "name"),
|
|
489
|
+
stage: stringOf(source, "stage"),
|
|
490
|
+
status: stringOf(source, "status"),
|
|
491
|
+
ref: stringOf(source, "ref"),
|
|
492
|
+
allowFailure: booleanOf(source, "allow_failure"),
|
|
493
|
+
failureReason: stringOf(source, "failure_reason"),
|
|
494
|
+
duration: numberOf(source, "duration"),
|
|
495
|
+
queuedDuration: numberOf(source, "queued_duration"),
|
|
496
|
+
createdAt: stringOf(source, "created_at"),
|
|
497
|
+
startedAt: stringOf(source, "started_at"),
|
|
498
|
+
finishedAt: stringOf(source, "finished_at"),
|
|
499
|
+
webUrl: stringOf(source, "web_url"),
|
|
500
|
+
user: userSummary(source["user"]),
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
function commitSummary(value) {
|
|
504
|
+
const source = recordOf(value);
|
|
505
|
+
return compact({
|
|
506
|
+
id: stringOf(source, "id"),
|
|
507
|
+
shortId: stringOf(source, "short_id"),
|
|
508
|
+
title: stringOf(source, "title"),
|
|
509
|
+
authorName: stringOf(source, "author_name"),
|
|
510
|
+
authoredDate: stringOf(source, "authored_date"),
|
|
511
|
+
committerName: stringOf(source, "committer_name"),
|
|
512
|
+
webUrl: stringOf(source, "web_url"),
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* One file of a diff. The diff text is what makes a comparison useful and what
|
|
517
|
+
* makes it enormous, so callers spend a shared character budget on it and keep
|
|
518
|
+
* every path even after the budget runs out.
|
|
519
|
+
*/
|
|
520
|
+
function diffEntry(value, budget) {
|
|
521
|
+
const source = recordOf(value);
|
|
522
|
+
const diff = stringOf(source, "diff");
|
|
523
|
+
const partial = diff !== undefined && diff.length > budget.left;
|
|
524
|
+
const kept = diff === undefined ? undefined : diff.slice(0, budget.left);
|
|
525
|
+
budget.left -= kept?.length ?? 0;
|
|
526
|
+
return compact({
|
|
527
|
+
oldPath: stringOf(source, "old_path"),
|
|
528
|
+
newPath: stringOf(source, "new_path"),
|
|
529
|
+
newFile: booleanOf(source, "new_file"),
|
|
530
|
+
renamedFile: booleanOf(source, "renamed_file"),
|
|
531
|
+
deletedFile: booleanOf(source, "deleted_file"),
|
|
532
|
+
tooLarge: booleanOf(source, "too_large"),
|
|
533
|
+
collapsed: booleanOf(source, "collapsed"),
|
|
534
|
+
diff: kept,
|
|
535
|
+
diffTruncated: partial ? true : undefined,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
function diffsWithin(values, maxChars) {
|
|
539
|
+
const budget = { left: maxChars };
|
|
540
|
+
const items = values.map((value) => diffEntry(value, budget));
|
|
541
|
+
return {
|
|
542
|
+
items,
|
|
543
|
+
truncated: items.some((item) => item["diffTruncated"] === true),
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
function noteSummary(value) {
|
|
547
|
+
const source = recordOf(value);
|
|
548
|
+
return compact({
|
|
549
|
+
id: numberOf(source, "id"),
|
|
550
|
+
body: stringOf(source, "body"),
|
|
551
|
+
author: userSummary(source["author"]),
|
|
552
|
+
system: booleanOf(source, "system"),
|
|
553
|
+
internal: booleanOf(source, "internal"),
|
|
554
|
+
resolvable: booleanOf(source, "resolvable"),
|
|
555
|
+
resolved: booleanOf(source, "resolved"),
|
|
556
|
+
createdAt: stringOf(source, "created_at"),
|
|
557
|
+
updatedAt: stringOf(source, "updated_at"),
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
function projectDetail(value) {
|
|
561
|
+
const source = recordOf(value);
|
|
562
|
+
const namespace = recordOf(source["namespace"]);
|
|
563
|
+
return compact({
|
|
564
|
+
...projectSummary(source),
|
|
565
|
+
topics: arrayOf(source, "topics"),
|
|
566
|
+
createdAt: stringOf(source, "created_at"),
|
|
567
|
+
namespace: compact({
|
|
568
|
+
id: numberOf(namespace, "id"),
|
|
569
|
+
fullPath: stringOf(namespace, "full_path"),
|
|
570
|
+
kind: stringOf(namespace, "kind"),
|
|
571
|
+
}),
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function issueDetail(value) {
|
|
575
|
+
const source = recordOf(value);
|
|
576
|
+
const milestone = recordOf(source["milestone"]);
|
|
577
|
+
return compact({
|
|
578
|
+
...issueSummary(source),
|
|
579
|
+
description: stringOf(source, "description"),
|
|
580
|
+
milestone: compact({
|
|
581
|
+
id: numberOf(milestone, "id"),
|
|
582
|
+
title: stringOf(milestone, "title"),
|
|
583
|
+
}),
|
|
584
|
+
dueDate: stringOf(source, "due_date"),
|
|
585
|
+
closedAt: stringOf(source, "closed_at"),
|
|
586
|
+
closedBy: userSummary(source["closed_by"]),
|
|
587
|
+
userNotesCount: numberOf(source, "user_notes_count"),
|
|
588
|
+
reference: stringOf(source, "references") === undefined
|
|
589
|
+
? undefined
|
|
590
|
+
: stringOf(recordOf(source["references"]), "full"),
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
function mergeRequestDetail(value) {
|
|
594
|
+
const source = recordOf(value);
|
|
595
|
+
const milestone = recordOf(source["milestone"]);
|
|
596
|
+
return compact({
|
|
597
|
+
...mergeRequestSummary(source),
|
|
598
|
+
description: stringOf(source, "description"),
|
|
599
|
+
mergeStatus: stringOf(source, "merge_status"),
|
|
600
|
+
detailedMergeStatus: stringOf(source, "detailed_merge_status"),
|
|
601
|
+
hasConflicts: booleanOf(source, "has_conflicts"),
|
|
602
|
+
blockingDiscussionsResolved: booleanOf(source, "blocking_discussions_resolved"),
|
|
603
|
+
labels: arrayOf(source, "labels"),
|
|
604
|
+
milestone: compact({
|
|
605
|
+
id: numberOf(milestone, "id"),
|
|
606
|
+
title: stringOf(milestone, "title"),
|
|
607
|
+
}),
|
|
608
|
+
userNotesCount: numberOf(source, "user_notes_count"),
|
|
609
|
+
sha: stringOf(source, "sha"),
|
|
610
|
+
sourceProjectId: numberOf(source, "source_project_id"),
|
|
611
|
+
targetProjectId: numberOf(source, "target_project_id"),
|
|
612
|
+
reference: stringOf(recordOf(source["references"]), "full"),
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
/** Character budget for the diff text of one comparison or change listing. */
|
|
616
|
+
const DIFF_BUDGET = 200_000;
|
|
617
|
+
export const GITLAB_PROJECTIONS = Object.freeze({
|
|
618
|
+
"connection.get": (data) => {
|
|
619
|
+
const source = recordOf(data);
|
|
620
|
+
return compact({
|
|
621
|
+
id: numberOf(source, "id"),
|
|
622
|
+
username: stringOf(source, "username"),
|
|
623
|
+
name: stringOf(source, "name"),
|
|
624
|
+
state: stringOf(source, "state"),
|
|
625
|
+
webUrl: stringOf(source, "web_url"),
|
|
626
|
+
});
|
|
627
|
+
},
|
|
628
|
+
"projects.list": (data) => (Array.isArray(data) ? data : []).map(projectSummary),
|
|
629
|
+
"projects.get": projectDetail,
|
|
630
|
+
"repository.tree": (data) => (Array.isArray(data) ? data : []).map((item) => {
|
|
631
|
+
const source = recordOf(item);
|
|
632
|
+
return compact({
|
|
633
|
+
id: stringOf(source, "id"),
|
|
634
|
+
name: stringOf(source, "name"),
|
|
635
|
+
type: stringOf(source, "type"),
|
|
636
|
+
path: stringOf(source, "path"),
|
|
637
|
+
mode: stringOf(source, "mode"),
|
|
638
|
+
});
|
|
639
|
+
}),
|
|
640
|
+
"repository.file": (data, context) => {
|
|
641
|
+
const source = recordOf(data);
|
|
642
|
+
const encoding = stringOf(source, "encoding") ?? "base64";
|
|
643
|
+
const raw = stringOf(source, "content") ?? "";
|
|
644
|
+
const bytes = Buffer.from(raw, encoding === "base64" ? "base64" : "utf8");
|
|
645
|
+
const binary = looksBinary(bytes);
|
|
646
|
+
// The body is what makes a file read useful and what makes it huge: keep
|
|
647
|
+
// a bounded prefix and say so rather than dropping the answer entirely.
|
|
648
|
+
const limit = context.byteLimit ?? bytes.byteLength;
|
|
649
|
+
const truncated = !binary && bytes.byteLength > limit;
|
|
650
|
+
return compact({
|
|
651
|
+
fileName: stringOf(source, "file_name"),
|
|
652
|
+
filePath: stringOf(source, "file_path"),
|
|
653
|
+
ref: stringOf(source, "ref"),
|
|
654
|
+
size: numberOf(source, "size"),
|
|
655
|
+
encoding,
|
|
656
|
+
blobId: stringOf(source, "blob_id"),
|
|
657
|
+
lastCommitId: stringOf(source, "last_commit_id"),
|
|
658
|
+
binary: binary ? true : undefined,
|
|
659
|
+
truncated: truncated ? true : undefined,
|
|
660
|
+
content: binary ? undefined : bytes.subarray(0, limit).toString("utf8"),
|
|
661
|
+
});
|
|
662
|
+
},
|
|
663
|
+
"repository.commits": (data) => (Array.isArray(data) ? data : []).map(commitSummary),
|
|
664
|
+
"repository.commit": (data) => {
|
|
665
|
+
const source = recordOf(data);
|
|
666
|
+
const stats = recordOf(source["stats"]);
|
|
667
|
+
return compact({
|
|
668
|
+
id: stringOf(source, "id"),
|
|
669
|
+
shortId: stringOf(source, "short_id"),
|
|
670
|
+
title: stringOf(source, "title"),
|
|
671
|
+
message: stringOf(source, "message"),
|
|
672
|
+
authorName: stringOf(source, "author_name"),
|
|
673
|
+
authorEmail: stringOf(source, "author_email"),
|
|
674
|
+
authoredDate: stringOf(source, "authored_date"),
|
|
675
|
+
committerName: stringOf(source, "committer_name"),
|
|
676
|
+
committedDate: stringOf(source, "committed_date"),
|
|
677
|
+
parentIds: arrayOf(source, "parent_ids"),
|
|
678
|
+
webUrl: stringOf(source, "web_url"),
|
|
679
|
+
stats: compact({
|
|
680
|
+
additions: numberOf(stats, "additions"),
|
|
681
|
+
deletions: numberOf(stats, "deletions"),
|
|
682
|
+
total: numberOf(stats, "total"),
|
|
683
|
+
}),
|
|
684
|
+
});
|
|
685
|
+
},
|
|
686
|
+
"repository.compare": (data) => {
|
|
687
|
+
const source = recordOf(data);
|
|
688
|
+
const diffs = diffsWithin(arrayOf(source, "diffs"), DIFF_BUDGET);
|
|
689
|
+
return compact({
|
|
690
|
+
commit: commitSummary(source["commit"]),
|
|
691
|
+
commits: arrayOf(source, "commits").map(commitSummary),
|
|
692
|
+
diffs: diffs.items,
|
|
693
|
+
diffTruncated: diffs.truncated ? true : undefined,
|
|
694
|
+
});
|
|
695
|
+
},
|
|
696
|
+
"search.run": (data) => (Array.isArray(data) ? data : []).map((item) => {
|
|
697
|
+
const source = recordOf(item);
|
|
698
|
+
return compact({
|
|
699
|
+
// Search answers differ per scope, so both shapes are projected onto
|
|
700
|
+
// one object with the fields a follow-up call needs.
|
|
701
|
+
id: numberOf(source, "id"),
|
|
702
|
+
iid: numberOf(source, "iid"),
|
|
703
|
+
projectId: numberOf(source, "project_id"),
|
|
704
|
+
title: stringOf(source, "title"),
|
|
705
|
+
name: stringOf(source, "name"),
|
|
706
|
+
path: stringOf(source, "path"),
|
|
707
|
+
filename: stringOf(source, "filename"),
|
|
708
|
+
ref: stringOf(source, "ref"),
|
|
709
|
+
startline: numberOf(source, "startline"),
|
|
710
|
+
data: stringOf(source, "data"),
|
|
711
|
+
webUrl: stringOf(source, "web_url"),
|
|
712
|
+
snippet: stringOf(source, "snippet"),
|
|
713
|
+
});
|
|
714
|
+
}),
|
|
715
|
+
"issues.list": (data) => (Array.isArray(data) ? data : []).map(issueSummary),
|
|
716
|
+
"issues.get": issueDetail,
|
|
717
|
+
"issues.notes": (data) => (Array.isArray(data) ? data : []).map(noteSummary),
|
|
718
|
+
"mergeRequests.list": (data) => (Array.isArray(data) ? data : []).map(mergeRequestSummary),
|
|
719
|
+
"mergeRequests.get": mergeRequestDetail,
|
|
720
|
+
"mergeRequests.changes": (data) => {
|
|
721
|
+
const diffs = diffsWithin(Array.isArray(data) ? data : [], DIFF_BUDGET);
|
|
722
|
+
return compact({
|
|
723
|
+
items: diffs.items,
|
|
724
|
+
diffTruncated: diffs.truncated ? true : undefined,
|
|
725
|
+
});
|
|
726
|
+
},
|
|
727
|
+
"mergeRequests.discussions": (data) => (Array.isArray(data) ? data : []).map((item) => {
|
|
728
|
+
const source = recordOf(item);
|
|
729
|
+
return compact({
|
|
730
|
+
id: stringOf(source, "id"),
|
|
731
|
+
individualNote: booleanOf(source, "individual_note"),
|
|
732
|
+
resolved: booleanOf(source, "resolved"),
|
|
733
|
+
notes: arrayOf(source, "notes").map(noteSummary),
|
|
734
|
+
});
|
|
735
|
+
}),
|
|
736
|
+
"mergeRequests.approvals": (data) => {
|
|
737
|
+
const source = recordOf(data);
|
|
738
|
+
return compact({
|
|
739
|
+
approved: booleanOf(source, "approved"),
|
|
740
|
+
approvalsRequired: numberOf(source, "approvals_required"),
|
|
741
|
+
approvalsLeft: numberOf(source, "approvals_left"),
|
|
742
|
+
userHasApproved: booleanOf(source, "user_has_approved"),
|
|
743
|
+
userCanApprove: booleanOf(source, "user_can_approve"),
|
|
744
|
+
approvedBy: arrayOf(source, "approved_by")
|
|
745
|
+
.map((item) => userSummary(recordOf(item)["user"]))
|
|
746
|
+
.filter((item) => item !== undefined),
|
|
747
|
+
});
|
|
748
|
+
},
|
|
749
|
+
"mergeRequests.pipelines": (data) => (Array.isArray(data) ? data : []).map(pipelineSummary),
|
|
750
|
+
"pipelines.list": (data) => (Array.isArray(data) ? data : []).map(pipelineSummary),
|
|
751
|
+
"pipelines.get": (data) => {
|
|
752
|
+
const source = recordOf(data);
|
|
753
|
+
return compact({
|
|
754
|
+
...pipelineSummary(source),
|
|
755
|
+
duration: numberOf(source, "duration"),
|
|
756
|
+
queuedDuration: numberOf(source, "queued_duration"),
|
|
757
|
+
startedAt: stringOf(source, "started_at"),
|
|
758
|
+
finishedAt: stringOf(source, "finished_at"),
|
|
759
|
+
coverage: stringOf(source, "coverage"),
|
|
760
|
+
detailedStatus: stringOf(source, "detailed_status") === undefined
|
|
761
|
+
? undefined
|
|
762
|
+
: stringOf(recordOf(source["detailed_status"]), "label"),
|
|
763
|
+
});
|
|
764
|
+
},
|
|
765
|
+
"pipelines.jobs": (data) => (Array.isArray(data) ? data : []).map(jobSummary),
|
|
766
|
+
"jobs.get": (data) => {
|
|
767
|
+
const source = recordOf(data);
|
|
768
|
+
const pipeline = recordOf(source["pipeline"]);
|
|
769
|
+
return compact({
|
|
770
|
+
...jobSummary(source),
|
|
771
|
+
tagList: arrayOf(source, "tag_list"),
|
|
772
|
+
pipelineId: numberOf(pipeline, "id"),
|
|
773
|
+
artifacts: arrayOf(source, "artifacts").map((item) => {
|
|
774
|
+
const artifact = recordOf(item);
|
|
775
|
+
return compact({
|
|
776
|
+
fileType: stringOf(artifact, "file_type"),
|
|
777
|
+
filename: stringOf(artifact, "filename"),
|
|
778
|
+
size: numberOf(artifact, "size"),
|
|
779
|
+
});
|
|
780
|
+
}),
|
|
781
|
+
});
|
|
782
|
+
},
|
|
783
|
+
});
|
|
784
|
+
/** Byte size of a project's file that this deployment is willing to hand over. */
|
|
785
|
+
export function fileByteLimit(requested, flags) {
|
|
786
|
+
const asked = optionalInteger(requested, "maxBytes", 1_024, 4_194_304);
|
|
787
|
+
return Math.min(asked ?? flags.maxFileBytes, flags.maxFileBytes);
|
|
788
|
+
}
|
|
789
|
+
/** Byte size of a job log this deployment is willing to hand over. */
|
|
790
|
+
export function jobLogByteLimit(requested, flags) {
|
|
791
|
+
const asked = optionalInteger(requested, "maxBytes", 1_024, 4_194_304);
|
|
792
|
+
return Math.min(asked ?? flags.maxJobLogBytes, flags.maxJobLogBytes);
|
|
793
|
+
}
|
|
794
|
+
//# sourceMappingURL=operations.js.map
|