@vite-hub/workspace 0.0.4 → 0.1.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/README.md +225 -58
- package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
- package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +57 -36
- package/dist/index.js +56 -56
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +4 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/path-CNAwN7pw.js +114 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
- package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
- package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +7 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- package/dist/runtime/state.d.ts +3 -3
- package/dist/runtime/state.js +6 -6
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +51 -17
- package/dist/runtime.js +320 -60
- package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -328
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +6 -7
- package/dist/source-metadata.js +7 -7
- package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
- package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
- package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
- package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
- package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
- package/package.json +89 -55
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-Bc3c4Su1.js +0 -7904
- package/dist/config-CHLLWklZ.js +0 -36
- package/dist/file-Bc1X7pco.js +0 -23
- package/dist/glob-CEZKeZFC.js +0 -18
- package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
- package/dist/lifecycle-LrL3sA4n.js +0 -316
- package/dist/metadata-target-B0tOmVW7.js +0 -717
- package/dist/path-Cp59koVz.js +0 -139
- package/dist/provider-B1yLjCJJ.js +0 -746
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
|
@@ -0,0 +1,2530 @@
|
|
|
1
|
+
import { At as resolveToken, B as TokenRevokedError, Ct as rateLimitPart, Dt as requireIssueOrPull, E as BranchMovedError, F as NotFoundError, Ft as teamOrg, H as UnsupportedOperationError, Ht as versionAtLeast, It as toDate, M as InsufficientScopeError, Mt as soleMergeMethod, O as ForbiddenError, Ot as requireThread, Pt as syntheticReview, Q as firstPageEtag, Rt as toMergeError, T as AuthenticationRequiredError, Tt as reactionContent, Ut as webUrlFor, V as UnresolvedThreadError, Vt as toWarning, Wt as withEtag, Y as createListing, Z as degradesToWarning, _t as milestoneId, at as isFirstPage, bt as phased, et as getManyConcurrently, ft as lineOf, gt as mergeCommitMessage, ht as memoBy, k as ForgeApiError, mt as memo, ot as isNamespaceRef, pt as mapConcurrent, rt as hexColour, ut as iteratePages, xt as rangeOf, zt as toPage } from "./shared-DalXdP0i.js";
|
|
2
|
+
import { C as toFileContent, E as verifySharedToken, c as existingFiles, h as perKind, i as defineForgeProvider, m as nativeEventsFor, o as eventKindsOf, r as changeBase64, s as eventTime, t as WRITE_VERBS, u as fromBase64, w as verb } from "./webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js";
|
|
3
|
+
//#region ../forge/dist/gitlab-BoDm8-BC.js
|
|
4
|
+
const SECTIONS = {
|
|
5
|
+
issue: "work_items",
|
|
6
|
+
pull_request: "merge_requests"
|
|
7
|
+
};
|
|
8
|
+
const KINDS = new Map([
|
|
9
|
+
...Object.entries(SECTIONS).map(([kind, section]) => [section, kind]),
|
|
10
|
+
["issues", "issue"],
|
|
11
|
+
["work_items", "issue"]
|
|
12
|
+
]);
|
|
13
|
+
const PREFIXES = {
|
|
14
|
+
issue: "#",
|
|
15
|
+
pull_request: "!"
|
|
16
|
+
};
|
|
17
|
+
const PAGES = {
|
|
18
|
+
issues: "work_items",
|
|
19
|
+
pullRequests: "merge_requests",
|
|
20
|
+
compare: "compare",
|
|
21
|
+
releases: "releases",
|
|
22
|
+
stargazers: "starrers",
|
|
23
|
+
forks: "forks"
|
|
24
|
+
};
|
|
25
|
+
const GROUP_PAGES = {
|
|
26
|
+
issues: "work_items",
|
|
27
|
+
pullRequests: "merge_requests"
|
|
28
|
+
};
|
|
29
|
+
const REFERENCES = {
|
|
30
|
+
threads: [{
|
|
31
|
+
prefix: "#",
|
|
32
|
+
kind: "issue"
|
|
33
|
+
}, {
|
|
34
|
+
prefix: "!",
|
|
35
|
+
kind: "pull_request"
|
|
36
|
+
}],
|
|
37
|
+
repo: String.raw`(?:[\w.-]+\/)+[\w.-]+`,
|
|
38
|
+
suffix: String.raw`\+s?`,
|
|
39
|
+
commits: true
|
|
40
|
+
};
|
|
41
|
+
const encode = (path) => path.split("/").map(encodeURIComponent).join("/");
|
|
42
|
+
const projectPath = (repo) => `/${encode(repo.owner)}/${encodeURIComponent(repo.name)}`;
|
|
43
|
+
function gitlabWeb(baseUrl) {
|
|
44
|
+
return {
|
|
45
|
+
baseUrl,
|
|
46
|
+
repo: (repo) => repo.kind === "namespace" ? `/${encode(repo.owner)}` : projectPath(repo),
|
|
47
|
+
section: (repo, section) => repo.kind === "namespace" ? GROUP_PAGES[section] && `/groups/${encode(repo.owner)}/-/${GROUP_PAGES[section]}` : PAGES[section] && `${projectPath(repo)}/-/${PAGES[section]}`,
|
|
48
|
+
thread: (ref) => ref.repo.kind === "namespace" || !SECTIONS[ref.kind] ? void 0 : `${projectPath(ref.repo)}/-/${SECTIONS[ref.kind]}/${encodeURIComponent(ref.number)}`,
|
|
49
|
+
comment: (ref) => ref.thread.repo.kind === "namespace" || !SECTIONS[ref.thread.kind] ? void 0 : `${projectPath(ref.thread.repo)}/-/${SECTIONS[ref.thread.kind]}/${encodeURIComponent(ref.thread.number)}#note_${ref.id}`,
|
|
50
|
+
commit: (repo, sha) => repo.kind === "namespace" ? void 0 : `${projectPath(repo)}/-/commit/${encodeURIComponent(sha)}`,
|
|
51
|
+
release: (ref) => ref.tag ? `${projectPath(ref.repo)}/-/releases/${encodeURIComponent(ref.tag)}` : void 0,
|
|
52
|
+
file: (repo, path, at, line) => `${projectPath(repo)}/-/blob/${encodeURIComponent(at)}/${encode(path)}${line ? `#L${line}` : ""}`,
|
|
53
|
+
raw: (repo, path, at) => `${projectPath(repo)}/-/raw/${encodeURIComponent(at)}/${encode(path)}`,
|
|
54
|
+
compare: (repo, base, head) => `${projectPath(repo)}/-/compare/${encodeURIComponent(base)}...${encodeURIComponent(head)}`,
|
|
55
|
+
parse: (segments, url, from) => {
|
|
56
|
+
const separator = segments.indexOf("-");
|
|
57
|
+
const path = separator < 0 ? segments : segments.slice(0, separator);
|
|
58
|
+
if (path.length < 2) return;
|
|
59
|
+
const repo = {
|
|
60
|
+
...from,
|
|
61
|
+
owner: path.slice(0, -1).join("/"),
|
|
62
|
+
name: path.at(-1).replace(/\.git$/, "")
|
|
63
|
+
};
|
|
64
|
+
const [section, id] = separator < 0 ? [] : segments.slice(separator + 1);
|
|
65
|
+
if (section === "blob" && id && segments.length > separator + 3) return {
|
|
66
|
+
repo,
|
|
67
|
+
file: {
|
|
68
|
+
at: id,
|
|
69
|
+
path: segments.slice(separator + 3).join("/"),
|
|
70
|
+
...lineOf(url.hash.replace(/^#L/, ""))
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (section === "releases" && id) return {
|
|
74
|
+
repo,
|
|
75
|
+
release: {
|
|
76
|
+
...from,
|
|
77
|
+
repo,
|
|
78
|
+
id,
|
|
79
|
+
tag: id
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
if (section === "commit" && id) return {
|
|
83
|
+
repo,
|
|
84
|
+
commit: {
|
|
85
|
+
...from,
|
|
86
|
+
repo,
|
|
87
|
+
sha: id
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
if (section === "tags" && id) return {
|
|
91
|
+
repo,
|
|
92
|
+
tag: segments.slice(separator + 2).join("/")
|
|
93
|
+
};
|
|
94
|
+
if (section === "compare" && id) return {
|
|
95
|
+
repo,
|
|
96
|
+
...rangeOf(segments.slice(separator + 2).join("/"))
|
|
97
|
+
};
|
|
98
|
+
const kind = section ? KINDS.get(section) : void 0;
|
|
99
|
+
if (!kind || !id) return { repo };
|
|
100
|
+
const thread = {
|
|
101
|
+
...from,
|
|
102
|
+
repo,
|
|
103
|
+
kind,
|
|
104
|
+
number: id
|
|
105
|
+
};
|
|
106
|
+
const sha = kind === "pull_request" ? url.searchParams.get("commit_id") : void 0;
|
|
107
|
+
if (sha) return {
|
|
108
|
+
repo,
|
|
109
|
+
thread,
|
|
110
|
+
commit: {
|
|
111
|
+
...from,
|
|
112
|
+
repo,
|
|
113
|
+
sha
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const note = url.hash.startsWith("#note_") ? url.hash.slice(6) : void 0;
|
|
117
|
+
return {
|
|
118
|
+
repo,
|
|
119
|
+
thread,
|
|
120
|
+
...note ? { comment: {
|
|
121
|
+
...from,
|
|
122
|
+
thread,
|
|
123
|
+
id: note
|
|
124
|
+
} } : {}
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
reference: (ref, same, expand) => {
|
|
128
|
+
if ("sha" in ref) return `${same ? "" : `${ref.repo.owner}/${ref.repo.name}@`}${ref.sha.slice(0, 8)}`;
|
|
129
|
+
const prefix = PREFIXES[ref.kind];
|
|
130
|
+
if (!prefix || ref.repo.kind === "namespace") return;
|
|
131
|
+
return `${same ? "" : `${ref.repo.owner}/${ref.repo.name}`}${prefix}${ref.number}${expand ? "+" : ""}`;
|
|
132
|
+
},
|
|
133
|
+
references: REFERENCES
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const GITLAB_WEB = {
|
|
137
|
+
forge: "gitlab",
|
|
138
|
+
baseUrl: "https://gitlab.com",
|
|
139
|
+
apiPath: "/api/v4",
|
|
140
|
+
links: ({ baseUrl }) => gitlabWeb(baseUrl.replace(/\/api\/v4$/, ""))
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* GitLab subscribes per event with a boolean flag rather than an event name,
|
|
144
|
+
* so the flag names are the native events.
|
|
145
|
+
*/
|
|
146
|
+
const GITLAB_NATIVE_EVENTS = {
|
|
147
|
+
comment: ["note_events", "confidential_note_events"],
|
|
148
|
+
review: ["merge_requests_events"],
|
|
149
|
+
review_comment: ["note_events"],
|
|
150
|
+
state_change: [
|
|
151
|
+
"issues_events",
|
|
152
|
+
"confidential_issues_events",
|
|
153
|
+
"merge_requests_events"
|
|
154
|
+
],
|
|
155
|
+
label: ["issues_events", "merge_requests_events"],
|
|
156
|
+
assignment: ["issues_events", "merge_requests_events"],
|
|
157
|
+
push: ["push_events"],
|
|
158
|
+
ref: ["tag_push_events", "push_events"],
|
|
159
|
+
release: ["releases_events"],
|
|
160
|
+
membership: ["member_events"],
|
|
161
|
+
wiki: ["wiki_page_events"]
|
|
162
|
+
};
|
|
163
|
+
/** Normalised kinds and actions GitLab deliveries translate into. */
|
|
164
|
+
const GITLAB_WEBHOOK_EVENTS = [
|
|
165
|
+
{
|
|
166
|
+
kind: "comment",
|
|
167
|
+
action: "created"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
kind: "review",
|
|
171
|
+
action: "submitted"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
kind: "review_comment",
|
|
175
|
+
action: "created"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
kind: "state_change",
|
|
179
|
+
action: "opened"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
kind: "state_change",
|
|
183
|
+
action: "closed"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
kind: "state_change",
|
|
187
|
+
action: "reopened"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
kind: "state_change",
|
|
191
|
+
action: "merged"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
kind: "label",
|
|
195
|
+
action: "labelled"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
kind: "label",
|
|
199
|
+
action: "unlabelled"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
kind: "assignment",
|
|
203
|
+
action: "assigned"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
kind: "assignment",
|
|
207
|
+
action: "unassigned"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
kind: "assignment",
|
|
211
|
+
action: "review_requested"
|
|
212
|
+
},
|
|
213
|
+
{ kind: "push" },
|
|
214
|
+
{
|
|
215
|
+
kind: "ref",
|
|
216
|
+
action: "created"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
kind: "ref",
|
|
220
|
+
action: "deleted"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
kind: "release",
|
|
224
|
+
action: "published"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
kind: "release",
|
|
228
|
+
action: "edited"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
kind: "release",
|
|
232
|
+
action: "deleted"
|
|
233
|
+
},
|
|
234
|
+
{ kind: "membership" },
|
|
235
|
+
{
|
|
236
|
+
kind: "wiki",
|
|
237
|
+
action: "created"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
kind: "wiki",
|
|
241
|
+
action: "edited"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
kind: "wiki",
|
|
245
|
+
action: "deleted"
|
|
246
|
+
}
|
|
247
|
+
];
|
|
248
|
+
const FORGE = "gitlab";
|
|
249
|
+
function toActor(instance, user) {
|
|
250
|
+
if (!user) return;
|
|
251
|
+
return {
|
|
252
|
+
forge: FORGE,
|
|
253
|
+
instance,
|
|
254
|
+
login: user.username,
|
|
255
|
+
id: String(user.id),
|
|
256
|
+
name: user.name,
|
|
257
|
+
avatarUrl: user.avatar_url ?? void 0,
|
|
258
|
+
url: user.web_url,
|
|
259
|
+
typeRaw: user.bot === void 0 ? void 0 : user.bot ? "bot" : "user",
|
|
260
|
+
isBotHint: user.bot === true || /^(?:project|group)_\d+_bot(?:_|$)/.test(user.username)
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/** Splits a full project path into the namespace (which may contain slashes) and the project name. */
|
|
264
|
+
function toRepoRef(instance, pathWithNamespace, id) {
|
|
265
|
+
const index = pathWithNamespace.lastIndexOf("/");
|
|
266
|
+
return {
|
|
267
|
+
forge: FORGE,
|
|
268
|
+
instance,
|
|
269
|
+
owner: pathWithNamespace.slice(0, index),
|
|
270
|
+
name: pathWithNamespace.slice(index + 1),
|
|
271
|
+
externalId: id === void 0 ? void 0 : String(id)
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/** Reads the project path out of a `/-/`-style web URL, which cross-project listings carry instead of a project path. */
|
|
275
|
+
function repoRefFromWebUrl(instance, webUrl, id) {
|
|
276
|
+
const path = webUrl?.match(/^https?:\/\/[^/]+\/(.+?)\/-\//)?.[1];
|
|
277
|
+
return path ? toRepoRef(instance, path, id) : void 0;
|
|
278
|
+
}
|
|
279
|
+
function toNamespaceRef(instance, fullPath, id) {
|
|
280
|
+
return {
|
|
281
|
+
forge: FORGE,
|
|
282
|
+
instance,
|
|
283
|
+
kind: "namespace",
|
|
284
|
+
owner: fullPath,
|
|
285
|
+
name: "",
|
|
286
|
+
externalId: id === void 0 ? void 0 : String(id)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/** GitLab has no teams of its own; a subgroup stands in for one, with its path below `org` as the slug. */
|
|
290
|
+
function toTeam(instance, org, raw) {
|
|
291
|
+
const slug = raw.full_path.slice(org.owner.length + 1);
|
|
292
|
+
const parent = slug.includes("/") ? slug.slice(0, slug.lastIndexOf("/")) : void 0;
|
|
293
|
+
return {
|
|
294
|
+
ref: {
|
|
295
|
+
forge: FORGE,
|
|
296
|
+
instance,
|
|
297
|
+
org,
|
|
298
|
+
id: String(raw.id),
|
|
299
|
+
slug
|
|
300
|
+
},
|
|
301
|
+
name: raw.name ?? raw.path ?? slug,
|
|
302
|
+
description: raw.description || void 0,
|
|
303
|
+
visibilityRaw: raw.visibility,
|
|
304
|
+
parent: parent === void 0 ? void 0 : {
|
|
305
|
+
forge: FORGE,
|
|
306
|
+
instance,
|
|
307
|
+
org,
|
|
308
|
+
id: raw.parent_id == null ? void 0 : String(raw.parent_id),
|
|
309
|
+
slug: parent
|
|
310
|
+
},
|
|
311
|
+
url: raw.web_url,
|
|
312
|
+
raw
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/** Project id accepted by every `/projects/:id` route. */
|
|
316
|
+
function projectId(repo) {
|
|
317
|
+
return encodeURIComponent(`${repo.owner}/${repo.name}`);
|
|
318
|
+
}
|
|
319
|
+
function toThreadKind(targetType) {
|
|
320
|
+
switch (targetType) {
|
|
321
|
+
case "Issue": return "issue";
|
|
322
|
+
case "MergeRequest": return "pull_request";
|
|
323
|
+
default: return;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const REASONS = {
|
|
327
|
+
added_approver: "approval_requested",
|
|
328
|
+
approval_required: "approval_requested",
|
|
329
|
+
assigned: "assigned",
|
|
330
|
+
build_failed: "ci_activity",
|
|
331
|
+
directly_addressed: "mention",
|
|
332
|
+
marked: "manual",
|
|
333
|
+
member_access_requested: "access_requested",
|
|
334
|
+
mentioned: "mention",
|
|
335
|
+
merge_train_removed: "merge_blocked",
|
|
336
|
+
review_requested: "review_requested",
|
|
337
|
+
review_submitted: "review_submitted",
|
|
338
|
+
unmergeable: "merge_blocked"
|
|
339
|
+
};
|
|
340
|
+
function toReason(action) {
|
|
341
|
+
return REASONS[action] ?? "unknown";
|
|
342
|
+
}
|
|
343
|
+
function toState(state) {
|
|
344
|
+
switch (state) {
|
|
345
|
+
case "opened": return "open";
|
|
346
|
+
case "closed":
|
|
347
|
+
case "locked": return "closed";
|
|
348
|
+
case "merged": return "merged";
|
|
349
|
+
default: return "unknown";
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function toNotification(instance, raw) {
|
|
353
|
+
const repo = raw.project ? toRepoRef(instance, raw.project.path_with_namespace, raw.project.id) : toNamespaceRef(instance, raw.group?.full_path ?? "", raw.group?.id);
|
|
354
|
+
const kind = toThreadKind(raw.target_type);
|
|
355
|
+
const target = raw.target ?? void 0;
|
|
356
|
+
const number = target?.iid === void 0 ? target?.id === void 0 ? void 0 : String(target.id) : String(target.iid);
|
|
357
|
+
let subject;
|
|
358
|
+
if (raw.target_type === "Vulnerability") subject = {
|
|
359
|
+
type: "security_alert",
|
|
360
|
+
alert: {
|
|
361
|
+
forge: FORGE,
|
|
362
|
+
instance,
|
|
363
|
+
repo,
|
|
364
|
+
id: number ?? String(raw.id)
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
else if (raw.target_type === "Project" || raw.target_type === "Namespace") subject = {
|
|
368
|
+
type: "repo",
|
|
369
|
+
repo
|
|
370
|
+
};
|
|
371
|
+
else if (raw.target_type === "Commit" && number) subject = {
|
|
372
|
+
type: "commit",
|
|
373
|
+
commit: {
|
|
374
|
+
forge: FORGE,
|
|
375
|
+
instance,
|
|
376
|
+
repo,
|
|
377
|
+
sha: number
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
else if (!kind) subject = {
|
|
381
|
+
type: "other",
|
|
382
|
+
typeRaw: raw.target_type,
|
|
383
|
+
repo,
|
|
384
|
+
id: number,
|
|
385
|
+
url: raw.target_url
|
|
386
|
+
};
|
|
387
|
+
else subject = {
|
|
388
|
+
type: "thread",
|
|
389
|
+
thread: {
|
|
390
|
+
forge: FORGE,
|
|
391
|
+
instance,
|
|
392
|
+
repo,
|
|
393
|
+
kind,
|
|
394
|
+
typeRaw: raw.target_type,
|
|
395
|
+
number
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
return {
|
|
399
|
+
ref: {
|
|
400
|
+
forge: FORGE,
|
|
401
|
+
instance,
|
|
402
|
+
id: String(raw.id)
|
|
403
|
+
},
|
|
404
|
+
subject,
|
|
405
|
+
subjectTypeRaw: raw.target_type,
|
|
406
|
+
reason: toReason(raw.action_name),
|
|
407
|
+
reasonRaw: raw.action_name,
|
|
408
|
+
unread: raw.state === "pending",
|
|
409
|
+
title: target?.title ?? raw.body ?? "",
|
|
410
|
+
subjectState: toState(target?.state),
|
|
411
|
+
subjectStateRaw: target?.state,
|
|
412
|
+
updatedAt: toDate(raw.updated_at ?? raw.created_at) ?? /* @__PURE__ */ new Date(0),
|
|
413
|
+
url: raw.target_url,
|
|
414
|
+
raw
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
const ACCESS_LEVELS$1 = {
|
|
418
|
+
admin: 50,
|
|
419
|
+
maintain: 40,
|
|
420
|
+
push: 30,
|
|
421
|
+
triage: 20,
|
|
422
|
+
pull: 10
|
|
423
|
+
};
|
|
424
|
+
/** GitLab access levels: 50 owner, 40 maintainer, 30 developer, 20 reporter, 10 guest. */
|
|
425
|
+
function toRole(level) {
|
|
426
|
+
return level >= 50 ? "admin" : level >= 40 ? "maintain" : level >= 30 ? "write" : level >= 20 ? "triage" : level >= 10 ? "read" : "none";
|
|
427
|
+
}
|
|
428
|
+
function toLabel(raw) {
|
|
429
|
+
return {
|
|
430
|
+
name: raw.name,
|
|
431
|
+
colour: raw.color?.replace(/^#/, ""),
|
|
432
|
+
description: raw.description ?? void 0
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function toMilestone(raw) {
|
|
436
|
+
return raw ? {
|
|
437
|
+
id: String(raw.id),
|
|
438
|
+
title: raw.title,
|
|
439
|
+
state: raw.state === "closed" ? "closed" : "open",
|
|
440
|
+
description: raw.description ?? void 0,
|
|
441
|
+
dueOn: toDate(raw.due_date),
|
|
442
|
+
url: raw.web_url,
|
|
443
|
+
raw
|
|
444
|
+
} : void 0;
|
|
445
|
+
}
|
|
446
|
+
/** GitLab counts only thumbs up and down on a thread read; the full set needs the award emoji listing. */
|
|
447
|
+
function toVoteReactions(raw) {
|
|
448
|
+
if (raw.upvotes === void 0 && raw.downvotes === void 0) return;
|
|
449
|
+
return {
|
|
450
|
+
total: (raw.upvotes ?? 0) + (raw.downvotes ?? 0),
|
|
451
|
+
counts: {
|
|
452
|
+
...raw.upvotes ? { "+1": raw.upvotes } : {},
|
|
453
|
+
...raw.downvotes ? { "-1": raw.downvotes } : {}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
const BASE_METHODS = {
|
|
458
|
+
merge: "merge",
|
|
459
|
+
rebase_merge: "rebase_merge",
|
|
460
|
+
ff: "fast_forward_only"
|
|
461
|
+
};
|
|
462
|
+
function toRepo(instance, raw) {
|
|
463
|
+
const level = Math.max(raw.permissions?.project_access?.access_level ?? 0, raw.permissions?.group_access?.access_level ?? 0);
|
|
464
|
+
const visibility = raw.visibility === "internal" ? "internal" : raw.visibility === "private" ? "private" : "public";
|
|
465
|
+
const merge = raw.merge_commit_template?.trim() ? { template: raw.merge_commit_template } : void 0;
|
|
466
|
+
const squash = raw.squash_commit_template?.trim() ? { template: raw.squash_commit_template } : void 0;
|
|
467
|
+
return {
|
|
468
|
+
ref: toRepoRef(instance, raw.path_with_namespace, raw.id),
|
|
469
|
+
description: raw.description ?? void 0,
|
|
470
|
+
defaultBranch: raw.default_branch ?? void 0,
|
|
471
|
+
visibility,
|
|
472
|
+
visibilityRaw: raw.visibility,
|
|
473
|
+
isFork: Boolean(raw.forked_from_project),
|
|
474
|
+
isArchived: raw.archived ?? false,
|
|
475
|
+
parent: raw.forked_from_project ? toRepoRef(instance, raw.forked_from_project.path_with_namespace, raw.forked_from_project.id) : void 0,
|
|
476
|
+
topics: raw.topics ?? [],
|
|
477
|
+
url: raw.web_url,
|
|
478
|
+
cloneUrls: raw.http_url_to_repo || raw.ssh_url_to_repo ? {
|
|
479
|
+
https: raw.http_url_to_repo,
|
|
480
|
+
ssh: raw.ssh_url_to_repo
|
|
481
|
+
} : void 0,
|
|
482
|
+
createdAt: toDate(raw.created_at),
|
|
483
|
+
updatedAt: toDate(raw.last_activity_at),
|
|
484
|
+
openIssueCount: raw.open_issues_count,
|
|
485
|
+
owner: toActor(instance, raw.owner),
|
|
486
|
+
licence: raw.license?.key && raw.license.key !== "other" ? raw.license.key : void 0,
|
|
487
|
+
stars: raw.star_count,
|
|
488
|
+
forks: raw.forks_count,
|
|
489
|
+
mergeMethods: raw.merge_method === void 0 ? void 0 : [
|
|
490
|
+
...raw.merge_method === "merge" ? ["merge"] : [],
|
|
491
|
+
...raw.merge_method === "rebase_merge" ? ["rebase_merge"] : [],
|
|
492
|
+
...raw.merge_method === "ff" ? ["fast_forward_only"] : [],
|
|
493
|
+
...raw.squash_option && raw.squash_option !== "never" ? ["squash"] : []
|
|
494
|
+
],
|
|
495
|
+
defaultMergeMethod: raw.merge_method === void 0 ? void 0 : raw.squash_option === "always" || raw.squash_option === "default_on" ? "squash" : BASE_METHODS[raw.merge_method],
|
|
496
|
+
deleteBranchOnMerge: raw.remove_source_branch_after_merge ?? void 0,
|
|
497
|
+
mergeCommit: merge || squash ? {
|
|
498
|
+
merge,
|
|
499
|
+
squash
|
|
500
|
+
} : void 0,
|
|
501
|
+
features: raw.issues_access_level === void 0 && raw.issues_enabled === void 0 ? void 0 : {
|
|
502
|
+
issues: raw.issues_enabled ?? raw.issues_access_level !== "disabled",
|
|
503
|
+
pullRequests: raw.merge_requests_enabled ?? raw.merge_requests_access_level !== "disabled",
|
|
504
|
+
discussions: false,
|
|
505
|
+
wiki: raw.wiki_enabled ?? raw.wiki_access_level !== "disabled",
|
|
506
|
+
projects: false,
|
|
507
|
+
releases: raw.releases_access_level !== "disabled"
|
|
508
|
+
},
|
|
509
|
+
permissions: raw.permissions ? {
|
|
510
|
+
admin: level >= ACCESS_LEVELS$1.admin,
|
|
511
|
+
maintain: level >= ACCESS_LEVELS$1.maintain,
|
|
512
|
+
push: level >= ACCESS_LEVELS$1.push,
|
|
513
|
+
triage: level >= ACCESS_LEVELS$1.triage,
|
|
514
|
+
pull: level >= ACCESS_LEVELS$1.pull
|
|
515
|
+
} : void 0,
|
|
516
|
+
raw
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
function toThread(ref, raw) {
|
|
520
|
+
const isMerge = ref.kind === "pull_request";
|
|
521
|
+
const reviewers = (raw.reviewers ?? []).flatMap((user) => {
|
|
522
|
+
const actor = toActor(ref.instance, user);
|
|
523
|
+
return actor ? [{
|
|
524
|
+
actor,
|
|
525
|
+
state: "unknown"
|
|
526
|
+
}] : [];
|
|
527
|
+
});
|
|
528
|
+
return {
|
|
529
|
+
ref: {
|
|
530
|
+
...ref,
|
|
531
|
+
externalId: raw.id === void 0 ? ref.externalId : String(raw.id)
|
|
532
|
+
},
|
|
533
|
+
kind: ref.kind,
|
|
534
|
+
title: raw.title,
|
|
535
|
+
body: raw.description ?? void 0,
|
|
536
|
+
state: toState(raw.state),
|
|
537
|
+
stateRaw: raw.state,
|
|
538
|
+
isDraft: raw.draft ?? false,
|
|
539
|
+
assignees: (raw.assignees ?? []).flatMap((user) => toActor(ref.instance, user) ?? []),
|
|
540
|
+
reviewers,
|
|
541
|
+
lastActivityAt: toDate(raw.updated_at),
|
|
542
|
+
branches: isMerge && raw.source_branch && raw.target_branch ? {
|
|
543
|
+
head: {
|
|
544
|
+
ref: raw.source_branch,
|
|
545
|
+
sha: raw.diff_refs?.head_sha ?? raw.sha,
|
|
546
|
+
repo: raw.source_project_id !== void 0 && raw.source_project_id === raw.target_project_id ? ref.repo : void 0
|
|
547
|
+
},
|
|
548
|
+
base: {
|
|
549
|
+
ref: raw.target_branch,
|
|
550
|
+
sha: raw.diff_refs?.base_sha
|
|
551
|
+
},
|
|
552
|
+
mergeCommitSha: raw.merge_commit_sha ?? raw.squash_commit_sha ?? void 0
|
|
553
|
+
} : void 0,
|
|
554
|
+
stats: isMerge && raw.changes_count && /^\d+$/.test(raw.changes_count) ? { changedFileCount: Number(raw.changes_count) } : void 0,
|
|
555
|
+
author: toActor(ref.instance, raw.author),
|
|
556
|
+
url: raw.web_url,
|
|
557
|
+
createdAt: toDate(raw.created_at),
|
|
558
|
+
updatedAt: toDate(raw.updated_at),
|
|
559
|
+
closedAt: toDate(raw.closed_at),
|
|
560
|
+
mergedAt: isMerge ? toDate(raw.merged_at) : void 0,
|
|
561
|
+
mergedBy: isMerge ? toActor(ref.instance, raw.merge_user ?? raw.merged_by) : void 0,
|
|
562
|
+
labels: (raw.labels ?? []).map((label) => typeof label === "string" ? { name: label } : {
|
|
563
|
+
name: label.name,
|
|
564
|
+
colour: label.color,
|
|
565
|
+
description: label.description ?? void 0
|
|
566
|
+
}),
|
|
567
|
+
locked: raw.discussion_locked ?? void 0,
|
|
568
|
+
commentCount: raw.user_notes_count,
|
|
569
|
+
milestone: toMilestone(raw.milestone),
|
|
570
|
+
reactions: toVoteReactions(raw),
|
|
571
|
+
raw
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
/** System notes are the only record of label, state and assignment changes in the notes API. */
|
|
575
|
+
const SYSTEM_NOTE_KINDS = [
|
|
576
|
+
[/^approved this merge request/i, "review"],
|
|
577
|
+
[/^added \d+ (?:new )?commits?/i, "commit"],
|
|
578
|
+
[/^(?:added|removed) .*label/i, "label"],
|
|
579
|
+
[/^(?:closed|reopened|merged|marked this merge request as|status changed to)/i, "state_change"],
|
|
580
|
+
[/^(?:assigned to|reassigned to|unassigned|requested review from)/i, "assignment"],
|
|
581
|
+
[/^mentioned in /i, "referenced"]
|
|
582
|
+
];
|
|
583
|
+
function toNoteKind(note) {
|
|
584
|
+
if (!note.system) return note.type === "DiffNote" ? "review_comment" : "comment";
|
|
585
|
+
return SYSTEM_NOTE_KINDS.find(([pattern]) => pattern.test(note.body))?.[1] ?? "other";
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* A "mentioned in" system note names the subject that mentioned this thread:
|
|
589
|
+
* `!5` or `acme/widgets!5` for a merge request, `#5` for an issue, or a sha
|
|
590
|
+
* for a commit. The reference is read from that wording, since the note
|
|
591
|
+
* carries no structured source.
|
|
592
|
+
*/
|
|
593
|
+
function crossReference(ref, body) {
|
|
594
|
+
const text = body.match(/^mentioned in (?:merge request|issue|commit) (\S+)/i)?.[1];
|
|
595
|
+
if (!text) return {
|
|
596
|
+
type: "referenced",
|
|
597
|
+
text: body
|
|
598
|
+
};
|
|
599
|
+
const thread = text.match(/^(?:([^!#]+)([!#]))?[!#]?(\d+)$/);
|
|
600
|
+
if (thread) {
|
|
601
|
+
const repo = thread[1] ? toRepoRef(ref.instance, thread[1]) : ref.repo;
|
|
602
|
+
return {
|
|
603
|
+
type: "referenced",
|
|
604
|
+
from: {
|
|
605
|
+
forge: FORGE,
|
|
606
|
+
instance: ref.instance,
|
|
607
|
+
repo,
|
|
608
|
+
kind: text.includes("!") ? "pull_request" : "issue",
|
|
609
|
+
number: thread[3]
|
|
610
|
+
},
|
|
611
|
+
fromRepo: repo,
|
|
612
|
+
text
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
return /^[0-9a-f]{7,40}$/i.test(text) ? {
|
|
616
|
+
type: "referenced",
|
|
617
|
+
from: {
|
|
618
|
+
forge: FORGE,
|
|
619
|
+
instance: ref.instance,
|
|
620
|
+
repo: ref.repo,
|
|
621
|
+
sha: text
|
|
622
|
+
},
|
|
623
|
+
fromRepo: ref.repo,
|
|
624
|
+
text
|
|
625
|
+
} : {
|
|
626
|
+
type: "referenced",
|
|
627
|
+
text
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
/** The review id that `threads.reviews()` gives an approval by `user`. */
|
|
631
|
+
function approvalId(user) {
|
|
632
|
+
return `approval:${user?.username ?? user?.id ?? ""}`;
|
|
633
|
+
}
|
|
634
|
+
function noteDetail(ref, note, kind) {
|
|
635
|
+
switch (kind) {
|
|
636
|
+
case "comment":
|
|
637
|
+
case "review_comment": return {
|
|
638
|
+
type: kind,
|
|
639
|
+
comment: {
|
|
640
|
+
forge: FORGE,
|
|
641
|
+
instance: ref.instance,
|
|
642
|
+
thread: ref,
|
|
643
|
+
id: String(note.id)
|
|
644
|
+
},
|
|
645
|
+
body: note.body
|
|
646
|
+
};
|
|
647
|
+
case "review": return {
|
|
648
|
+
type: "review",
|
|
649
|
+
state: "approved",
|
|
650
|
+
stateRaw: "approved",
|
|
651
|
+
review: {
|
|
652
|
+
forge: FORGE,
|
|
653
|
+
instance: ref.instance,
|
|
654
|
+
thread: ref,
|
|
655
|
+
id: approvalId(note.author)
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
case "referenced": return crossReference(ref, note.body);
|
|
659
|
+
default: return;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function toNoteEvent(ref, note) {
|
|
663
|
+
const actor = toActor(ref.instance, note.author);
|
|
664
|
+
const kind = toNoteKind(note);
|
|
665
|
+
const who = actor?.login ?? "someone";
|
|
666
|
+
return {
|
|
667
|
+
forge: FORGE,
|
|
668
|
+
instance: ref.instance,
|
|
669
|
+
id: String(note.id),
|
|
670
|
+
kind,
|
|
671
|
+
kindRaw: note.system ? "system" : note.type ?? "Note",
|
|
672
|
+
summary: note.system ? `${who} ${note.body.split("\n")[0]}` : `${who} ${kind === "review_comment" ? "commented on a line" : "commented"}`,
|
|
673
|
+
...eventTime(toDate(note.created_at), /* @__PURE__ */ new Date(0)),
|
|
674
|
+
actor,
|
|
675
|
+
repo: ref.repo,
|
|
676
|
+
thread: ref,
|
|
677
|
+
detail: noteDetail(ref, note, kind),
|
|
678
|
+
source: "poll",
|
|
679
|
+
payload: note
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
/** GitLab commit comments carry no id, so they are keyed by creation time and author. */
|
|
683
|
+
function commitCommentId(comment) {
|
|
684
|
+
return `${comment.created_at ?? ""}:${comment.author?.id ?? ""}`;
|
|
685
|
+
}
|
|
686
|
+
function toNoteComment(thread, note, discussion) {
|
|
687
|
+
return {
|
|
688
|
+
ref: {
|
|
689
|
+
forge: FORGE,
|
|
690
|
+
instance: thread.instance,
|
|
691
|
+
thread,
|
|
692
|
+
id: String(note.id)
|
|
693
|
+
},
|
|
694
|
+
body: note.body,
|
|
695
|
+
author: toActor(thread.instance, note.author),
|
|
696
|
+
createdAt: toDate(note.created_at),
|
|
697
|
+
updatedAt: toDate(note.updated_at),
|
|
698
|
+
...discussion && note.resolvable && { thread: {
|
|
699
|
+
id: discussion.id,
|
|
700
|
+
resolved: Boolean(note.resolved)
|
|
701
|
+
} },
|
|
702
|
+
raw: note
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function toCommitComment(commit, comment) {
|
|
706
|
+
return {
|
|
707
|
+
ref: {
|
|
708
|
+
forge: FORGE,
|
|
709
|
+
instance: commit.instance,
|
|
710
|
+
commit,
|
|
711
|
+
id: commitCommentId(comment)
|
|
712
|
+
},
|
|
713
|
+
body: comment.note,
|
|
714
|
+
author: toActor(commit.instance, comment.author),
|
|
715
|
+
createdAt: toDate(comment.created_at),
|
|
716
|
+
raw: comment
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
/** Pipeline and job statuses. `manual` jobs wait for a person, so they neither pass nor fail. */
|
|
720
|
+
function pipelineState(status) {
|
|
721
|
+
switch (status) {
|
|
722
|
+
case "success": return "success";
|
|
723
|
+
case "failed":
|
|
724
|
+
case "canceled": return "failure";
|
|
725
|
+
case "skipped":
|
|
726
|
+
case "manual": return "neutral";
|
|
727
|
+
case "created":
|
|
728
|
+
case "waiting_for_resource":
|
|
729
|
+
case "preparing":
|
|
730
|
+
case "pending":
|
|
731
|
+
case "running":
|
|
732
|
+
case "scheduled": return "pending";
|
|
733
|
+
default: return "unknown";
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
/** The merge request's head pipeline, which GitLab reports as one combined status. */
|
|
737
|
+
function toPipelineSummary(pipeline) {
|
|
738
|
+
const state = pipelineState(pipeline.status);
|
|
739
|
+
return {
|
|
740
|
+
state: state === "neutral" ? "pending" : state,
|
|
741
|
+
stateRaw: pipeline.status,
|
|
742
|
+
...pipeline.web_url ? { url: pipeline.web_url } : {}
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
function toJobCheck(repo, job, run) {
|
|
746
|
+
const state = pipelineState(job.status);
|
|
747
|
+
return {
|
|
748
|
+
ref: {
|
|
749
|
+
forge: FORGE,
|
|
750
|
+
instance: repo.instance,
|
|
751
|
+
repo,
|
|
752
|
+
id: String(job.id),
|
|
753
|
+
type: "job"
|
|
754
|
+
},
|
|
755
|
+
name: job.stage ? `${job.stage}: ${job.name}` : job.name,
|
|
756
|
+
state: state === "failure" && job.allow_failure ? "neutral" : state,
|
|
757
|
+
stateRaw: job.status,
|
|
758
|
+
url: job.web_url,
|
|
759
|
+
startedAt: toDate(job.started_at),
|
|
760
|
+
completedAt: toDate(job.finished_at),
|
|
761
|
+
...run ? { run } : {},
|
|
762
|
+
raw: job
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
/** GitLab keys releases by tag and has no drafts or prereleases. */
|
|
766
|
+
function toRelease(repo, raw) {
|
|
767
|
+
return {
|
|
768
|
+
ref: {
|
|
769
|
+
forge: FORGE,
|
|
770
|
+
instance: repo.instance,
|
|
771
|
+
repo,
|
|
772
|
+
id: raw.tag_name,
|
|
773
|
+
tag: raw.tag_name
|
|
774
|
+
},
|
|
775
|
+
name: raw.name ?? void 0,
|
|
776
|
+
tag: raw.tag_name,
|
|
777
|
+
body: raw.description ?? void 0,
|
|
778
|
+
isDraft: false,
|
|
779
|
+
isPrerelease: false,
|
|
780
|
+
author: toActor(repo.instance, raw.author),
|
|
781
|
+
publishedAt: raw.upcoming_release ? void 0 : toDate(raw.released_at),
|
|
782
|
+
createdAt: toDate(raw.created_at),
|
|
783
|
+
url: raw._links?.self,
|
|
784
|
+
assets: raw.assets?.links?.map((link) => ({
|
|
785
|
+
name: link.name,
|
|
786
|
+
url: link.direct_asset_url ?? link.url
|
|
787
|
+
})),
|
|
788
|
+
raw
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
const REPORT_KINDS = {
|
|
792
|
+
DEPENDENCY_SCANNING: "dependency",
|
|
793
|
+
CONTAINER_SCANNING: "dependency",
|
|
794
|
+
CLUSTER_IMAGE_SCANNING: "dependency",
|
|
795
|
+
SAST: "code_scanning",
|
|
796
|
+
SECRET_DETECTION: "secret"
|
|
797
|
+
};
|
|
798
|
+
const REPORT_TYPES = {
|
|
799
|
+
dependency: [
|
|
800
|
+
"DEPENDENCY_SCANNING",
|
|
801
|
+
"CONTAINER_SCANNING",
|
|
802
|
+
"CLUSTER_IMAGE_SCANNING"
|
|
803
|
+
],
|
|
804
|
+
code_scanning: ["SAST"],
|
|
805
|
+
secret: ["SECRET_DETECTION"],
|
|
806
|
+
advisory: []
|
|
807
|
+
};
|
|
808
|
+
/** `INFO` findings are informational and carry no severity. */
|
|
809
|
+
function toSeverity(raw) {
|
|
810
|
+
const severity = raw.toLowerCase();
|
|
811
|
+
return severity === "critical" || severity === "high" || severity === "medium" || severity === "low" ? severity : "unknown";
|
|
812
|
+
}
|
|
813
|
+
function toVulnerability(repo, raw) {
|
|
814
|
+
const kind = REPORT_KINDS[raw.reportType] ?? "other";
|
|
815
|
+
const state = raw.state === "DETECTED" || raw.state === "CONFIRMED" ? "open" : raw.state === "RESOLVED" ? "fixed" : raw.state === "DISMISSED" ? "dismissed" : "unknown";
|
|
816
|
+
const id = raw.id.replace(/^gid:\/\/gitlab\/Vulnerability\//, "");
|
|
817
|
+
return {
|
|
818
|
+
ref: {
|
|
819
|
+
forge: FORGE,
|
|
820
|
+
instance: repo.instance,
|
|
821
|
+
repo,
|
|
822
|
+
id,
|
|
823
|
+
kind,
|
|
824
|
+
severityRaw: raw.severity.toLowerCase()
|
|
825
|
+
},
|
|
826
|
+
kind,
|
|
827
|
+
kindRaw: raw.reportType.toLowerCase(),
|
|
828
|
+
severity: toSeverity(raw.severity),
|
|
829
|
+
severityRaw: raw.severity.toLowerCase(),
|
|
830
|
+
state,
|
|
831
|
+
stateRaw: raw.state.toLowerCase(),
|
|
832
|
+
title: raw.title,
|
|
833
|
+
url: raw.webUrl ?? void 0,
|
|
834
|
+
createdAt: toDate(raw.detectedAt),
|
|
835
|
+
updatedAt: toDate(raw.updatedAt),
|
|
836
|
+
dismissedAt: toDate(raw.dismissedAt),
|
|
837
|
+
raw
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
function toStatusCheck(repo, raw) {
|
|
841
|
+
const state = pipelineState(raw.status);
|
|
842
|
+
return {
|
|
843
|
+
ref: {
|
|
844
|
+
forge: FORGE,
|
|
845
|
+
instance: repo.instance,
|
|
846
|
+
repo,
|
|
847
|
+
id: String(raw.id),
|
|
848
|
+
type: "status"
|
|
849
|
+
},
|
|
850
|
+
name: raw.name ?? String(raw.id),
|
|
851
|
+
state: state === "failure" && raw.allow_failure ? "neutral" : state,
|
|
852
|
+
stateRaw: raw.status,
|
|
853
|
+
url: raw.target_url ?? void 0,
|
|
854
|
+
startedAt: toDate(raw.created_at),
|
|
855
|
+
completedAt: toDate(raw.finished_at),
|
|
856
|
+
raw
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
function toPipeline(repo, raw) {
|
|
860
|
+
return {
|
|
861
|
+
ref: {
|
|
862
|
+
forge: FORGE,
|
|
863
|
+
instance: repo.instance,
|
|
864
|
+
repo,
|
|
865
|
+
id: String(raw.id)
|
|
866
|
+
},
|
|
867
|
+
name: raw.name || raw.source || `pipeline ${raw.id}`,
|
|
868
|
+
state: pipelineState(raw.status),
|
|
869
|
+
stateRaw: raw.status,
|
|
870
|
+
number: raw.iid === void 0 ? void 0 : String(raw.iid),
|
|
871
|
+
eventRaw: raw.source,
|
|
872
|
+
branch: raw.ref,
|
|
873
|
+
sha: raw.sha,
|
|
874
|
+
url: raw.web_url,
|
|
875
|
+
actor: toActor(repo.instance, raw.user),
|
|
876
|
+
createdAt: toDate(raw.created_at),
|
|
877
|
+
startedAt: toDate(raw.started_at),
|
|
878
|
+
completedAt: toDate(raw.finished_at),
|
|
879
|
+
raw
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
function toCiJob(run, raw) {
|
|
883
|
+
const state = pipelineState(raw.status);
|
|
884
|
+
return {
|
|
885
|
+
ref: {
|
|
886
|
+
forge: FORGE,
|
|
887
|
+
instance: run.instance,
|
|
888
|
+
repo: run.repo,
|
|
889
|
+
id: String(raw.id),
|
|
890
|
+
run
|
|
891
|
+
},
|
|
892
|
+
name: raw.name,
|
|
893
|
+
state: state === "failure" && raw.allow_failure ? "neutral" : state,
|
|
894
|
+
stateRaw: raw.status,
|
|
895
|
+
stage: raw.stage,
|
|
896
|
+
url: raw.web_url,
|
|
897
|
+
startedAt: toDate(raw.started_at),
|
|
898
|
+
completedAt: toDate(raw.finished_at),
|
|
899
|
+
raw
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
function toCommit(repo, raw, files) {
|
|
903
|
+
return {
|
|
904
|
+
ref: {
|
|
905
|
+
forge: FORGE,
|
|
906
|
+
instance: repo.instance,
|
|
907
|
+
repo,
|
|
908
|
+
sha: raw.id
|
|
909
|
+
},
|
|
910
|
+
sha: raw.id,
|
|
911
|
+
message: raw.message ?? raw.title,
|
|
912
|
+
author: {
|
|
913
|
+
name: raw.author_name,
|
|
914
|
+
email: raw.author_email,
|
|
915
|
+
date: toDate(raw.authored_date ?? raw.created_at)
|
|
916
|
+
},
|
|
917
|
+
committer: {
|
|
918
|
+
name: raw.committer_name,
|
|
919
|
+
email: raw.committer_email,
|
|
920
|
+
date: toDate(raw.committed_date)
|
|
921
|
+
},
|
|
922
|
+
parents: raw.parent_ids ?? [],
|
|
923
|
+
url: raw.web_url,
|
|
924
|
+
...raw.stats ? { stats: {
|
|
925
|
+
additions: raw.stats.additions ?? 0,
|
|
926
|
+
deletions: raw.stats.deletions ?? 0,
|
|
927
|
+
total: raw.stats.total
|
|
928
|
+
} } : {},
|
|
929
|
+
...files ? { files } : {},
|
|
930
|
+
raw
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
/** GitLab reports a change by three booleans and a unified diff, with no counts. */
|
|
934
|
+
function toChangedFile(raw) {
|
|
935
|
+
const path = raw.new_path ?? raw.old_path ?? "";
|
|
936
|
+
const status = raw.new_file ? "added" : raw.deleted_file ? "removed" : raw.renamed_file ? "renamed" : "modified";
|
|
937
|
+
return {
|
|
938
|
+
path,
|
|
939
|
+
previousPath: raw.renamed_file ? raw.old_path : void 0,
|
|
940
|
+
status,
|
|
941
|
+
statusRaw: status,
|
|
942
|
+
patch: raw.diff
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
function toBranch(raw) {
|
|
946
|
+
return {
|
|
947
|
+
name: raw.name,
|
|
948
|
+
sha: raw.commit?.id ?? "",
|
|
949
|
+
isDefault: raw.default,
|
|
950
|
+
isProtected: raw.protected,
|
|
951
|
+
url: raw.web_url,
|
|
952
|
+
raw
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
/** Whether a branch name matches a protected branch name, where `*` stands for any run of characters. */
|
|
956
|
+
function matchesBranch(pattern, name) {
|
|
957
|
+
return new RegExp(`^${pattern.split("*").map((part) => part.replace(/[\\^$.|?+()[\]{}]/g, "\\$&")).join(".*")}$`).test(name);
|
|
958
|
+
}
|
|
959
|
+
/** Code owner and report rules apply only to some changes, so just `any_approver` and `regular` set the floor. */
|
|
960
|
+
function toBranchRules(branch, project, rules, warnings) {
|
|
961
|
+
const applies = (rule) => rule.protected_branches?.length ? rule.protected_branches.some((protectedBranch) => matchesBranch(protectedBranch.name, branch.name)) : !rule.applies_to_all_protected_branches || branch.protected === true;
|
|
962
|
+
const approvals = rules?.filter((rule) => (rule.rule_type === "any_approver" || rule.rule_type === "regular") && applies(rule)).map((rule) => rule.approvals_required);
|
|
963
|
+
return {
|
|
964
|
+
branch: branch.name,
|
|
965
|
+
requiredChecks: [],
|
|
966
|
+
requiresAllChecks: project.only_allow_merge_if_pipeline_succeeds ?? void 0,
|
|
967
|
+
requiredApprovals: approvals && Math.max(0, ...approvals),
|
|
968
|
+
...warnings.length ? { warnings } : {},
|
|
969
|
+
raw: {
|
|
970
|
+
branch,
|
|
971
|
+
project,
|
|
972
|
+
rules
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
function toTag(raw) {
|
|
977
|
+
return {
|
|
978
|
+
name: raw.name,
|
|
979
|
+
sha: raw.commit?.id ?? raw.target ?? "",
|
|
980
|
+
raw
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
function toTreeEntry(raw) {
|
|
984
|
+
return {
|
|
985
|
+
path: raw.path,
|
|
986
|
+
type: raw.mode === "120000" ? "symlink" : raw.type === "tree" ? "directory" : raw.type === "commit" ? "submodule" : "file",
|
|
987
|
+
sha: raw.id,
|
|
988
|
+
mode: raw.mode
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
function toWebhook(target, raw) {
|
|
992
|
+
const nativeEvents = Object.entries(raw).filter(([key, value]) => key.endsWith("_events") && value === true).map(([key]) => key);
|
|
993
|
+
return {
|
|
994
|
+
ref: {
|
|
995
|
+
forge: FORGE,
|
|
996
|
+
instance: target.instance,
|
|
997
|
+
target,
|
|
998
|
+
id: String(raw.id)
|
|
999
|
+
},
|
|
1000
|
+
url: raw.url,
|
|
1001
|
+
events: eventKindsOf(GITLAB_NATIVE_EVENTS, nativeEvents),
|
|
1002
|
+
nativeEvents,
|
|
1003
|
+
active: !raw.disabled_until,
|
|
1004
|
+
createdAt: toDate(raw.created_at),
|
|
1005
|
+
raw
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
function toWebhookDelivery(hook, raw) {
|
|
1009
|
+
const status = Number(raw.response_status) || 0;
|
|
1010
|
+
return {
|
|
1011
|
+
ref: {
|
|
1012
|
+
forge: FORGE,
|
|
1013
|
+
instance: hook.instance,
|
|
1014
|
+
hook,
|
|
1015
|
+
id: String(raw.id)
|
|
1016
|
+
},
|
|
1017
|
+
event: raw.trigger ?? "",
|
|
1018
|
+
status,
|
|
1019
|
+
ok: status >= 200 && status < 300,
|
|
1020
|
+
deliveredAt: toDate(raw.created_at),
|
|
1021
|
+
duration: raw.execution_duration === void 0 ? void 0 : Math.round(raw.execution_duration * 1e3),
|
|
1022
|
+
raw
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
const TOKEN_HEADER = "x-gitlab-token";
|
|
1026
|
+
/**
|
|
1027
|
+
* GitLab sends the configured secret verbatim in `X-Gitlab-Token`; there is no
|
|
1028
|
+
* body signature to compute.
|
|
1029
|
+
*/
|
|
1030
|
+
async function verifyGitLabToken(delivery, secret) {
|
|
1031
|
+
return verifySharedToken(delivery, secret, TOKEN_HEADER);
|
|
1032
|
+
}
|
|
1033
|
+
const gitlabWebhooks = ({ options, instance }) => ({
|
|
1034
|
+
events: GITLAB_WEBHOOK_EVENTS,
|
|
1035
|
+
verify: (delivery) => verifyGitLabToken(delivery, options.webhookSecret),
|
|
1036
|
+
translate: async (delivery) => (await import("./events-7EBoeIPd-A2RUkJi5-BxrICQ17.js")).translateGitLabWebhook(instance, delivery)
|
|
1037
|
+
});
|
|
1038
|
+
const PROJECT_ORDER = {
|
|
1039
|
+
created: "created_at",
|
|
1040
|
+
updated: "updated_at",
|
|
1041
|
+
pushed: "last_activity_at",
|
|
1042
|
+
name: "name"
|
|
1043
|
+
};
|
|
1044
|
+
/** GitLab versions with the webhook event log and resend endpoints. */
|
|
1045
|
+
const GITLAB_HOOK_EVENTS = "17.0";
|
|
1046
|
+
const ISSUE_LIKE = {
|
|
1047
|
+
issue: true,
|
|
1048
|
+
pull_request: true
|
|
1049
|
+
};
|
|
1050
|
+
const STATE_EVENTS = {
|
|
1051
|
+
open: "reopen",
|
|
1052
|
+
closed: "close"
|
|
1053
|
+
};
|
|
1054
|
+
/** Access level per normalised role, as `POST /projects/:id/members` takes it. */
|
|
1055
|
+
const ACCESS_LEVELS = {
|
|
1056
|
+
admin: 50,
|
|
1057
|
+
maintain: 40,
|
|
1058
|
+
write: 30,
|
|
1059
|
+
triage: 20,
|
|
1060
|
+
read: 10,
|
|
1061
|
+
none: 0
|
|
1062
|
+
};
|
|
1063
|
+
/** GitLab awards emoji by name; these are the names behind the normalised reactions. */
|
|
1064
|
+
const AWARD_EMOJI = {
|
|
1065
|
+
"+1": "thumbsup",
|
|
1066
|
+
"-1": "thumbsdown",
|
|
1067
|
+
"laugh": "laughing",
|
|
1068
|
+
"confused": "confused",
|
|
1069
|
+
"heart": "heart",
|
|
1070
|
+
"hooray": "tada",
|
|
1071
|
+
"rocket": "rocket",
|
|
1072
|
+
"eyes": "eyes"
|
|
1073
|
+
};
|
|
1074
|
+
/** The model's name for each award emoji `forges` writes. */
|
|
1075
|
+
const REACTION_NAMES = Object.fromEntries(Object.entries(AWARD_EMOJI).map(([content, name]) => [name, content]));
|
|
1076
|
+
const VULNERABILITIES_QUERY = `query ProjectVulnerabilities($fullPath: ID!, $first: Int, $after: String, $state: [VulnerabilityState!], $reportType: [VulnerabilityReportType!]) {
|
|
1077
|
+
project(fullPath: $fullPath) {
|
|
1078
|
+
vulnerabilities(first: $first, after: $after, state: $state, reportType: $reportType) {
|
|
1079
|
+
pageInfo { hasNextPage endCursor }
|
|
1080
|
+
nodes { id title severity state reportType detectedAt updatedAt dismissedAt resolvedAt webUrl }
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
}`;
|
|
1084
|
+
const PROJECTS_QUERY = `query CodeSearchProjects($ids: [ID!]) {
|
|
1085
|
+
projects(ids: $ids) {
|
|
1086
|
+
nodes { id fullPath }
|
|
1087
|
+
}
|
|
1088
|
+
}`;
|
|
1089
|
+
function threadPath(ref) {
|
|
1090
|
+
const project = `/projects/${projectId(ref.repo)}`;
|
|
1091
|
+
switch (ref.kind) {
|
|
1092
|
+
case "pull_request": return `${project}/merge_requests/${encodeURIComponent(ref.number)}`;
|
|
1093
|
+
default: return `${project}/issues/${encodeURIComponent(ref.number)}`;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
/** Creates a GitLab provider for gitlab.com or a self-managed instance. */
|
|
1097
|
+
const gitlab = /* @__PURE__ */ defineForgeProvider({
|
|
1098
|
+
forge: FORGE,
|
|
1099
|
+
hasWeb: true,
|
|
1100
|
+
baseUrl: "https://gitlab.com",
|
|
1101
|
+
anonymous: true,
|
|
1102
|
+
apiPath: "/api/v4",
|
|
1103
|
+
headers: { accept: "application/json" },
|
|
1104
|
+
webhooks: gitlabWebhooks,
|
|
1105
|
+
authHeaders: ({ options: { auth } }) => auth?.type === "token" ? async () => ({ authorization: `Bearer ${await resolveToken(auth)}` }) : void 0,
|
|
1106
|
+
setup({ options, instance, baseUrl, origin: context, fetcher }) {
|
|
1107
|
+
/** GitLab serves notes, labels, milestones, members, commit statuses, commit and code search and vulnerabilities only to signed-in users. */
|
|
1108
|
+
const anonymous = options.auth?.type === "anonymous";
|
|
1109
|
+
const web = GITLAB_WEB.links({
|
|
1110
|
+
baseUrl,
|
|
1111
|
+
instance
|
|
1112
|
+
});
|
|
1113
|
+
/**
|
|
1114
|
+
* GitLab lists pending and done to-dos separately. With `all`, pending
|
|
1115
|
+
* pages are followed by done pages; `cursor.token` marks the switch. Only
|
|
1116
|
+
* the pending listing on its own is conditional.
|
|
1117
|
+
*/
|
|
1118
|
+
async function notificationPage(listOptions = {}) {
|
|
1119
|
+
const cursor = listOptions.cursor;
|
|
1120
|
+
const state = cursor?.token === "done" ? "done" : "pending";
|
|
1121
|
+
const conditional = !listOptions.all && isFirstPage(cursor);
|
|
1122
|
+
const result = await fetcher.json(cursor?.nextUrl ?? "/todos", {
|
|
1123
|
+
query: cursor?.nextUrl ? void 0 : {
|
|
1124
|
+
state,
|
|
1125
|
+
per_page: listOptions.perPage
|
|
1126
|
+
},
|
|
1127
|
+
etag: conditional ? firstPageEtag(cursor) : void 0,
|
|
1128
|
+
signal: listOptions.signal
|
|
1129
|
+
});
|
|
1130
|
+
const since = listOptions.since?.getTime();
|
|
1131
|
+
const items = (result.data ?? []).map((raw) => toNotification(instance, raw)).filter((item) => since === void 0 || item.updatedAt.getTime() >= since);
|
|
1132
|
+
const phase = cursor?.token ?? "pending";
|
|
1133
|
+
const next = result.cursor?.nextUrl ? {
|
|
1134
|
+
...result.cursor,
|
|
1135
|
+
token: phase === "done" ? "done" : void 0
|
|
1136
|
+
} : listOptions.all && phase !== "done" ? { token: "done" } : void 0;
|
|
1137
|
+
const page = {
|
|
1138
|
+
items,
|
|
1139
|
+
cursor: result.notModified ? void 0 : next,
|
|
1140
|
+
notModified: result.notModified,
|
|
1141
|
+
...rateLimitPart(result.response)
|
|
1142
|
+
};
|
|
1143
|
+
return conditional ? withEtag(page, result, cursor) : page;
|
|
1144
|
+
}
|
|
1145
|
+
/** GitLab assigns by user id, so logins are resolved once each. */
|
|
1146
|
+
/** Award emoji hang off the issue, the merge request or a note, all under the same path. */
|
|
1147
|
+
function awardPath(target) {
|
|
1148
|
+
return "thread" in target ? `${threadPath(requireIssueOrPull(target.thread, context, "react to"))}/notes/${target.id}` : threadPath(requireIssueOrPull(target, context, "react to"));
|
|
1149
|
+
}
|
|
1150
|
+
/** The authenticated username, read once; removing an award needs its id, which is found by owner. */
|
|
1151
|
+
const viewerLogin = memo(() => fetcher.json("/user").then((result) => result.data.username, () => void 0));
|
|
1152
|
+
const userIdByName = memoBy((username) => fetcher.json("/users", { query: { username } }).then(({ data }) => {
|
|
1153
|
+
if (!data[0]) throw new UnsupportedOperationError(`No GitLab user named ${username}`, context);
|
|
1154
|
+
return data[0].id;
|
|
1155
|
+
}));
|
|
1156
|
+
function userId(actor) {
|
|
1157
|
+
if (typeof actor !== "string" && /^\d+$/.test(actor.id)) return Promise.resolve(Number(actor.id));
|
|
1158
|
+
return userIdByName(typeof actor === "string" ? actor : actor.login);
|
|
1159
|
+
}
|
|
1160
|
+
const STATUS_STATES = {
|
|
1161
|
+
pending: "pending",
|
|
1162
|
+
success: "success",
|
|
1163
|
+
failure: "failed",
|
|
1164
|
+
neutral: "success",
|
|
1165
|
+
unknown: "pending"
|
|
1166
|
+
};
|
|
1167
|
+
const PIPELINE_STATES = {
|
|
1168
|
+
pending: "running",
|
|
1169
|
+
success: "success",
|
|
1170
|
+
failure: "failed",
|
|
1171
|
+
neutral: "manual",
|
|
1172
|
+
unknown: void 0
|
|
1173
|
+
};
|
|
1174
|
+
async function setDiscussionResolved(thread, id, resolved, options) {
|
|
1175
|
+
const ref = requireThread(thread, context);
|
|
1176
|
+
await fetcher.raw(`${threadPath(ref)}/discussions/${encodeURIComponent(id)}`, {
|
|
1177
|
+
method: "PUT",
|
|
1178
|
+
query: { resolved },
|
|
1179
|
+
signal: options?.signal
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
const list = createListing(fetcher, "per_page");
|
|
1183
|
+
function milestonesPage(repo, listOptions = {}, includeAncestors) {
|
|
1184
|
+
return list(`${projectPath(repo)}/milestones`, listOptions, (raw) => toMilestone(raw), { query: {
|
|
1185
|
+
state: (listOptions.state ?? "open") === "all" ? void 0 : listOptions.state === "closed" ? "closed" : "active",
|
|
1186
|
+
include_ancestors: includeAncestors
|
|
1187
|
+
} });
|
|
1188
|
+
}
|
|
1189
|
+
async function readUser(path, signal) {
|
|
1190
|
+
const { data } = await fetcher.json(path, { signal });
|
|
1191
|
+
return {
|
|
1192
|
+
...toActor(instance, data),
|
|
1193
|
+
bio: data.bio || void 0,
|
|
1194
|
+
company: data.organization || void 0,
|
|
1195
|
+
location: data.location || void 0,
|
|
1196
|
+
websiteUrl: data.website_url || void 0,
|
|
1197
|
+
createdAt: toDate(data.created_at),
|
|
1198
|
+
followers: data.followers,
|
|
1199
|
+
following: data.following,
|
|
1200
|
+
raw: data
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
function projectPath(repo) {
|
|
1204
|
+
return `/projects/${projectId(repo)}`;
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* The listing gives only names, group templates included, so every body costs one more request. A name in both
|
|
1208
|
+
* the project and a group reads as the group's template unless the project's id picks the project's own.
|
|
1209
|
+
*/
|
|
1210
|
+
async function templates(repo, options = {}) {
|
|
1211
|
+
const signal = options.signal;
|
|
1212
|
+
const kinds = options.kind ? [options.kind] : ["issue", "pull_request"];
|
|
1213
|
+
return (await Promise.all(kinds.map(async (kind) => {
|
|
1214
|
+
const type = kind === "issue" ? "issues" : "merge_requests";
|
|
1215
|
+
const names = await Array.fromAsync(iteratePages((listOptions) => list(`${projectPath(repo)}/templates/${type}`, {
|
|
1216
|
+
...listOptions,
|
|
1217
|
+
perPage: 100,
|
|
1218
|
+
signal
|
|
1219
|
+
}, (raw) => raw)));
|
|
1220
|
+
const keys = [...new Set(names.map(({ key }) => key))];
|
|
1221
|
+
const shared = keys.filter((key) => names.filter((name) => name.key === key).length > 1);
|
|
1222
|
+
const id = shared.length ? repo.externalId ?? String((await fetcher.json(projectPath(repo), { signal })).data.id) : void 0;
|
|
1223
|
+
const read = async (key, source) => {
|
|
1224
|
+
const { data } = await fetcher.json(`${projectPath(repo)}/templates/${type}/${encodeURIComponent(key)}`, {
|
|
1225
|
+
query: { source_template_project_id: source },
|
|
1226
|
+
signal
|
|
1227
|
+
});
|
|
1228
|
+
return {
|
|
1229
|
+
kind,
|
|
1230
|
+
name: data.name,
|
|
1231
|
+
format: "markdown",
|
|
1232
|
+
body: data.content,
|
|
1233
|
+
raw: data
|
|
1234
|
+
};
|
|
1235
|
+
};
|
|
1236
|
+
const [inherited, own] = await Promise.all([mapConcurrent(keys, 4, (key) => read(key)), mapConcurrent(shared, 4, (key) => read(key, id).catch((error) => {
|
|
1237
|
+
if (error instanceof NotFoundError) return;
|
|
1238
|
+
throw error;
|
|
1239
|
+
}))]);
|
|
1240
|
+
return [...inherited, ...own.filter((template) => template !== void 0)];
|
|
1241
|
+
}))).flat();
|
|
1242
|
+
}
|
|
1243
|
+
/** GitLab has no write that creates or updates, so each file is looked up first, at the commit the change builds on. */
|
|
1244
|
+
async function commitFiles(repo, input, options) {
|
|
1245
|
+
const signal = options?.signal;
|
|
1246
|
+
const start = input.createFrom === void 0 ? void 0 : (await fetcher.json(`${projectPath(repo)}/repository/commits/${encodeURIComponent(input.createFrom)}`, { signal })).data.id;
|
|
1247
|
+
if (input.expectedHead !== void 0) {
|
|
1248
|
+
const { data } = await fetcher.json(`${projectPath(repo)}/repository/branches/${encodeURIComponent(input.branch)}`, { signal });
|
|
1249
|
+
if (data.commit?.id !== input.expectedHead.toLowerCase()) throw new BranchMovedError(`${input.branch} is at ${data.commit?.id}, not ${input.expectedHead}`, 409, "", context);
|
|
1250
|
+
}
|
|
1251
|
+
const ref = start ?? input.expectedHead ?? input.branch;
|
|
1252
|
+
const existing = await existingFiles(input.changes, async (path) => {
|
|
1253
|
+
try {
|
|
1254
|
+
return await fetcher.raw(`${projectPath(repo)}/repository/files/${encodeURIComponent(path)}`, {
|
|
1255
|
+
method: "HEAD",
|
|
1256
|
+
query: { ref },
|
|
1257
|
+
signal
|
|
1258
|
+
});
|
|
1259
|
+
} catch (error) {
|
|
1260
|
+
if (error instanceof NotFoundError) return;
|
|
1261
|
+
throw error;
|
|
1262
|
+
}
|
|
1263
|
+
}, context);
|
|
1264
|
+
const { data } = await fetcher.json(`${projectPath(repo)}/repository/commits`, {
|
|
1265
|
+
method: "POST",
|
|
1266
|
+
json: {
|
|
1267
|
+
branch: input.branch,
|
|
1268
|
+
commit_message: input.message,
|
|
1269
|
+
...start && { start_sha: start },
|
|
1270
|
+
...input.author && {
|
|
1271
|
+
author_name: input.author.name,
|
|
1272
|
+
author_email: input.author.email
|
|
1273
|
+
},
|
|
1274
|
+
actions: input.changes.map(({ path, content }) => content === null ? {
|
|
1275
|
+
action: "delete",
|
|
1276
|
+
file_path: path
|
|
1277
|
+
} : {
|
|
1278
|
+
action: existing.has(path) ? "update" : "create",
|
|
1279
|
+
file_path: path,
|
|
1280
|
+
...typeof content === "string" ? { content } : {
|
|
1281
|
+
content: changeBase64(content),
|
|
1282
|
+
encoding: "base64"
|
|
1283
|
+
}
|
|
1284
|
+
})
|
|
1285
|
+
},
|
|
1286
|
+
signal
|
|
1287
|
+
});
|
|
1288
|
+
return toCommit(repo, data);
|
|
1289
|
+
}
|
|
1290
|
+
async function ownerReposPage(owner, query = {}) {
|
|
1291
|
+
const read = (path, extra) => list(path, query, (raw) => toRepo(instance, raw), {
|
|
1292
|
+
query: {
|
|
1293
|
+
visibility: query.visibility === "all" ? void 0 : query.visibility,
|
|
1294
|
+
order_by: query.sort && PROJECT_ORDER[query.sort],
|
|
1295
|
+
sort: query.direction,
|
|
1296
|
+
...extra
|
|
1297
|
+
},
|
|
1298
|
+
warnings: query.sort === "pushed" && isFirstPage(query.cursor) ? [{
|
|
1299
|
+
code: "sort_unsupported",
|
|
1300
|
+
message: "GitLab does not report pushes; sorted by last activity, which includes issues and merge requests"
|
|
1301
|
+
}] : void 0
|
|
1302
|
+
});
|
|
1303
|
+
try {
|
|
1304
|
+
return await read(`/groups/${encodeURIComponent(owner.externalId ?? owner.owner)}/projects`, {
|
|
1305
|
+
include_subgroups: query.subgroups || void 0,
|
|
1306
|
+
with_shared: false
|
|
1307
|
+
});
|
|
1308
|
+
} catch (error) {
|
|
1309
|
+
if (!(error instanceof NotFoundError) || !isFirstPage(query.cursor) || !owner.owner || owner.owner.includes("/")) throw error;
|
|
1310
|
+
}
|
|
1311
|
+
return read(`/users/${encodeURIComponent(owner.owner)}/projects`, {});
|
|
1312
|
+
}
|
|
1313
|
+
/** Project hooks, or group hooks for a namespace ref. */
|
|
1314
|
+
function hooksPath(target) {
|
|
1315
|
+
return isNamespaceRef(target) ? `/groups/${encodeURIComponent(target.externalId ?? target.owner)}/hooks` : `${projectPath(target)}/hooks`;
|
|
1316
|
+
}
|
|
1317
|
+
/** GitLab subscribes with one boolean per event group rather than a list of names. */
|
|
1318
|
+
function hookFlags(input) {
|
|
1319
|
+
return Object.fromEntries(nativeEventsFor(GITLAB_NATIVE_EVENTS, input.events, input.nativeEvents).map((flag) => [flag, true]));
|
|
1320
|
+
}
|
|
1321
|
+
function requireMerge(thread, action) {
|
|
1322
|
+
const ref = requireThread(thread, context);
|
|
1323
|
+
if (ref.kind !== "pull_request") throw new UnsupportedOperationError(`Only merge requests can be ${action}`, context);
|
|
1324
|
+
return ref;
|
|
1325
|
+
}
|
|
1326
|
+
/** GitLab's file endpoint needs an explicit ref, so the project's default branch stands in. */
|
|
1327
|
+
async function defaultBranch(repo, options) {
|
|
1328
|
+
const { data } = await fetcher.json(projectPath(repo), { signal: options?.signal });
|
|
1329
|
+
return data.default_branch ?? "HEAD";
|
|
1330
|
+
}
|
|
1331
|
+
async function get(thread, options) {
|
|
1332
|
+
const ref = requireThread(thread, context);
|
|
1333
|
+
if (ref.kind === "discussion") throw new UnsupportedOperationError("GitLab has no discussion threads", context);
|
|
1334
|
+
const { data } = await fetcher.json(threadPath(ref), { signal: options?.signal });
|
|
1335
|
+
const result = toThread(ref, data);
|
|
1336
|
+
if (data.head_pipeline) result.checks = toPipelineSummary(data.head_pipeline);
|
|
1337
|
+
return result;
|
|
1338
|
+
}
|
|
1339
|
+
const graphqlUrl = `${baseUrl.replace(/\/api\/v4$/, "")}/api/graphql`;
|
|
1340
|
+
async function vulnerabilitiesPage(repo, listOptions = {}) {
|
|
1341
|
+
const state = listOptions.state ?? "open";
|
|
1342
|
+
const { data, response } = await fetcher.json(graphqlUrl, {
|
|
1343
|
+
method: "POST",
|
|
1344
|
+
json: {
|
|
1345
|
+
operationName: "ProjectVulnerabilities",
|
|
1346
|
+
query: VULNERABILITIES_QUERY,
|
|
1347
|
+
variables: {
|
|
1348
|
+
fullPath: `${repo.owner}/${repo.name}`,
|
|
1349
|
+
first: Math.min(listOptions.perPage ?? 50, 100),
|
|
1350
|
+
after: listOptions.cursor?.token ?? null,
|
|
1351
|
+
state: state === "open" ? ["DETECTED", "CONFIRMED"] : state === "closed" ? ["RESOLVED", "DISMISSED"] : null,
|
|
1352
|
+
reportType: listOptions.kind ? REPORT_TYPES[listOptions.kind] : null
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
signal: listOptions.signal
|
|
1356
|
+
});
|
|
1357
|
+
const vulnerabilities = data.data?.project?.vulnerabilities;
|
|
1358
|
+
if (!vulnerabilities) {
|
|
1359
|
+
const error = new InsufficientScopeError(data.errors?.[0]?.message ?? "The token cannot read vulnerabilities for this project, or its licence has no vulnerability report", 403, "", context);
|
|
1360
|
+
if (listOptions.kind) throw error;
|
|
1361
|
+
return {
|
|
1362
|
+
items: [],
|
|
1363
|
+
warnings: [toWarning("insufficient_scope", error, `${repo.owner}/${repo.name}`)]
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
return {
|
|
1367
|
+
items: vulnerabilities.nodes.map((node) => toVulnerability(repo, node)),
|
|
1368
|
+
cursor: vulnerabilities.pageInfo.hasNextPage && vulnerabilities.pageInfo.endCursor ? { token: vulnerabilities.pageInfo.endCursor } : void 0,
|
|
1369
|
+
...rateLimitPart(response)
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
async function releasesPage(repo, listOptions = {}) {
|
|
1373
|
+
return list(`${projectPath(repo)}/releases`, listOptions, (raw) => toRelease(repo, raw));
|
|
1374
|
+
}
|
|
1375
|
+
function requirePublishedRelease(input) {
|
|
1376
|
+
if (input.draft) throw new UnsupportedOperationError("GitLab has no draft releases", context);
|
|
1377
|
+
if (input.prerelease) throw new UnsupportedOperationError("GitLab has no prereleases", context);
|
|
1378
|
+
}
|
|
1379
|
+
async function listPage(repo, query = {}) {
|
|
1380
|
+
if (query.kind === "discussion") return {
|
|
1381
|
+
items: [],
|
|
1382
|
+
warnings: [{
|
|
1383
|
+
code: "kind_unsupported",
|
|
1384
|
+
message: "GitLab has no discussion threads"
|
|
1385
|
+
}]
|
|
1386
|
+
};
|
|
1387
|
+
const warnings = isFirstPage(query.cursor) && query.sort === "comments" ? [{
|
|
1388
|
+
code: "sort_unsupported",
|
|
1389
|
+
message: "GitLab cannot sort by comment count; sorted by creation time"
|
|
1390
|
+
}] : [];
|
|
1391
|
+
const state = query.state ?? "open";
|
|
1392
|
+
const kinds = query.kind ? [query.kind] : ["issue", "pull_request"];
|
|
1393
|
+
const page = await phased(kinds.map((kind) => async (cursor) => {
|
|
1394
|
+
const merges = kind === "pull_request";
|
|
1395
|
+
const result = await fetcher.page(`${projectPath(repo)}/${merges ? "merge_requests" : "issues"}`, {
|
|
1396
|
+
query: {
|
|
1397
|
+
state: state === "open" ? "opened" : state === "merged" ? "merged" : state === "closed" && !merges ? "closed" : void 0,
|
|
1398
|
+
labels: query.labels?.join(","),
|
|
1399
|
+
author_username: query.author,
|
|
1400
|
+
assignee_username: query.assignee,
|
|
1401
|
+
updated_after: query.since?.toISOString(),
|
|
1402
|
+
created_after: query.createdAfter?.toISOString(),
|
|
1403
|
+
order_by: query.sort === "updated" ? "updated_at" : "created_at",
|
|
1404
|
+
sort: query.direction ?? "desc",
|
|
1405
|
+
per_page: query.perPage
|
|
1406
|
+
},
|
|
1407
|
+
cursor,
|
|
1408
|
+
signal: query.signal
|
|
1409
|
+
});
|
|
1410
|
+
return toPage(result, (raw) => merges && state === "closed" && raw.state === "opened" ? void 0 : toThread({
|
|
1411
|
+
forge: FORGE,
|
|
1412
|
+
instance,
|
|
1413
|
+
repo,
|
|
1414
|
+
kind,
|
|
1415
|
+
number: String(raw.iid)
|
|
1416
|
+
}, raw));
|
|
1417
|
+
}), query.cursor);
|
|
1418
|
+
return warnings.length ? {
|
|
1419
|
+
...page,
|
|
1420
|
+
warnings
|
|
1421
|
+
} : page;
|
|
1422
|
+
}
|
|
1423
|
+
/** Cross-project search runs on the global issue and merge request listings, which take `search` and `in`. */
|
|
1424
|
+
async function searchThreadsPage(query) {
|
|
1425
|
+
const warnings = [];
|
|
1426
|
+
if (isFirstPage(query.cursor) && query.involves) warnings.push({
|
|
1427
|
+
code: "filter_unsupported",
|
|
1428
|
+
message: "GitLab has no involves filter; it was ignored"
|
|
1429
|
+
});
|
|
1430
|
+
if (isFirstPage(query.cursor) && query.sort === "comments") warnings.push({
|
|
1431
|
+
code: "sort_unsupported",
|
|
1432
|
+
message: "GitLab cannot sort by comment count; sorted by update time"
|
|
1433
|
+
});
|
|
1434
|
+
const state = query.state ?? "all";
|
|
1435
|
+
const kinds = query.kind ? [query.kind] : ["issue", "pull_request"];
|
|
1436
|
+
const page = await phased(kinds.map((kind) => async (cursor) => {
|
|
1437
|
+
const merges = kind === "pull_request";
|
|
1438
|
+
const base = query.repo ? `${projectPath(query.repo)}/` : query.owner ? `/groups/${encodeURIComponent(query.owner)}/` : "/";
|
|
1439
|
+
const result = await fetcher.page(`${base}${merges ? "merge_requests" : "issues"}`, {
|
|
1440
|
+
query: {
|
|
1441
|
+
scope: query.repo ? void 0 : "all",
|
|
1442
|
+
search: query.text,
|
|
1443
|
+
in: query.text ? "title,description" : void 0,
|
|
1444
|
+
state: state === "open" ? "opened" : state === "closed" ? "closed" : void 0,
|
|
1445
|
+
labels: query.labels?.join(","),
|
|
1446
|
+
author_username: query.author,
|
|
1447
|
+
assignee_username: query.assignee,
|
|
1448
|
+
updated_after: query.since?.toISOString(),
|
|
1449
|
+
order_by: query.sort === "created" ? "created_at" : "updated_at",
|
|
1450
|
+
sort: query.direction ?? "desc",
|
|
1451
|
+
per_page: query.perPage
|
|
1452
|
+
},
|
|
1453
|
+
cursor,
|
|
1454
|
+
signal: query.signal
|
|
1455
|
+
});
|
|
1456
|
+
return toPage(result, (raw) => {
|
|
1457
|
+
const repo = query.repo ?? repoRefFromWebUrl(instance, raw.web_url, merges ? raw.target_project_id : void 0);
|
|
1458
|
+
return repo ? toThread({
|
|
1459
|
+
forge: FORGE,
|
|
1460
|
+
instance,
|
|
1461
|
+
repo,
|
|
1462
|
+
kind,
|
|
1463
|
+
number: String(raw.iid)
|
|
1464
|
+
}, raw) : void 0;
|
|
1465
|
+
});
|
|
1466
|
+
}), query.cursor);
|
|
1467
|
+
return warnings.length ? {
|
|
1468
|
+
...page,
|
|
1469
|
+
warnings: [...warnings, ...page.warnings ?? []]
|
|
1470
|
+
} : page;
|
|
1471
|
+
}
|
|
1472
|
+
async function searchReposPage(query) {
|
|
1473
|
+
const path = query.owner ? `/groups/${encodeURIComponent(query.owner)}/projects` : "/projects";
|
|
1474
|
+
const result = await fetcher.page(path, {
|
|
1475
|
+
query: {
|
|
1476
|
+
search: query.text,
|
|
1477
|
+
order_by: query.sort === "created" ? "created_at" : query.sort === "stars" ? "star_count" : query.sort === "updated" ? "updated_at" : void 0,
|
|
1478
|
+
sort: query.direction,
|
|
1479
|
+
per_page: query.perPage
|
|
1480
|
+
},
|
|
1481
|
+
cursor: query.cursor,
|
|
1482
|
+
signal: query.signal
|
|
1483
|
+
});
|
|
1484
|
+
return toPage(result, (raw) => toRepo(instance, raw));
|
|
1485
|
+
}
|
|
1486
|
+
/** Needs Advanced Search, which no endpoint reports; an instance without it returns an empty page. */
|
|
1487
|
+
async function searchCommitsPage(query) {
|
|
1488
|
+
const unsupported = [
|
|
1489
|
+
"author",
|
|
1490
|
+
"committer",
|
|
1491
|
+
"since",
|
|
1492
|
+
"until",
|
|
1493
|
+
"sort"
|
|
1494
|
+
].filter((field) => query[field] !== void 0);
|
|
1495
|
+
const warnings = unsupported.length ? [{
|
|
1496
|
+
code: "filter_unsupported",
|
|
1497
|
+
message: `GitLab commit search cannot filter or sort by ${unsupported.join(", ")}`
|
|
1498
|
+
}] : [];
|
|
1499
|
+
const result = await fetcher.page(query.repo ? `${projectPath(query.repo)}/search` : "/search", {
|
|
1500
|
+
query: {
|
|
1501
|
+
scope: "commits",
|
|
1502
|
+
search: query.text ?? "",
|
|
1503
|
+
per_page: query.perPage
|
|
1504
|
+
},
|
|
1505
|
+
cursor: query.cursor,
|
|
1506
|
+
signal: query.signal
|
|
1507
|
+
});
|
|
1508
|
+
const repo = query.repo;
|
|
1509
|
+
return toPage(result, (raw) => repo && toCommit(repo, raw), warnings);
|
|
1510
|
+
}
|
|
1511
|
+
/** Projects that code searches and user events named by id, kept so later pages skip the lookup. */
|
|
1512
|
+
const projectRefs = /* @__PURE__ */ new Map();
|
|
1513
|
+
/** A project the token cannot read costs its blobs and a warning, not the page. */
|
|
1514
|
+
async function resolveProjects(ids, signal, warnings) {
|
|
1515
|
+
if (!ids.length) return;
|
|
1516
|
+
try {
|
|
1517
|
+
const { data } = await fetcher.json(graphqlUrl, {
|
|
1518
|
+
method: "POST",
|
|
1519
|
+
json: {
|
|
1520
|
+
operationName: "CodeSearchProjects",
|
|
1521
|
+
query: PROJECTS_QUERY,
|
|
1522
|
+
variables: { ids: ids.map((id) => `gid://gitlab/Project/${id}`) }
|
|
1523
|
+
},
|
|
1524
|
+
signal
|
|
1525
|
+
});
|
|
1526
|
+
for (const node of data.data?.projects?.nodes ?? []) {
|
|
1527
|
+
const id = Number(node.id.slice(node.id.lastIndexOf("/") + 1));
|
|
1528
|
+
projectRefs.set(id, toRepoRef(instance, node.fullPath, id));
|
|
1529
|
+
}
|
|
1530
|
+
} catch (error) {
|
|
1531
|
+
if (!degradesToWarning(error)) throw error;
|
|
1532
|
+
warnings.push(...ids.map((id) => toWarning("record_unreachable", error, `project ${id}`)));
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
for (const id of ids.filter((id) => !projectRefs.has(id))) warnings.push({
|
|
1536
|
+
code: "record_unreachable",
|
|
1537
|
+
message: "GitLab returned no project for this id",
|
|
1538
|
+
subject: `project ${id}`
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
/** Any tier searches a project; a group or the instance needs Advanced Search or exact code search. */
|
|
1542
|
+
async function searchCodePage(query) {
|
|
1543
|
+
const path = query.repo ? `${projectPath(query.repo)}/search` : query.owner ? `/groups/${encodeURIComponent(query.owner)}/search` : "/search";
|
|
1544
|
+
const result = await fetcher.page(path, {
|
|
1545
|
+
query: {
|
|
1546
|
+
scope: "blobs",
|
|
1547
|
+
search: query.text ?? "",
|
|
1548
|
+
per_page: query.perPage
|
|
1549
|
+
},
|
|
1550
|
+
cursor: query.cursor,
|
|
1551
|
+
signal: query.signal
|
|
1552
|
+
});
|
|
1553
|
+
const warnings = [];
|
|
1554
|
+
await resolveProjects(query.repo ? [] : [...new Set((result.data ?? []).map((raw) => raw.project_id))].filter((id) => !projectRefs.has(id)), query.signal, warnings);
|
|
1555
|
+
/** GitLab returns one blob per excerpt; basic search lists a file again, with the same first excerpt, when its name matches too. */
|
|
1556
|
+
const files = /* @__PURE__ */ new Map();
|
|
1557
|
+
for (const blob of result.data ?? []) {
|
|
1558
|
+
const key = `${blob.project_id}:${blob.ref}:${blob.path}`;
|
|
1559
|
+
const excerpts = files.get(key);
|
|
1560
|
+
if (!excerpts) files.set(key, [blob]);
|
|
1561
|
+
else if (!excerpts.some((seen) => seen.startline === blob.startline && seen.data === blob.data)) excerpts.push(blob);
|
|
1562
|
+
}
|
|
1563
|
+
return toPage({
|
|
1564
|
+
...result,
|
|
1565
|
+
data: [...files.values()]
|
|
1566
|
+
}, (excerpts) => {
|
|
1567
|
+
const [first] = excerpts;
|
|
1568
|
+
const repo = query.repo ?? projectRefs.get(first.project_id);
|
|
1569
|
+
if (!repo) return;
|
|
1570
|
+
const url = webUrlFor(web, { file: {
|
|
1571
|
+
repo,
|
|
1572
|
+
path: first.path,
|
|
1573
|
+
at: first.ref,
|
|
1574
|
+
line: first.startline
|
|
1575
|
+
} });
|
|
1576
|
+
return {
|
|
1577
|
+
repo,
|
|
1578
|
+
path: first.path,
|
|
1579
|
+
ref: first.ref,
|
|
1580
|
+
fragments: excerpts.map((raw) => ({
|
|
1581
|
+
text: raw.data,
|
|
1582
|
+
line: raw.startline
|
|
1583
|
+
})),
|
|
1584
|
+
url,
|
|
1585
|
+
raw: excerpts
|
|
1586
|
+
};
|
|
1587
|
+
}, warnings);
|
|
1588
|
+
}
|
|
1589
|
+
/** A user's events name each project by id alone, so the page resolves the ids it has not seen. */
|
|
1590
|
+
async function feedPage(path, listOptions, repo) {
|
|
1591
|
+
const result = await fetcher.page(path, {
|
|
1592
|
+
query: { per_page: listOptions.perPage },
|
|
1593
|
+
cursor: listOptions.cursor,
|
|
1594
|
+
signal: listOptions.signal
|
|
1595
|
+
});
|
|
1596
|
+
const warnings = [];
|
|
1597
|
+
if (!repo) await resolveProjects([...new Set((result.data ?? []).flatMap((raw) => typeof raw.project_id === "number" ? [raw.project_id] : []))].filter((id) => !projectRefs.has(id)), listOptions.signal, warnings);
|
|
1598
|
+
const { toFeedEvent } = await import("./feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js");
|
|
1599
|
+
return toPage(result, (raw) => toFeedEvent(instance, raw, repo ?? (typeof raw.project_id === "number" ? projectRefs.get(raw.project_id) : void 0)), warnings);
|
|
1600
|
+
}
|
|
1601
|
+
async function setSubscribed(thread, subscribed, options) {
|
|
1602
|
+
const ref = requireIssueOrPull(thread, context, subscribed ? "subscribe to" : "unsubscribe from");
|
|
1603
|
+
await fetcher.raw(`${threadPath(ref)}/${subscribed ? "subscribe" : "unsubscribe"}`, {
|
|
1604
|
+
method: "POST",
|
|
1605
|
+
signal: options?.signal
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
async function unsubscribe(_ref, writeOptions = {}) {
|
|
1609
|
+
if (!writeOptions.thread) throw new UnresolvedThreadError("GitLab cannot look up a to-do by id; pass { thread } to unsubscribe", context);
|
|
1610
|
+
const thread = requireThread(writeOptions.thread, context);
|
|
1611
|
+
if (thread.kind !== "issue" && thread.kind !== "pull_request") throw new UnsupportedOperationError(`GitLab cannot unsubscribe from a ${thread.kind}`, context);
|
|
1612
|
+
await fetcher.raw(`${threadPath(thread)}/unsubscribe`, {
|
|
1613
|
+
method: "POST",
|
|
1614
|
+
signal: writeOptions.signal
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
async function setState(thread, stateEvent, options) {
|
|
1618
|
+
const ref = requireIssueOrPull(thread, context, stateEvent);
|
|
1619
|
+
const { data } = await fetcher.json(threadPath(ref), {
|
|
1620
|
+
method: "PUT",
|
|
1621
|
+
json: { state_event: stateEvent },
|
|
1622
|
+
signal: options?.signal
|
|
1623
|
+
});
|
|
1624
|
+
return toThread(ref, data);
|
|
1625
|
+
}
|
|
1626
|
+
async function setLocked(thread, locked, options) {
|
|
1627
|
+
const ref = requireIssueOrPull(thread, context, locked ? "lock" : "unlock");
|
|
1628
|
+
await fetcher.raw(threadPath(ref), {
|
|
1629
|
+
method: "PUT",
|
|
1630
|
+
json: { discussion_locked: locked },
|
|
1631
|
+
signal: options?.signal
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
async function resolveMergeMethod(ref, requested, signal) {
|
|
1635
|
+
if (requested === "squash") return requested;
|
|
1636
|
+
const { data: project } = await fetcher.json(`/projects/${projectId(ref.repo)}`, { signal });
|
|
1637
|
+
const base = BASE_METHODS[project.merge_method ?? "merge"];
|
|
1638
|
+
const squash = project.squash_option ?? "default_off";
|
|
1639
|
+
if (requested) {
|
|
1640
|
+
if (requested !== base || squash === "always") throw new UnsupportedOperationError(`This project merges with ${squash === "always" ? "squash" : base}; GitLab cannot override it per merge request`, context);
|
|
1641
|
+
return requested;
|
|
1642
|
+
}
|
|
1643
|
+
return soleMergeMethod({
|
|
1644
|
+
[base]: squash !== "always",
|
|
1645
|
+
squash: squash !== "never"
|
|
1646
|
+
}, context);
|
|
1647
|
+
}
|
|
1648
|
+
/** GitLab has approvals, not reviews: one synthesised review per approver, with no comments to hang on it. */
|
|
1649
|
+
function toApprovalReviews(ref, approvals) {
|
|
1650
|
+
return (approvals.approved_by ?? []).map(({ user }) => syntheticReview(ref, approvalId(user), "approved", {
|
|
1651
|
+
author: toActor(instance, user),
|
|
1652
|
+
stateRaw: "approved",
|
|
1653
|
+
raw: user
|
|
1654
|
+
}));
|
|
1655
|
+
}
|
|
1656
|
+
async function approve(thread, body, options) {
|
|
1657
|
+
const ref = requireThread(thread, context);
|
|
1658
|
+
if (ref.kind !== "pull_request") throw new UnsupportedOperationError("Only merge requests can be approved", context);
|
|
1659
|
+
if (body) throw new UnsupportedOperationError("GitLab approvals carry no body; leave a comment instead", context);
|
|
1660
|
+
const { data } = await fetcher.json(`${threadPath(ref)}/approve`, {
|
|
1661
|
+
method: "POST",
|
|
1662
|
+
signal: options?.signal,
|
|
1663
|
+
mapError: (error) => error instanceof TokenRevokedError ? new InsufficientScopeError("Not allowed to approve this merge request", 401, error.body, {
|
|
1664
|
+
...context,
|
|
1665
|
+
url: error.url,
|
|
1666
|
+
method: error.method
|
|
1667
|
+
}, { cause: error }) : error
|
|
1668
|
+
});
|
|
1669
|
+
const reviews = toApprovalReviews(ref, data);
|
|
1670
|
+
const viewer = reviews.length > 1 ? await viewerLogin() : void 0;
|
|
1671
|
+
return reviews.find((review) => viewer !== void 0 && review.author?.login === viewer) ?? reviews.at(-1) ?? {
|
|
1672
|
+
ref: {
|
|
1673
|
+
forge: "gitlab",
|
|
1674
|
+
instance,
|
|
1675
|
+
thread: ref,
|
|
1676
|
+
id: "approval:"
|
|
1677
|
+
},
|
|
1678
|
+
state: "approved",
|
|
1679
|
+
stateRaw: "approved",
|
|
1680
|
+
comments: false,
|
|
1681
|
+
raw: data
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
async function merge(thread, mergeOptions = {}) {
|
|
1685
|
+
const ref = requireThread(thread, context);
|
|
1686
|
+
if (ref.kind !== "pull_request") throw new UnsupportedOperationError("Only merge requests can be merged", context);
|
|
1687
|
+
const method = await resolveMergeMethod(ref, mergeOptions.method, mergeOptions.signal);
|
|
1688
|
+
const message = mergeCommitMessage(mergeOptions);
|
|
1689
|
+
const { data } = await fetcher.json(`${threadPath(ref)}/merge`, {
|
|
1690
|
+
method: "PUT",
|
|
1691
|
+
json: {
|
|
1692
|
+
sha: mergeOptions.sha,
|
|
1693
|
+
...message ? { [method === "squash" ? "squash_commit_message" : "merge_commit_message"]: message } : {},
|
|
1694
|
+
squash: method === "squash",
|
|
1695
|
+
merge_when_pipeline_succeeds: mergeOptions.whenChecksPass ?? false
|
|
1696
|
+
},
|
|
1697
|
+
mapError: toMergeError,
|
|
1698
|
+
signal: mergeOptions.signal
|
|
1699
|
+
});
|
|
1700
|
+
return data.state === "merged" ? {
|
|
1701
|
+
status: "merged",
|
|
1702
|
+
sha: data.merge_commit_sha ?? data.squash_commit_sha ?? void 0,
|
|
1703
|
+
raw: data
|
|
1704
|
+
} : {
|
|
1705
|
+
status: "queued",
|
|
1706
|
+
raw: data
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
/** An issue or merge request from a listing that spans projects, or `undefined` for one from an external issue tracker. */
|
|
1710
|
+
function referencedThread(raw, kind) {
|
|
1711
|
+
const path = raw.references?.full?.replace(/[#!]\d+$/, "");
|
|
1712
|
+
const project = kind === "pull_request" ? raw.target_project_id : raw.project_id;
|
|
1713
|
+
const repo = path ? toRepoRef(instance, path, project) : repoRefFromWebUrl(instance, raw.web_url, project);
|
|
1714
|
+
return repo && raw.iid !== void 0 ? toThread({
|
|
1715
|
+
forge: FORGE,
|
|
1716
|
+
instance,
|
|
1717
|
+
repo,
|
|
1718
|
+
kind,
|
|
1719
|
+
number: String(raw.iid)
|
|
1720
|
+
}, raw) : void 0;
|
|
1721
|
+
}
|
|
1722
|
+
/** GitLab rebases only, in the background, and takes no expected head, so `sha` is compared against a read of the merge request first. */
|
|
1723
|
+
async function updateBranch(thread, updateOptions = {}) {
|
|
1724
|
+
const ref = requireThread(thread, context);
|
|
1725
|
+
if (ref.kind !== "pull_request") throw new UnsupportedOperationError("Only merge requests can be updated", context);
|
|
1726
|
+
if (updateOptions.method === "merge") throw new UnsupportedOperationError("GitLab updates a merge request by rebasing it only", context);
|
|
1727
|
+
const { sha, signal } = updateOptions;
|
|
1728
|
+
if (sha !== void 0) {
|
|
1729
|
+
const { data } = await fetcher.json(threadPath(ref), { signal });
|
|
1730
|
+
if (data.sha !== sha) throw new BranchMovedError(`Source branch of merge request ${ref.number} is at ${data.sha}, not ${sha}`, 409, "", context);
|
|
1731
|
+
}
|
|
1732
|
+
const { data } = await fetcher.json(`${threadPath(ref)}/rebase`, {
|
|
1733
|
+
method: "PUT",
|
|
1734
|
+
signal
|
|
1735
|
+
});
|
|
1736
|
+
return {
|
|
1737
|
+
status: "queued",
|
|
1738
|
+
raw: data
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
return {
|
|
1742
|
+
traits: {
|
|
1743
|
+
eventKinds: "heuristic",
|
|
1744
|
+
authKinds: ["token", "anonymous"],
|
|
1745
|
+
limits: {
|
|
1746
|
+
bodyLength: 1048576,
|
|
1747
|
+
commentLength: 1e6,
|
|
1748
|
+
labelLength: 255
|
|
1749
|
+
}
|
|
1750
|
+
},
|
|
1751
|
+
notApplicable: ["threads.hideComment"],
|
|
1752
|
+
probeVersion: async () => (await fetcher.json("/version")).data.version,
|
|
1753
|
+
web,
|
|
1754
|
+
webhooks: {
|
|
1755
|
+
listPage: verb(true, (target, listOptions = {}) => list(hooksPath(target), listOptions, (raw) => toWebhook(target, raw))),
|
|
1756
|
+
create: verb(true, async (target, input, options) => toWebhook(target, (await fetcher.json(hooksPath(target), {
|
|
1757
|
+
method: "POST",
|
|
1758
|
+
json: {
|
|
1759
|
+
url: input.url,
|
|
1760
|
+
token: input.secret,
|
|
1761
|
+
...hookFlags(input)
|
|
1762
|
+
},
|
|
1763
|
+
signal: options?.signal
|
|
1764
|
+
})).data)),
|
|
1765
|
+
update: verb(true, async (ref, update, options) => toWebhook(ref.target, (await fetcher.json(`${hooksPath(ref.target)}/${ref.id}`, {
|
|
1766
|
+
method: "PUT",
|
|
1767
|
+
json: {
|
|
1768
|
+
...update.url ? { url: update.url } : {},
|
|
1769
|
+
...update.secret ? { token: update.secret } : {},
|
|
1770
|
+
...hookFlags(update)
|
|
1771
|
+
},
|
|
1772
|
+
signal: options?.signal
|
|
1773
|
+
})).data)),
|
|
1774
|
+
delete: verb(true, async (ref, options) => {
|
|
1775
|
+
await fetcher.raw(`${hooksPath(ref.target)}/${ref.id}`, {
|
|
1776
|
+
method: "DELETE",
|
|
1777
|
+
signal: options?.signal
|
|
1778
|
+
});
|
|
1779
|
+
}),
|
|
1780
|
+
rotateSecret: verb(true, async (ref, secret, options) => toWebhook(ref.target, (await fetcher.json(`${hooksPath(ref.target)}/${ref.id}`, {
|
|
1781
|
+
method: "PUT",
|
|
1782
|
+
json: { token: secret },
|
|
1783
|
+
signal: options?.signal
|
|
1784
|
+
})).data)),
|
|
1785
|
+
deliveriesPage: verb(({ version }) => versionAtLeast(version, GITLAB_HOOK_EVENTS), (ref, listOptions = {}) => list(`${hooksPath(ref.target)}/${ref.id}/events`, listOptions, (raw) => toWebhookDelivery(ref, raw))),
|
|
1786
|
+
redeliver: verb(({ version }) => versionAtLeast(version, GITLAB_HOOK_EVENTS), async (ref, options) => {
|
|
1787
|
+
await fetcher.raw(`${hooksPath(ref.hook.target)}/${ref.hook.id}/events/${ref.id}/resend`, {
|
|
1788
|
+
method: "POST",
|
|
1789
|
+
signal: options?.signal
|
|
1790
|
+
});
|
|
1791
|
+
})
|
|
1792
|
+
},
|
|
1793
|
+
scopes: gitlabScopesFor,
|
|
1794
|
+
users: {
|
|
1795
|
+
get: verb(true, async (login, options) => {
|
|
1796
|
+
const { data: matches } = await fetcher.json("/users", {
|
|
1797
|
+
query: { username: login },
|
|
1798
|
+
signal: options?.signal
|
|
1799
|
+
});
|
|
1800
|
+
const [match] = matches ?? [];
|
|
1801
|
+
if (!match) throw new NotFoundError(`No GitLab user named ${login}`, 404, "", context);
|
|
1802
|
+
try {
|
|
1803
|
+
return await readUser(`/users/${match.id}`, options?.signal);
|
|
1804
|
+
} catch (error) {
|
|
1805
|
+
if (error instanceof InsufficientScopeError || error instanceof AuthenticationRequiredError) return {
|
|
1806
|
+
...toActor(instance, match),
|
|
1807
|
+
raw: match
|
|
1808
|
+
};
|
|
1809
|
+
throw error;
|
|
1810
|
+
}
|
|
1811
|
+
}),
|
|
1812
|
+
me: verb(true, (options) => readUser("/user", options?.signal)),
|
|
1813
|
+
eventsPage: verb(true, (login, listOptions = {}) => feedPage(`/users/${encodeURIComponent(login)}/events`, listOptions))
|
|
1814
|
+
},
|
|
1815
|
+
repos: {
|
|
1816
|
+
get: verb(true, async (ref, options) => {
|
|
1817
|
+
const query = options?.licence ? { license: true } : void 0;
|
|
1818
|
+
return toRepo(instance, (await fetcher.json(projectPath(ref), {
|
|
1819
|
+
query,
|
|
1820
|
+
signal: options?.signal
|
|
1821
|
+
})).data);
|
|
1822
|
+
}),
|
|
1823
|
+
listPage: verb(true, (listOptions = {}) => list("/projects", listOptions, (raw) => toRepo(instance, raw), { query: { membership: true } })),
|
|
1824
|
+
byOwnerPage: verb(true, ownerReposPage),
|
|
1825
|
+
labelsPage: verb(!anonymous, (repo, listOptions = {}) => list(`${projectPath(repo)}/labels`, listOptions, toLabel)),
|
|
1826
|
+
createLabel: verb(true, async (repo, label, options) => toLabel((await fetcher.json(`${projectPath(repo)}/labels`, {
|
|
1827
|
+
method: "POST",
|
|
1828
|
+
json: {
|
|
1829
|
+
name: label.name,
|
|
1830
|
+
color: hexColour(label.colour, "#"),
|
|
1831
|
+
description: label.description
|
|
1832
|
+
},
|
|
1833
|
+
signal: options?.signal
|
|
1834
|
+
})).data)),
|
|
1835
|
+
milestonesPage: verb(!anonymous, milestonesPage),
|
|
1836
|
+
collaboratorsPage: verb(!anonymous, (repo, listOptions = {}) => list(`${projectPath(repo)}/members/all`, listOptions, (raw) => ({
|
|
1837
|
+
actor: toActor(instance, raw),
|
|
1838
|
+
role: toRole(raw.access_level),
|
|
1839
|
+
roleRaw: String(raw.access_level),
|
|
1840
|
+
raw
|
|
1841
|
+
}))),
|
|
1842
|
+
templates: verb(true, templates),
|
|
1843
|
+
contributorsPage: verb(true, (repo, listOptions = {}) => list(`${projectPath(repo)}/repository/contributors`, listOptions, (raw) => ({
|
|
1844
|
+
name: raw.name || void 0,
|
|
1845
|
+
email: raw.email || void 0,
|
|
1846
|
+
contributions: raw.commits,
|
|
1847
|
+
raw
|
|
1848
|
+
}), {
|
|
1849
|
+
query: {
|
|
1850
|
+
order_by: "commits",
|
|
1851
|
+
sort: "desc"
|
|
1852
|
+
},
|
|
1853
|
+
warnings: listOptions.includeUnlinked === false && isFirstPage(listOptions.cursor) ? [{
|
|
1854
|
+
code: "filter_unsupported",
|
|
1855
|
+
message: "GitLab links no contributor accounts, so it cannot leave the unlinked ones out; the option was ignored"
|
|
1856
|
+
}] : []
|
|
1857
|
+
})),
|
|
1858
|
+
permissionFor: verb(!anonymous, async (repo, actor, options) => {
|
|
1859
|
+
try {
|
|
1860
|
+
const { data } = await fetcher.json(`${projectPath(repo)}/members/all/${await userId(actor)}`, { signal: options?.signal });
|
|
1861
|
+
return toRole(data.access_level);
|
|
1862
|
+
} catch (error) {
|
|
1863
|
+
if (error instanceof NotFoundError) return "none";
|
|
1864
|
+
throw error;
|
|
1865
|
+
}
|
|
1866
|
+
}),
|
|
1867
|
+
branchRules: verb(!anonymous, async (repo, name, options) => {
|
|
1868
|
+
const warnings = [];
|
|
1869
|
+
const [{ data: branch }, { data: project }, rules] = await Promise.all([
|
|
1870
|
+
fetcher.json(`${projectPath(repo)}/repository/branches/${encodeURIComponent(name)}`, { signal: options?.signal }),
|
|
1871
|
+
fetcher.json(projectPath(repo), { signal: options?.signal }),
|
|
1872
|
+
Array.fromAsync(fetcher.items(`${projectPath(repo)}/approval_rules`, {
|
|
1873
|
+
query: { per_page: 100 },
|
|
1874
|
+
signal: options?.signal
|
|
1875
|
+
})).catch((error) => {
|
|
1876
|
+
if (!(error instanceof ForbiddenError || error instanceof InsufficientScopeError || error instanceof NotFoundError)) throw error;
|
|
1877
|
+
warnings.push(toWarning("insufficient_scope", error, "approval_rules"));
|
|
1878
|
+
})
|
|
1879
|
+
]);
|
|
1880
|
+
return toBranchRules(branch, project, rules, warnings);
|
|
1881
|
+
}),
|
|
1882
|
+
addCollaborator: verb(true, async (repo, actor, role, options) => {
|
|
1883
|
+
await fetcher.raw(`${projectPath(repo)}/members`, {
|
|
1884
|
+
method: "POST",
|
|
1885
|
+
json: {
|
|
1886
|
+
user_id: await userId(actor),
|
|
1887
|
+
access_level: ACCESS_LEVELS[role]
|
|
1888
|
+
},
|
|
1889
|
+
signal: options?.signal
|
|
1890
|
+
});
|
|
1891
|
+
return { status: "added" };
|
|
1892
|
+
}),
|
|
1893
|
+
assignableUsersPage: verb(true, (repo, listOptions = {}) => list(`${projectPath(repo)}/users`, listOptions, (raw) => toActor(instance, raw))),
|
|
1894
|
+
reviewerCandidatesPage: verb("emulated", (thread, listOptions = {}) => list(`${projectPath(requireThread(thread, context).repo)}/users`, listOptions, (raw) => toActor(instance, raw))),
|
|
1895
|
+
eventsPage: verb(true, (repo, listOptions = {}) => feedPage(`${projectPath(repo)}/events`, listOptions, repo))
|
|
1896
|
+
},
|
|
1897
|
+
orgs: {
|
|
1898
|
+
/** GitLab has no teams, so a subgroup stands in for one. With a token, GitLab lists only the account's own subgroups unless `all_available` is set. */
|
|
1899
|
+
teamsPage: verb(true, (org, listOptions = {}) => list(`/groups/${encodeURIComponent(org.externalId ?? org.owner)}/descendant_groups`, listOptions, (raw) => toTeam(instance, teamOrg(org), raw), { query: { all_available: true } })),
|
|
1900
|
+
teamMembersPage: verb(!anonymous, (team, listOptions = {}) => list(`/groups/${encodeURIComponent(team.id ?? `${team.org.owner}/${team.slug}`)}/members`, listOptions, (raw) => toActor(instance, raw)))
|
|
1901
|
+
},
|
|
1902
|
+
notifications: {
|
|
1903
|
+
listPage: verb(true, notificationPage),
|
|
1904
|
+
markDone: verb(true, async (ref, options) => {
|
|
1905
|
+
await fetcher.raw(`/todos/${ref.id}/mark_as_done`, {
|
|
1906
|
+
method: "POST",
|
|
1907
|
+
signal: options?.signal
|
|
1908
|
+
});
|
|
1909
|
+
}),
|
|
1910
|
+
unsubscribe: verb(true, unsubscribe),
|
|
1911
|
+
markAllDone: verb(true, async (bulk = {}) => {
|
|
1912
|
+
if (bulk.repo || bulk.before) throw new UnsupportedOperationError("GitLab marks every to-do done at once; repo and before filters are not supported", context);
|
|
1913
|
+
await fetcher.raw("/todos/mark_as_done", {
|
|
1914
|
+
method: "POST",
|
|
1915
|
+
signal: bulk.signal
|
|
1916
|
+
});
|
|
1917
|
+
}),
|
|
1918
|
+
unreadCount: verb(true, async (options) => {
|
|
1919
|
+
const total = (await fetcher.raw("/todos", {
|
|
1920
|
+
query: {
|
|
1921
|
+
state: "pending",
|
|
1922
|
+
per_page: 1
|
|
1923
|
+
},
|
|
1924
|
+
signal: options?.signal
|
|
1925
|
+
})).headers.get("x-total");
|
|
1926
|
+
if (total === null) throw new UnsupportedOperationError("GitLab omitted X-Total; the to-do count is too large to report", context);
|
|
1927
|
+
return Number(total);
|
|
1928
|
+
})
|
|
1929
|
+
},
|
|
1930
|
+
contents: {
|
|
1931
|
+
getFile: verb(true, async (repo, path, fileOptions = {}) => {
|
|
1932
|
+
const target = `${projectPath(repo)}/repository/files/${encodeURIComponent(path.replace(/^\//, ""))}`;
|
|
1933
|
+
if (fileOptions.metadata === false) {
|
|
1934
|
+
const response = await fetcher.raw(`${target}/raw`, {
|
|
1935
|
+
query: { ref: fileOptions.ref },
|
|
1936
|
+
signal: fileOptions.signal
|
|
1937
|
+
});
|
|
1938
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
1939
|
+
return toFileContent(bytes, {
|
|
1940
|
+
path: path.replace(/^\//, ""),
|
|
1941
|
+
size: bytes.byteLength
|
|
1942
|
+
}, fileOptions, context);
|
|
1943
|
+
}
|
|
1944
|
+
const ref = fileOptions.ref ?? await defaultBranch(repo, fileOptions);
|
|
1945
|
+
const { data } = await fetcher.json(target, {
|
|
1946
|
+
query: { ref },
|
|
1947
|
+
signal: fileOptions.signal
|
|
1948
|
+
});
|
|
1949
|
+
const file = {
|
|
1950
|
+
path: data.file_path,
|
|
1951
|
+
sha: data.blob_id,
|
|
1952
|
+
size: data.size
|
|
1953
|
+
};
|
|
1954
|
+
return toFileContent(fromBase64(data.content ?? ""), file, fileOptions, context);
|
|
1955
|
+
}),
|
|
1956
|
+
treePage: verb(true, (repo, treeOptions = {}) => list(`${projectPath(repo)}/repository/tree`, treeOptions, toTreeEntry, { query: {
|
|
1957
|
+
ref: treeOptions.ref,
|
|
1958
|
+
path: treeOptions.path,
|
|
1959
|
+
recursive: treeOptions.recursive ? "true" : void 0
|
|
1960
|
+
} })),
|
|
1961
|
+
branchesPage: verb(true, (repo, listOptions = {}) => list(`${projectPath(repo)}/repository/branches`, listOptions, toBranch)),
|
|
1962
|
+
tagsPage: verb(true, (repo, listOptions = {}) => list(`${projectPath(repo)}/repository/tags`, listOptions, toTag)),
|
|
1963
|
+
resolveRef: verb(true, async (repo, ref, options) => (await fetcher.json(`${projectPath(repo)}/repository/commits/${encodeURIComponent(ref)}`, { signal: options?.signal })).data.id),
|
|
1964
|
+
compare: verb(true, async (repo, base, head, options) => {
|
|
1965
|
+
const { data } = await fetcher.json(`${projectPath(repo)}/repository/compare`, {
|
|
1966
|
+
query: {
|
|
1967
|
+
from: base,
|
|
1968
|
+
to: head
|
|
1969
|
+
},
|
|
1970
|
+
signal: options?.signal
|
|
1971
|
+
});
|
|
1972
|
+
return {
|
|
1973
|
+
base,
|
|
1974
|
+
head,
|
|
1975
|
+
aheadBy: data.commits?.length,
|
|
1976
|
+
commits: (data.commits ?? []).map((raw) => toCommit(repo, raw)).toReversed(),
|
|
1977
|
+
files: (data.diffs ?? []).map(toChangedFile),
|
|
1978
|
+
raw: data
|
|
1979
|
+
};
|
|
1980
|
+
}),
|
|
1981
|
+
commitFiles: verb(true, commitFiles)
|
|
1982
|
+
},
|
|
1983
|
+
commits: {
|
|
1984
|
+
listPage: verb(true, (repo, query = {}) => list(`${projectPath(repo)}/repository/commits`, query, (raw) => toCommit(repo, raw), { query: {
|
|
1985
|
+
ref_name: query.ref,
|
|
1986
|
+
path: query.path,
|
|
1987
|
+
author: query.author,
|
|
1988
|
+
since: query.since?.toISOString(),
|
|
1989
|
+
until: query.until?.toISOString()
|
|
1990
|
+
} })),
|
|
1991
|
+
get: verb(true, async ({ repo, sha }, options) => {
|
|
1992
|
+
const [commit, diffs] = await Promise.all([fetcher.json(`${projectPath(repo)}/repository/commits/${sha}`, {
|
|
1993
|
+
query: { stats: "true" },
|
|
1994
|
+
signal: options?.signal
|
|
1995
|
+
}), fetcher.json(`${projectPath(repo)}/repository/commits/${sha}/diff`, { signal: options?.signal })]);
|
|
1996
|
+
return toCommit(repo, commit.data, (diffs.data ?? []).map(toChangedFile));
|
|
1997
|
+
}),
|
|
1998
|
+
commentsPage: verb(true, (commit, listOptions = {}) => list(`${projectPath(commit.repo)}/repository/commits/${encodeURIComponent(commit.sha)}/comments`, listOptions, (comment) => toCommitComment(commit, comment))),
|
|
1999
|
+
createComment: verb(true, async (commit, body, options) => {
|
|
2000
|
+
const { data } = await fetcher.json(`${projectPath(commit.repo)}/repository/commits/${encodeURIComponent(commit.sha)}/comments`, {
|
|
2001
|
+
method: "POST",
|
|
2002
|
+
json: { note: body },
|
|
2003
|
+
signal: options?.signal
|
|
2004
|
+
});
|
|
2005
|
+
return toCommitComment(commit, data);
|
|
2006
|
+
})
|
|
2007
|
+
},
|
|
2008
|
+
releases: {
|
|
2009
|
+
listPage: verb(true, releasesPage),
|
|
2010
|
+
get: verb(true, async (ref, options) => toRelease(ref.repo, (await fetcher.json(`${projectPath(ref.repo)}/releases/${encodeURIComponent(ref.tag ?? ref.id)}`, { signal: options?.signal })).data)),
|
|
2011
|
+
getByTag: verb(true, async (repo, tag, options) => toRelease(repo, (await fetcher.json(`${projectPath(repo)}/releases/${encodeURIComponent(tag)}`, { signal: options?.signal })).data)),
|
|
2012
|
+
latest: verb(true, async (repo, options) => {
|
|
2013
|
+
const [newest] = (await releasesPage(repo, {
|
|
2014
|
+
perPage: 1,
|
|
2015
|
+
signal: options?.signal
|
|
2016
|
+
})).items;
|
|
2017
|
+
if (!newest || newest.publishedAt) return newest;
|
|
2018
|
+
return (await releasesPage(repo, {
|
|
2019
|
+
perPage: 20,
|
|
2020
|
+
signal: options?.signal
|
|
2021
|
+
})).items.find((release) => release.publishedAt);
|
|
2022
|
+
}),
|
|
2023
|
+
create: verb(true, async (repo, input, options) => {
|
|
2024
|
+
requirePublishedRelease(input);
|
|
2025
|
+
const { data } = await fetcher.json(`${projectPath(repo)}/releases`, {
|
|
2026
|
+
method: "POST",
|
|
2027
|
+
json: {
|
|
2028
|
+
tag_name: input.tag,
|
|
2029
|
+
ref: input.target,
|
|
2030
|
+
name: input.name,
|
|
2031
|
+
description: input.body
|
|
2032
|
+
},
|
|
2033
|
+
signal: options?.signal
|
|
2034
|
+
});
|
|
2035
|
+
return toRelease(repo, data);
|
|
2036
|
+
}),
|
|
2037
|
+
update: verb(true, async (ref, update, options) => {
|
|
2038
|
+
requirePublishedRelease(update);
|
|
2039
|
+
const tag = ref.tag ?? ref.id;
|
|
2040
|
+
if (update.tag !== void 0 && update.tag !== tag) throw new UnsupportedOperationError("GitLab keys a release by its tag, so the tag cannot change", context);
|
|
2041
|
+
if (update.target !== void 0) throw new UnsupportedOperationError("GitLab cannot change the commit a release points to", context);
|
|
2042
|
+
const { data } = await fetcher.json(`${projectPath(ref.repo)}/releases/${encodeURIComponent(tag)}`, {
|
|
2043
|
+
method: "PUT",
|
|
2044
|
+
json: {
|
|
2045
|
+
name: update.name,
|
|
2046
|
+
description: update.body
|
|
2047
|
+
},
|
|
2048
|
+
signal: options?.signal
|
|
2049
|
+
});
|
|
2050
|
+
return toRelease(ref.repo, data);
|
|
2051
|
+
})
|
|
2052
|
+
},
|
|
2053
|
+
search: {
|
|
2054
|
+
threadsPage: verb(true, searchThreadsPage),
|
|
2055
|
+
reposPage: verb(true, searchReposPage),
|
|
2056
|
+
commitsPage: verb(!anonymous && "experimental", searchCommitsPage),
|
|
2057
|
+
codePage: verb(!anonymous, searchCodePage)
|
|
2058
|
+
},
|
|
2059
|
+
checks: {
|
|
2060
|
+
list: verb(!anonymous, async (repo, sha, options) => ({ items: await Array.fromAsync(fetcher.items(`${projectPath(repo)}/repository/commits/${sha}/statuses`, {
|
|
2061
|
+
query: { per_page: 100 },
|
|
2062
|
+
signal: options?.signal
|
|
2063
|
+
}), (raw) => toStatusCheck(repo, raw)) })),
|
|
2064
|
+
report: verb(true, async (repo, sha, input, options) => toStatusCheck(repo, (await fetcher.json(`${projectPath(repo)}/statuses/${sha}`, {
|
|
2065
|
+
method: "POST",
|
|
2066
|
+
json: {
|
|
2067
|
+
state: STATUS_STATES[input.state],
|
|
2068
|
+
name: input.name,
|
|
2069
|
+
description: input.description,
|
|
2070
|
+
target_url: input.url
|
|
2071
|
+
},
|
|
2072
|
+
signal: options?.signal
|
|
2073
|
+
})).data)),
|
|
2074
|
+
rerun: verb(true, async (ref, options) => {
|
|
2075
|
+
if (ref.type !== "job" && ref.type !== "status") throw new UnsupportedOperationError(`GitLab cannot re-run a ${ref.type}`, context);
|
|
2076
|
+
await fetcher.raw(`${projectPath(ref.repo)}/jobs/${ref.id}/retry`, {
|
|
2077
|
+
method: "POST",
|
|
2078
|
+
signal: options?.signal
|
|
2079
|
+
});
|
|
2080
|
+
})
|
|
2081
|
+
},
|
|
2082
|
+
ci: {
|
|
2083
|
+
runsPage: verb(true, (repo, query = {}) => list(`${projectPath(repo)}/pipelines`, query, (raw) => toPipeline(repo, raw), { query: {
|
|
2084
|
+
ref: query.branch,
|
|
2085
|
+
status: PIPELINE_STATES[query.state ?? "unknown"]
|
|
2086
|
+
} })),
|
|
2087
|
+
getRun: verb(true, async (ref, options) => toPipeline(ref.repo, (await fetcher.json(`${projectPath(ref.repo)}/pipelines/${ref.id}`, { signal: options?.signal })).data)),
|
|
2088
|
+
jobsPage: verb(true, (ref, listOptions = {}) => list(`${projectPath(ref.repo)}/pipelines/${ref.id}/jobs`, listOptions, (raw) => toCiJob(ref, raw))),
|
|
2089
|
+
getJob: verb(!anonymous, async (ref, options) => {
|
|
2090
|
+
const { data } = await fetcher.json(`${projectPath(ref.repo)}/jobs/${encodeURIComponent(ref.id)}`, { signal: options?.signal });
|
|
2091
|
+
const run = ref.run ?? (data.pipeline && {
|
|
2092
|
+
forge: "gitlab",
|
|
2093
|
+
instance,
|
|
2094
|
+
repo: ref.repo,
|
|
2095
|
+
id: String(data.pipeline.id)
|
|
2096
|
+
});
|
|
2097
|
+
if (!run) throw new UnsupportedOperationError(`GitLab returned job ${ref.id} without its pipeline, and the ref names no run`, context);
|
|
2098
|
+
return toCiJob(run, data);
|
|
2099
|
+
}),
|
|
2100
|
+
log: verb(!anonymous, async (ref, options) => (await fetcher.stream(`${projectPath(ref.repo)}/jobs/${encodeURIComponent(ref.id)}/trace`, { signal: options?.signal })).body),
|
|
2101
|
+
rerunFailed: verb(true, async (ref, options) => {
|
|
2102
|
+
await fetcher.raw(`${projectPath(ref.repo)}/pipelines/${encodeURIComponent(ref.id)}/retry`, {
|
|
2103
|
+
method: "POST",
|
|
2104
|
+
signal: options?.signal
|
|
2105
|
+
});
|
|
2106
|
+
})
|
|
2107
|
+
},
|
|
2108
|
+
securityAlerts: {
|
|
2109
|
+
kinds: {
|
|
2110
|
+
dependency: !anonymous,
|
|
2111
|
+
code_scanning: !anonymous,
|
|
2112
|
+
secret: !anonymous
|
|
2113
|
+
},
|
|
2114
|
+
listPage: vulnerabilitiesPage
|
|
2115
|
+
},
|
|
2116
|
+
emulated: { getCommitComment: anonymous ? "unverified" : "emulated" },
|
|
2117
|
+
threads: {
|
|
2118
|
+
filesPage: verb(true, (thread, listOptions = {}) => list(`${threadPath(requireMerge(thread, "read for changed files"))}/diffs`, listOptions, toChangedFile)),
|
|
2119
|
+
commitsPage: verb(true, (thread, listOptions = {}) => list(`${threadPath(requireMerge(thread, "read for commits"))}/commits`, listOptions, (raw) => toCommit(thread.repo, raw))),
|
|
2120
|
+
reviewsPage: verb("emulated", async (thread, listOptions) => {
|
|
2121
|
+
const ref = requireThread(thread, context);
|
|
2122
|
+
if (ref.kind !== "pull_request") throw new UnsupportedOperationError("Only merge requests have approvals", context);
|
|
2123
|
+
const { data, response } = await fetcher.json(`${threadPath(ref)}/approvals`, { signal: listOptions?.signal });
|
|
2124
|
+
return {
|
|
2125
|
+
items: toApprovalReviews(ref, data),
|
|
2126
|
+
...rateLimitPart(response)
|
|
2127
|
+
};
|
|
2128
|
+
}),
|
|
2129
|
+
approve: verb(true, approve),
|
|
2130
|
+
createReview: verb("emulated", async (thread, input, options) => {
|
|
2131
|
+
if (input.comments?.length) throw new UnsupportedOperationError("GitLab reviews carry no inline comments yet", context);
|
|
2132
|
+
const ref = requireThread(thread, context);
|
|
2133
|
+
if (input.event === "comment" && input.body) {
|
|
2134
|
+
const { data } = await fetcher.json(`${threadPath(ref)}/discussions`, {
|
|
2135
|
+
method: "POST",
|
|
2136
|
+
json: { body: input.body },
|
|
2137
|
+
signal: options?.signal
|
|
2138
|
+
});
|
|
2139
|
+
const note = data.notes[0];
|
|
2140
|
+
return {
|
|
2141
|
+
...syntheticReview(ref, `discussion:${data.id}`, "commented", {
|
|
2142
|
+
author: toActor(instance, note.author),
|
|
2143
|
+
stateRaw: "discussion",
|
|
2144
|
+
submittedAt: toDate(note.created_at),
|
|
2145
|
+
raw: data
|
|
2146
|
+
}),
|
|
2147
|
+
body: note.body,
|
|
2148
|
+
comments: [{
|
|
2149
|
+
...toNoteComment(ref, note, data),
|
|
2150
|
+
raw: note
|
|
2151
|
+
}]
|
|
2152
|
+
};
|
|
2153
|
+
}
|
|
2154
|
+
if (input.event !== "approve") throw new UnsupportedOperationError("GitLab has approvals and discussions, not reviews; use `threads.approve()`, or `threads.createComment()` with a body", context);
|
|
2155
|
+
return approve(ref, input.body, options);
|
|
2156
|
+
}),
|
|
2157
|
+
replyToReviewComment: verb(true, async (thread, comment, body, options) => {
|
|
2158
|
+
const ref = requireMerge(thread, "reviewed");
|
|
2159
|
+
if (comment.thread === void 0) throw new UnsupportedOperationError("GitLab replies inside a discussion; pass a comment with its `thread` from `comments()`", context);
|
|
2160
|
+
const { data } = await fetcher.json(`${threadPath(ref)}/discussions/${encodeURIComponent(comment.thread.id)}/notes`, {
|
|
2161
|
+
method: "POST",
|
|
2162
|
+
json: { body },
|
|
2163
|
+
signal: options?.signal
|
|
2164
|
+
});
|
|
2165
|
+
return {
|
|
2166
|
+
...toNoteComment(ref, data),
|
|
2167
|
+
thread: {
|
|
2168
|
+
id: comment.thread.id,
|
|
2169
|
+
resolved: Boolean(data.resolved)
|
|
2170
|
+
}
|
|
2171
|
+
};
|
|
2172
|
+
}),
|
|
2173
|
+
reviewThreads: verb(true, {
|
|
2174
|
+
resolveReviewThread: (thread, id, options) => setDiscussionResolved(thread, id, true, options),
|
|
2175
|
+
unresolveReviewThread: (thread, id, options) => setDiscussionResolved(thread, id, false, options)
|
|
2176
|
+
}),
|
|
2177
|
+
checks: perKind({ pull_request: true }, async (thread, options) => {
|
|
2178
|
+
const ref = requireThread(thread, context);
|
|
2179
|
+
const { data } = await fetcher.json(threadPath(ref), { signal: options?.signal });
|
|
2180
|
+
if (!data.head_pipeline) return { items: [] };
|
|
2181
|
+
const pipelineProject = data.head_pipeline.project_id;
|
|
2182
|
+
const own = pipelineProject === void 0 || pipelineProject === data.target_project_id;
|
|
2183
|
+
const project = own ? projectPath(ref.repo) : `/projects/${pipelineProject}`;
|
|
2184
|
+
const repo = own ? ref.repo : repoRefFromWebUrl(instance, data.head_pipeline.web_url, pipelineProject);
|
|
2185
|
+
const run = repo && {
|
|
2186
|
+
forge: "gitlab",
|
|
2187
|
+
instance,
|
|
2188
|
+
repo,
|
|
2189
|
+
id: String(data.head_pipeline.id)
|
|
2190
|
+
};
|
|
2191
|
+
return { items: await Array.fromAsync(fetcher.items(`${project}/pipelines/${data.head_pipeline.id}/jobs`, {
|
|
2192
|
+
query: { per_page: 100 },
|
|
2193
|
+
signal: options?.signal
|
|
2194
|
+
}), (job) => toJobCheck(repo ?? ref.repo, job, run)) };
|
|
2195
|
+
}),
|
|
2196
|
+
get: perKind({
|
|
2197
|
+
issue: true,
|
|
2198
|
+
pull_request: true
|
|
2199
|
+
}, get),
|
|
2200
|
+
getMany: verb(true, (refs, options) => getManyConcurrently(refs, get, options)),
|
|
2201
|
+
closingIssuesPage: verb(true, async (thread, listOptions = {}) => {
|
|
2202
|
+
const ref = requireThread(thread, context);
|
|
2203
|
+
if (ref.kind !== "pull_request") throw new UnsupportedOperationError("Only merge requests close issues", context);
|
|
2204
|
+
return list(`${threadPath(ref)}/closes_issues`, listOptions, (raw) => referencedThread(raw, "issue"));
|
|
2205
|
+
}),
|
|
2206
|
+
closingPullRequestsPage: verb(true, async (thread, listOptions = {}) => {
|
|
2207
|
+
const ref = requireThread(thread, context);
|
|
2208
|
+
if (ref.kind !== "issue") throw new UnsupportedOperationError("Only issues are closed by merge requests", context);
|
|
2209
|
+
return list(`${threadPath(ref)}/closed_by`, listOptions, (raw) => referencedThread(raw, "pull_request"));
|
|
2210
|
+
}),
|
|
2211
|
+
listPage: perKind(ISSUE_LIKE, listPage),
|
|
2212
|
+
eventsPage: verb(!anonymous, async (thread, listOptions = {}) => {
|
|
2213
|
+
const ref = requireThread(thread, context);
|
|
2214
|
+
return list(`${threadPath(ref)}/notes`, listOptions, (note) => toNoteEvent(ref, note), { query: {
|
|
2215
|
+
sort: "asc",
|
|
2216
|
+
order_by: "created_at"
|
|
2217
|
+
} });
|
|
2218
|
+
}),
|
|
2219
|
+
commentsPage: perKind({
|
|
2220
|
+
issue: !anonymous,
|
|
2221
|
+
pull_request: !anonymous
|
|
2222
|
+
}, async (thread, listOptions = {}) => {
|
|
2223
|
+
const ref = requireThread(thread, context);
|
|
2224
|
+
const page = await list(`${threadPath(requireIssueOrPull(ref, context, "list comments on"))}/discussions`, listOptions, (discussion) => discussion);
|
|
2225
|
+
return {
|
|
2226
|
+
...page,
|
|
2227
|
+
items: page.items.flatMap((discussion) => discussion.notes.filter((note) => !note.system).map((note) => toNoteComment(ref, note, discussion)))
|
|
2228
|
+
};
|
|
2229
|
+
}),
|
|
2230
|
+
getComment: perKind({
|
|
2231
|
+
issue: !anonymous,
|
|
2232
|
+
pull_request: !anonymous
|
|
2233
|
+
}, async (ref, options) => {
|
|
2234
|
+
const thread = requireIssueOrPull(ref.thread, context, "read comments on");
|
|
2235
|
+
const { data } = await fetcher.json(`${threadPath(thread)}/notes/${ref.id}`, { signal: options?.signal });
|
|
2236
|
+
if (data.system) throw new NotFoundError(`Comment ${ref.id} not found`, 404, "", context);
|
|
2237
|
+
if (!data.resolvable) return toNoteComment(thread, data);
|
|
2238
|
+
for await (const discussion of fetcher.items(`${threadPath(thread)}/discussions`, {
|
|
2239
|
+
query: { per_page: 100 },
|
|
2240
|
+
signal: options?.signal
|
|
2241
|
+
})) {
|
|
2242
|
+
const note = discussion.notes.find((candidate) => String(candidate.id) === ref.id);
|
|
2243
|
+
if (note) return toNoteComment(thread, note, discussion);
|
|
2244
|
+
}
|
|
2245
|
+
return toNoteComment(thread, data);
|
|
2246
|
+
}),
|
|
2247
|
+
createComment: perKind({
|
|
2248
|
+
issue: true,
|
|
2249
|
+
pull_request: true
|
|
2250
|
+
}, async (thread, body, options) => {
|
|
2251
|
+
const ref = requireThread(thread, context);
|
|
2252
|
+
const { data } = await fetcher.json(`${threadPath(requireIssueOrPull(ref, context, "comment on"))}/notes`, {
|
|
2253
|
+
method: "POST",
|
|
2254
|
+
json: { body },
|
|
2255
|
+
signal: options?.signal
|
|
2256
|
+
});
|
|
2257
|
+
return toNoteComment(ref, data);
|
|
2258
|
+
}),
|
|
2259
|
+
updateComment: perKind({
|
|
2260
|
+
issue: true,
|
|
2261
|
+
pull_request: true
|
|
2262
|
+
}, async (ref, body, options) => {
|
|
2263
|
+
const thread = requireIssueOrPull(ref.thread, context, "edit comments on");
|
|
2264
|
+
const { data } = await fetcher.json(`${threadPath(thread)}/notes/${ref.id}`, {
|
|
2265
|
+
method: "PUT",
|
|
2266
|
+
json: { body },
|
|
2267
|
+
signal: options?.signal
|
|
2268
|
+
});
|
|
2269
|
+
return toNoteComment(thread, data);
|
|
2270
|
+
}),
|
|
2271
|
+
deleteComment: perKind({
|
|
2272
|
+
issue: true,
|
|
2273
|
+
pull_request: true
|
|
2274
|
+
}, async (ref, options) => {
|
|
2275
|
+
const thread = requireIssueOrPull(ref.thread, context, "delete comments on");
|
|
2276
|
+
await fetcher.raw(`${threadPath(thread)}/notes/${ref.id}`, {
|
|
2277
|
+
method: "DELETE",
|
|
2278
|
+
signal: options?.signal
|
|
2279
|
+
});
|
|
2280
|
+
}),
|
|
2281
|
+
create: perKind({
|
|
2282
|
+
issue: true,
|
|
2283
|
+
pull_request: true
|
|
2284
|
+
}, async (repo, input, options) => {
|
|
2285
|
+
if (input.kind === "discussion") throw new UnsupportedOperationError("GitLab has no discussion threads", context);
|
|
2286
|
+
const assignee_ids = input.assignees?.length ? await Promise.all(input.assignees.map(userId)) : void 0;
|
|
2287
|
+
const labels = input.labels?.join(",");
|
|
2288
|
+
if (input.kind === "issue") {
|
|
2289
|
+
const { data } = await fetcher.json(`${projectPath(repo)}/issues`, {
|
|
2290
|
+
method: "POST",
|
|
2291
|
+
json: {
|
|
2292
|
+
title: input.title,
|
|
2293
|
+
description: input.body,
|
|
2294
|
+
labels,
|
|
2295
|
+
assignee_ids
|
|
2296
|
+
},
|
|
2297
|
+
signal: options?.signal
|
|
2298
|
+
});
|
|
2299
|
+
return toThread({
|
|
2300
|
+
forge: FORGE,
|
|
2301
|
+
instance,
|
|
2302
|
+
repo,
|
|
2303
|
+
kind: "issue",
|
|
2304
|
+
number: String(data.iid)
|
|
2305
|
+
}, data);
|
|
2306
|
+
}
|
|
2307
|
+
if (!input.head || !input.base) throw new UnsupportedOperationError("Creating a merge request needs head and base branches", context);
|
|
2308
|
+
const { data } = await fetcher.json(`${projectPath(repo)}/merge_requests`, {
|
|
2309
|
+
method: "POST",
|
|
2310
|
+
json: {
|
|
2311
|
+
title: input.draft ? `Draft: ${input.title}` : input.title,
|
|
2312
|
+
description: input.body,
|
|
2313
|
+
source_branch: input.head,
|
|
2314
|
+
target_branch: input.base,
|
|
2315
|
+
labels,
|
|
2316
|
+
assignee_ids
|
|
2317
|
+
},
|
|
2318
|
+
signal: options?.signal
|
|
2319
|
+
});
|
|
2320
|
+
return toThread({
|
|
2321
|
+
forge: FORGE,
|
|
2322
|
+
instance,
|
|
2323
|
+
repo,
|
|
2324
|
+
kind: "pull_request",
|
|
2325
|
+
number: String(data.iid)
|
|
2326
|
+
}, data);
|
|
2327
|
+
}),
|
|
2328
|
+
update: perKind({
|
|
2329
|
+
issue: true,
|
|
2330
|
+
pull_request: true
|
|
2331
|
+
}, async (thread, input, options) => {
|
|
2332
|
+
const ref = requireIssueOrPull(thread, context, "update");
|
|
2333
|
+
const { data } = await fetcher.json(threadPath(ref), {
|
|
2334
|
+
method: "PUT",
|
|
2335
|
+
json: {
|
|
2336
|
+
title: input.title,
|
|
2337
|
+
description: input.body,
|
|
2338
|
+
state_event: input.state && STATE_EVENTS[input.state],
|
|
2339
|
+
labels: input.labels?.join(","),
|
|
2340
|
+
assignee_ids: input.assignees && await Promise.all(input.assignees.map(userId))
|
|
2341
|
+
},
|
|
2342
|
+
signal: options?.signal
|
|
2343
|
+
});
|
|
2344
|
+
return toThread(ref, data);
|
|
2345
|
+
}),
|
|
2346
|
+
addLabels: perKind({
|
|
2347
|
+
issue: true,
|
|
2348
|
+
pull_request: true
|
|
2349
|
+
}, async (thread, labels, options) => {
|
|
2350
|
+
const ref = requireIssueOrPull(thread, context, "label");
|
|
2351
|
+
return toThread(ref, (await fetcher.json(threadPath(ref), {
|
|
2352
|
+
method: "PUT",
|
|
2353
|
+
json: { add_labels: labels.join(",") },
|
|
2354
|
+
signal: options?.signal
|
|
2355
|
+
})).data).labels;
|
|
2356
|
+
}),
|
|
2357
|
+
removeLabels: perKind({
|
|
2358
|
+
issue: true,
|
|
2359
|
+
pull_request: true
|
|
2360
|
+
}, async (thread, labels, options) => {
|
|
2361
|
+
const ref = requireIssueOrPull(thread, context, "label");
|
|
2362
|
+
return toThread(ref, (await fetcher.json(threadPath(ref), {
|
|
2363
|
+
method: "PUT",
|
|
2364
|
+
json: { remove_labels: labels.join(",") },
|
|
2365
|
+
signal: options?.signal
|
|
2366
|
+
})).data).labels;
|
|
2367
|
+
}),
|
|
2368
|
+
setMilestone: perKind({
|
|
2369
|
+
issue: true,
|
|
2370
|
+
pull_request: true
|
|
2371
|
+
}, async (thread, milestone, options) => {
|
|
2372
|
+
const ref = requireIssueOrPull(thread, context, "set the milestone of");
|
|
2373
|
+
const { data } = await fetcher.json(threadPath(ref), {
|
|
2374
|
+
method: "PUT",
|
|
2375
|
+
json: { milestone_id: milestone === void 0 ? 0 : await milestoneId(milestone, (page) => milestonesPage(ref.repo, page, true), context, options) },
|
|
2376
|
+
signal: options?.signal
|
|
2377
|
+
});
|
|
2378
|
+
return toMilestone(data.milestone);
|
|
2379
|
+
}),
|
|
2380
|
+
reactionsPage: perKind(ISSUE_LIKE, async (target, listOptions = {}) => {
|
|
2381
|
+
const result = await fetcher.page(`${awardPath(target)}/award_emoji`, {
|
|
2382
|
+
query: { per_page: listOptions.perPage },
|
|
2383
|
+
cursor: listOptions.cursor,
|
|
2384
|
+
signal: listOptions.signal
|
|
2385
|
+
});
|
|
2386
|
+
return toPage(result, (raw) => {
|
|
2387
|
+
const reactor = toActor(instance, raw.user);
|
|
2388
|
+
return reactor && {
|
|
2389
|
+
content: reactionContent(REACTION_NAMES[raw.name] ?? raw.name),
|
|
2390
|
+
contentRaw: raw.name,
|
|
2391
|
+
actor: reactor,
|
|
2392
|
+
createdAt: toDate(raw.created_at),
|
|
2393
|
+
raw
|
|
2394
|
+
};
|
|
2395
|
+
});
|
|
2396
|
+
}),
|
|
2397
|
+
reactions: perKind({
|
|
2398
|
+
issue: true,
|
|
2399
|
+
pull_request: true
|
|
2400
|
+
}, {
|
|
2401
|
+
async react(target, reaction, options) {
|
|
2402
|
+
try {
|
|
2403
|
+
await fetcher.raw(`${awardPath(target)}/award_emoji`, {
|
|
2404
|
+
method: "POST",
|
|
2405
|
+
json: { name: AWARD_EMOJI[reaction] },
|
|
2406
|
+
signal: options?.signal
|
|
2407
|
+
});
|
|
2408
|
+
} catch (error) {
|
|
2409
|
+
if (!(error instanceof ForgeApiError && error.body.includes("has already been taken"))) throw error;
|
|
2410
|
+
}
|
|
2411
|
+
},
|
|
2412
|
+
async unreact(target, reaction, options) {
|
|
2413
|
+
const path = `${awardPath(target)}/award_emoji`;
|
|
2414
|
+
const { data } = await fetcher.json(path, {
|
|
2415
|
+
query: { per_page: 100 },
|
|
2416
|
+
signal: options?.signal
|
|
2417
|
+
});
|
|
2418
|
+
const login = await viewerLogin();
|
|
2419
|
+
const mine = data.find((award) => award.name === AWARD_EMOJI[reaction] && award.user?.username === login);
|
|
2420
|
+
if (mine) await fetcher.raw(`${path}/${mine.id}`, {
|
|
2421
|
+
method: "DELETE",
|
|
2422
|
+
signal: options?.signal
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
}),
|
|
2426
|
+
transfer: verb(true, async (thread, repo, options) => {
|
|
2427
|
+
const ref = requireIssueOrPull(thread, context, "transfer");
|
|
2428
|
+
if (ref.kind !== "issue") throw new UnsupportedOperationError("GitLab moves issues only", context);
|
|
2429
|
+
const { data: target } = await fetcher.json(`/projects/${projectId(repo)}`, { signal: options?.signal });
|
|
2430
|
+
const { data } = await fetcher.json(`${threadPath(ref)}/move`, {
|
|
2431
|
+
method: "POST",
|
|
2432
|
+
json: { to_project_id: target.id },
|
|
2433
|
+
signal: options?.signal
|
|
2434
|
+
});
|
|
2435
|
+
return {
|
|
2436
|
+
forge: FORGE,
|
|
2437
|
+
instance,
|
|
2438
|
+
repo,
|
|
2439
|
+
kind: "issue",
|
|
2440
|
+
number: String(data.iid),
|
|
2441
|
+
externalId: data.id === void 0 ? void 0 : String(data.id)
|
|
2442
|
+
};
|
|
2443
|
+
}),
|
|
2444
|
+
markDuplicate: verb("emulated", async (thread, canonical, options) => {
|
|
2445
|
+
const ref = requireIssueOrPull(thread, context, "mark duplicate");
|
|
2446
|
+
const reference = canonical.repo.owner === ref.repo.owner && canonical.repo.name === ref.repo.name ? `#${canonical.number}` : `${canonical.repo.owner}/${canonical.repo.name}#${canonical.number}`;
|
|
2447
|
+
await fetcher.raw(`${threadPath(ref)}/notes`, {
|
|
2448
|
+
method: "POST",
|
|
2449
|
+
json: { body: `/duplicate ${reference}` },
|
|
2450
|
+
signal: options?.signal
|
|
2451
|
+
});
|
|
2452
|
+
}),
|
|
2453
|
+
setLabels: perKind({
|
|
2454
|
+
issue: true,
|
|
2455
|
+
pull_request: true
|
|
2456
|
+
}, async (thread, labels, options) => {
|
|
2457
|
+
const ref = requireIssueOrPull(thread, context, "label");
|
|
2458
|
+
return toThread(ref, (await fetcher.json(threadPath(ref), {
|
|
2459
|
+
method: "PUT",
|
|
2460
|
+
json: { labels: labels.join(",") },
|
|
2461
|
+
signal: options?.signal
|
|
2462
|
+
})).data).labels;
|
|
2463
|
+
}),
|
|
2464
|
+
setAssignees: perKind({
|
|
2465
|
+
issue: true,
|
|
2466
|
+
pull_request: true
|
|
2467
|
+
}, async (thread, assignees, options) => {
|
|
2468
|
+
const ref = requireIssueOrPull(thread, context, "assign");
|
|
2469
|
+
const { data } = await fetcher.json(threadPath(ref), {
|
|
2470
|
+
method: "PUT",
|
|
2471
|
+
json: { assignee_ids: await Promise.all(assignees.map(userId)) },
|
|
2472
|
+
signal: options?.signal
|
|
2473
|
+
});
|
|
2474
|
+
return (data.assignees ?? []).flatMap((user) => toActor(instance, user) ?? []);
|
|
2475
|
+
}),
|
|
2476
|
+
requestReview: perKind({ pull_request: true }, async (thread, reviewers, options) => {
|
|
2477
|
+
const ref = requireThread(thread, context);
|
|
2478
|
+
if (ref.kind !== "pull_request") throw new UnsupportedOperationError("Only merge requests have reviewers", context);
|
|
2479
|
+
const { data } = await fetcher.json(threadPath(ref), { signal: options?.signal });
|
|
2480
|
+
const ids = /* @__PURE__ */ new Set([...(data.reviewers ?? []).map((user) => user.id), ...await Promise.all(reviewers.map(userId))]);
|
|
2481
|
+
await fetcher.raw(threadPath(ref), {
|
|
2482
|
+
method: "PUT",
|
|
2483
|
+
json: { reviewer_ids: [...ids] },
|
|
2484
|
+
signal: options?.signal
|
|
2485
|
+
});
|
|
2486
|
+
}),
|
|
2487
|
+
close: perKind({
|
|
2488
|
+
issue: true,
|
|
2489
|
+
pull_request: true
|
|
2490
|
+
}, (ref, options) => setState(ref, "close", options)),
|
|
2491
|
+
reopen: perKind({
|
|
2492
|
+
issue: true,
|
|
2493
|
+
pull_request: true
|
|
2494
|
+
}, (ref, options) => setState(ref, "reopen", options)),
|
|
2495
|
+
locking: perKind({
|
|
2496
|
+
issue: true,
|
|
2497
|
+
pull_request: true
|
|
2498
|
+
}, {
|
|
2499
|
+
lock: (thread, options) => setLocked(thread, true, options),
|
|
2500
|
+
unlock: (thread, options) => setLocked(thread, false, options)
|
|
2501
|
+
}),
|
|
2502
|
+
merge: verb(true, merge),
|
|
2503
|
+
updateBranch: verb(true, updateBranch),
|
|
2504
|
+
subscriptions: perKind(ISSUE_LIKE, {
|
|
2505
|
+
subscription: async (thread, options) => {
|
|
2506
|
+
const ref = requireIssueOrPull(thread, context, "read the subscription of");
|
|
2507
|
+
return (await fetcher.json(threadPath(ref), { signal: options?.signal })).data.subscribed ? "subscribed" : "none";
|
|
2508
|
+
},
|
|
2509
|
+
subscribe: (thread, options) => setSubscribed(thread, true, options),
|
|
2510
|
+
unsubscribe: (thread, options) => setSubscribed(thread, false, options)
|
|
2511
|
+
})
|
|
2512
|
+
}
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2515
|
+
});
|
|
2516
|
+
/** GitLab tokens carry coarse scopes; `api` covers writes and `read_api` reads. */
|
|
2517
|
+
function gitlabScopesFor(verb) {
|
|
2518
|
+
const [group = "", name = ""] = verb.split(".");
|
|
2519
|
+
if (group === "webhooks") return name === "verify" || name === "ingest" ? {} : {
|
|
2520
|
+
token: ["api"],
|
|
2521
|
+
note: "Maintainer on the project, or Owner on the group"
|
|
2522
|
+
};
|
|
2523
|
+
if (group === "orgs") return {
|
|
2524
|
+
token: ["read_api"],
|
|
2525
|
+
note: "A member of the group, for a private group"
|
|
2526
|
+
};
|
|
2527
|
+
return { token: [WRITE_VERBS.has(verb) ? "api" : "read_api"] };
|
|
2528
|
+
}
|
|
2529
|
+
//#endregion
|
|
2530
|
+
export { toRepoRef as a, gitlab, toLabel as i, approvalId as n, toState as o, toActor as r, toThreadKind as s, FORGE as t };
|