@vite-hub/workspace 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +164 -107
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/blob-database.d.ts +70 -117
  4. package/dist/blob-database.js +48 -41
  5. package/dist/checkout.d.ts +128 -0
  6. package/dist/checkout.js +849 -0
  7. package/dist/cloudflare.d.ts +2 -2
  8. package/dist/cloudflare.js +1 -1
  9. package/dist/config-B-863EgC.js +15 -0
  10. package/dist/{config-B7dmzDX3.js → config-BAgL2dtB.js} +48 -84
  11. package/dist/{config-DLKdaFWN.d.ts → config-BQKcPawI.d.ts} +1 -1
  12. package/dist/discard-CNNtCozM.js +8 -0
  13. package/dist/durability.d.ts +22 -0
  14. package/dist/durability.js +70 -0
  15. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  16. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  17. package/dist/file-2pFYNtsU.js +22 -0
  18. package/dist/{files-C7Px8uaC.js → files-BOo4SbwE.js} +2 -2
  19. package/dist/files.d.ts +38 -0
  20. package/dist/files.js +6 -0
  21. package/dist/{github-CPxHtFB7.js → github-CrYp4v8k.js} +32 -5
  22. package/dist/{glob--XcLlcml.js → glob-B8YGvTrZ.js} +4 -5
  23. package/dist/{glob--kNYDbfU.js → glob-Cjxms1t7.js} +1 -1
  24. package/dist/{host-CFnrTXTK.js → host-BFBpXn0N.js} +58 -47
  25. package/dist/{hosted-acMA5XyL.js → hosted-KcUR_jPv.js} +216 -93
  26. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  27. package/dist/hosted-vercel-blob.d.ts +2 -2
  28. package/dist/hosted-vercel-blob.js +1 -1
  29. package/dist/hosted.d.ts +5 -3
  30. package/dist/hosted.js +2 -2
  31. package/dist/index.d.ts +9 -51
  32. package/dist/index.js +21 -91
  33. package/dist/{lifecycle-BwZ7c9hb.js → lifecycle-B-enk_4A.js} +8 -8
  34. package/dist/lineage.d.ts +26 -0
  35. package/dist/lineage.js +76 -0
  36. package/dist/loader.d.ts +1 -1
  37. package/dist/loader.js +2 -2
  38. package/dist/{mcp-resources-BREFCmtn.js → mcp-resources-DF0F5rcL.js} +2 -2
  39. package/dist/{memory-BbwOqDXl.js → memory-BOexthyW.js} +3 -4
  40. package/dist/{metadata-target-DZEZQGHA.js → metadata-target-CWz6KHKq.js} +17 -16
  41. package/dist/object-Da1zyPCR.js +11 -0
  42. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  43. package/dist/operations-C6FpR8Rr.js +389 -0
  44. package/dist/operations-CE2drFih.js +1234 -0
  45. package/dist/operations.d.ts +41 -4
  46. package/dist/operations.js +3 -2
  47. package/dist/{path-CNAwN7pw.js → path--wrT_Azm.js} +2 -3
  48. package/dist/path-AxMho1wo.d.ts +7 -0
  49. package/dist/{plugins-DqQ8b4T5.d.ts → plugins-C8C0auoW.d.ts} +1 -1
  50. package/dist/{provider-kXjfli9u.js → provider-9s4Ufkm5.js} +104 -82
  51. package/dist/providers/github/store.d.ts +1 -1
  52. package/dist/providers/github/store.js +1 -1
  53. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  54. package/dist/{registry-Bp-8UUfG.js → registry-CNphafBx.js} +55 -20
  55. package/dist/registry-CYNN623b.d.ts +9 -0
  56. package/dist/request-scope-Dw5n8bMC.js +83 -0
  57. package/dist/results-DgkZUmTL.js +8 -0
  58. package/dist/{rolldown-runtime-B4iAMlE-.js → rolldown-runtime-rQ84J-ij.js} +2 -3
  59. package/dist/runtime/assets.d.ts +1 -1
  60. package/dist/runtime/assets.js +3 -3
  61. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  62. package/dist/runtime/empty-registry.d.ts +2 -1
  63. package/dist/runtime/registry.d.ts +2 -0
  64. package/dist/runtime/registry.js +23 -0
  65. package/dist/runtime/request.d.ts +4 -0
  66. package/dist/runtime/request.js +8 -0
  67. package/dist/runtime/state.d.ts +5 -4
  68. package/dist/runtime/state.js +8 -18
  69. package/dist/runtime/workspace.d.ts +1 -1
  70. package/dist/runtime/workspace.js +1 -1
  71. package/dist/runtime.d.ts +9 -8
  72. package/dist/runtime.js +23 -26
  73. package/dist/{search-CrTmXj5h.js → search-C_RfoM2j.js} +2 -2
  74. package/dist/{server-BNQ-Nbjj.js → server-8tGltlGz.js} +53 -40
  75. package/dist/server.d.ts +17 -8
  76. package/dist/server.js +1 -1
  77. package/dist/shared-B3_EUk89.js +848 -0
  78. package/dist/source-metadata.d.ts +6 -2
  79. package/dist/source-metadata.js +8 -8
  80. package/dist/state-BISnUf1s.d.ts +35 -0
  81. package/dist/{ai-BZyLwULx.js → state-DbrW-njQ.js} +96 -54
  82. package/dist/{store-CXgmu-uw.js → store-ybhyD38Z.js} +250 -106
  83. package/dist/{sync-CN6ec-5M.js → sync-CCD_VYC8.js} +4 -4
  84. package/dist/target-jWhTdIuF.js +89 -0
  85. package/dist/test.d.ts +1 -1
  86. package/dist/test.js +1 -1
  87. package/dist/{types-DeK9GIxy.d.ts → types-BbtwmBZ5.d.ts} +68 -14
  88. package/dist/use-C6lV3-wC.d.ts +321 -0
  89. package/dist/{use-BQj7nSz6.js → use-CSpT5W87.js} +75 -82
  90. package/dist/{utils-Blrh4N2n.js → utils-CgMZCHsX.js} +112 -41
  91. package/dist/vite.d.ts +585 -2
  92. package/dist/vite.js +21368 -1
  93. package/dist/{workspace-BWJQBK1u.d.ts → workspace-CYB2xZ1T.d.ts} +1 -1
  94. package/dist/{workspace-6pxkOuxr.js → workspace-sPWn2Jxj.js} +125 -40
  95. package/package.json +46 -55
  96. package/dist/ai-BW2ZhizI.d.ts +0 -177
  97. package/dist/ai.d.ts +0 -3
  98. package/dist/ai.js +0 -2
  99. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +0 -19
  100. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  101. package/dist/error-diagnostics-DY5GP47p.js +0 -96
  102. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +0 -354
  103. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +0 -214
  104. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +0 -527
  105. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +0 -248
  106. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +0 -179
  107. package/dist/file-C0_aPWSS.js +0 -26
  108. package/dist/file-metadata-CxDy-E2H.js +0 -58
  109. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +0 -2278
  110. package/dist/github-DtncTfmv-Du2S8lGF.js +0 -4159
  111. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +0 -2530
  112. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +0 -489
  113. package/dist/hosted-vercel-blob-DKntsHaf.js +0 -12603
  114. package/dist/inspect-BoObD2cJ.js +0 -167
  115. package/dist/mountx.d.ts +0 -8
  116. package/dist/mountx.js +0 -145
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -27
  120. package/dist/nuxt.js +0 -38
  121. package/dist/operations-BcpWr41m.js +0 -159
  122. package/dist/operations-CGqY1XeG.js +0 -965
  123. package/dist/operations-DnOwKsJT.d.ts +0 -136
  124. package/dist/registry-Cg1TJVVZ.d.ts +0 -10
  125. package/dist/request-execution-Dk9rY-Yh.js +0 -84
  126. package/dist/shared-DalXdP0i.js +0 -2158
  127. package/dist/state-B8zbLi5t.d.ts +0 -26
  128. package/dist/target-D4Bqb1eH.js +0 -11
  129. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +0 -125
  130. package/dist/token-CO62GglH.js +0 -61
  131. package/dist/use-DhwhbAVV.d.ts +0 -108
  132. package/dist/vite-BEvgU2GY.js +0 -20909
  133. package/dist/vite-CcZmMQ7S.d.ts +0 -476
  134. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +0 -1565
@@ -1,354 +0,0 @@
1
- import { It as toDate, U as WebhookVerificationError } from "./shared-DalXdP0i.js";
2
- import { S as threadSnapshot, a as eventAction, d as headerValue, g as refEvent, n as bodyText, s as eventTime } from "./webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js";
3
- import { a as toRepoRef, i as toLabel, n as approvalId, o as toState, r as toActor, t as FORGE } from "./gitlab-BoDm8-BC-xzZsW9eW.js";
4
- //#region ../forge/dist/events-7EBoeIPd-A2RUkJi5.js
5
- const EVENT_HEADER = "x-gitlab-event";
6
- function snapshotOf(instance, raw) {
7
- return raw && threadSnapshot({
8
- title: raw.title,
9
- body: raw.description ?? void 0,
10
- state: raw.state ? toState(raw.state) : void 0,
11
- stateRaw: raw.state,
12
- isDraft: raw.draft ?? void 0,
13
- labels: raw.labels?.map((label) => toLabel({
14
- name: label.title,
15
- color: label.color,
16
- description: label.description
17
- })),
18
- url: raw.url,
19
- branches: raw.source_branch && raw.target_branch ? {
20
- head: {
21
- ref: raw.source_branch,
22
- sha: raw.last_commit?.id,
23
- repo: raw.source?.path_with_namespace ? toRepoRef(instance, raw.source.path_with_namespace, raw.source.id) : void 0
24
- },
25
- base: { ref: raw.target_branch },
26
- mergeCommitSha: raw.merge_commit_sha ?? void 0
27
- } : void 0
28
- });
29
- }
30
- const ZERO_SHA = /^0+$/;
31
- function repoLevel(instance, payload, who, repo) {
32
- switch (payload.object_kind ?? payload.event_name) {
33
- case "push":
34
- case "tag_push": return refEvent(who, {
35
- ref: payload.ref ?? "",
36
- before: payload.before,
37
- after: payload.after,
38
- created: Boolean(payload.before && ZERO_SHA.test(payload.before)),
39
- deleted: Boolean(payload.after && ZERO_SHA.test(payload.after)),
40
- commits: (payload.commits ?? []).map((commit) => ({
41
- sha: commit.id,
42
- message: commit.message,
43
- author: commit.author?.name,
44
- url: commit.url
45
- })),
46
- commitCount: payload.total_commits_count
47
- });
48
- case "release": {
49
- if (!repo) return;
50
- const action = payload.action === "create" ? "published" : eventAction(payload.action) ?? "other";
51
- return {
52
- kind: "release",
53
- action,
54
- detail: {
55
- type: "release",
56
- release: {
57
- forge: FORGE,
58
- instance,
59
- repo,
60
- id: payload.tag ?? String(payload.id),
61
- tag: payload.tag
62
- },
63
- tag: payload.tag,
64
- name: payload.name,
65
- body: payload.description ?? void 0,
66
- url: payload.url
67
- },
68
- summary: `${who} ${action} ${payload.name ?? payload.tag ?? "a release"}`
69
- };
70
- }
71
- case "wiki_page": {
72
- const page = payload.object_attributes;
73
- const action = eventAction(page?.action) ?? "other";
74
- return {
75
- kind: "wiki",
76
- action,
77
- detail: {
78
- type: "wiki",
79
- title: page?.title,
80
- url: page?.url
81
- },
82
- summary: `${who} ${action} wiki page ${page?.title ?? ""}`.trim()
83
- };
84
- }
85
- case "project_rename": return {
86
- kind: "repo",
87
- action: "renamed",
88
- detail: {
89
- type: "repo_renamed",
90
- from: payload.old_path_with_namespace ?? "",
91
- to: payload.path_with_namespace ?? ""
92
- },
93
- summary: `${who} renamed the project`
94
- };
95
- case "project_transfer": return {
96
- kind: "repo",
97
- action: "transferred",
98
- detail: {
99
- type: "repo_transferred",
100
- fromOwner: payload.old_path_with_namespace?.split("/").slice(0, -1).join("/"),
101
- toOwner: payload.path_with_namespace?.split("/").slice(0, -1).join("/")
102
- },
103
- summary: `${who} transferred the project`
104
- };
105
- case "user_add_to_team":
106
- case "user_remove_from_team":
107
- case "user_add_to_group":
108
- case "user_remove_from_group":
109
- case "user_access_request_to_project":
110
- case "user_update_for_team":
111
- case "user_update_for_group": return {
112
- kind: "membership",
113
- action: membershipAction(payload.event_name),
114
- detail: {
115
- type: "membership",
116
- actionRaw: payload.event_name ?? "member",
117
- member: payload.user_name ? toActor(instance, {
118
- id: payload.user_id ?? 0,
119
- username: payload.user_username ?? payload.user_name,
120
- name: payload.user_name
121
- }) : void 0
122
- },
123
- summary: `${who} changed a membership`
124
- };
125
- default: return;
126
- }
127
- }
128
- /** The time of the change a project-level delivery reports, else the time its subject last changed. */
129
- function repoLevelTime(payload) {
130
- if (payload.object_kind === "release") return payload.action === "create" ? payload.created_at ?? payload.released_at : void 0;
131
- if (payload.event_name?.startsWith("user_add_")) return payload.created_at;
132
- if (payload.event_name?.startsWith("user_remove_")) return;
133
- return payload.commits?.at(-1)?.timestamp ?? payload.updated_at;
134
- }
135
- /** The time of the change an issue, merge request or note delivery reports, else the time its subject last changed. */
136
- function threadTime(payload) {
137
- const attributes = payload.object_attributes;
138
- const action = attributes?.action;
139
- if (payload.object_kind === "note") return action === "update" ? attributes?.updated_at : attributes?.created_at ?? attributes?.updated_at;
140
- if (action === "open") return attributes?.created_at;
141
- return (action === "close" ? attributes?.closed_at : void 0) ?? attributes?.updated_at;
142
- }
143
- function membershipAction(eventName) {
144
- if (eventName?.startsWith("user_add_")) return "added";
145
- if (eventName?.startsWith("user_remove_")) return "removed";
146
- return eventName?.startsWith("user_update_") ? "edited" : "other";
147
- }
148
- function diff(change, key) {
149
- const previous = change?.previous ?? [];
150
- const current = change?.current ?? [];
151
- const before = new Set(previous.map(key));
152
- const after = new Set(current.map(key));
153
- return {
154
- added: current.filter((item) => !before.has(key(item))),
155
- removed: previous.filter((item) => !after.has(key(item)))
156
- };
157
- }
158
- /** One event per label, assignee or reviewer an `update` delivery adds or removes. */
159
- function changeEvents(instance, payload, who) {
160
- const changes = payload.changes;
161
- if (payload.object_attributes?.action !== "update" || !changes) return [];
162
- const events = [];
163
- const labels = diff(changes.labels, (label) => label.title);
164
- for (const [items, action, verb] of [[
165
- labels.added,
166
- "labelled",
167
- "added"
168
- ], [
169
- labels.removed,
170
- "unlabelled",
171
- "removed"
172
- ]]) for (const { title = "" } of items) events.push({
173
- kind: "label",
174
- action,
175
- detail: {
176
- type: "label",
177
- label: title
178
- },
179
- summary: `${who} ${verb} label ${title}`.trim()
180
- });
181
- const people = (change, added, removed) => {
182
- const { added: joined, removed: left } = diff(change, (user) => user.username);
183
- for (const [users, [action, verb]] of [[joined, added], [left, removed]]) for (const user of users) events.push({
184
- kind: "assignment",
185
- action,
186
- detail: {
187
- type: "assignment",
188
- assignee: toActor(instance, user)
189
- },
190
- summary: `${who} ${verb} ${user.username}`
191
- });
192
- };
193
- people(changes.assignees, ["assigned", "assigned"], ["unassigned", "unassigned"]);
194
- people(changes.reviewers, ["review_requested", "requested review from"], ["other", "removed the review request for"]);
195
- return events;
196
- }
197
- function eventKindFor(payload) {
198
- const attributes = payload.object_attributes;
199
- switch (payload.object_kind) {
200
- case "note": return attributes?.noteable_type !== "Commit" && (attributes?.type === "DiffNote" || attributes?.position) ? "review_comment" : "comment";
201
- case "push": return "commit";
202
- case "emoji": return "reaction";
203
- case "issue":
204
- case "merge_request": switch (attributes?.action) {
205
- case "approved":
206
- case "approval": return "review";
207
- case "open":
208
- case "close":
209
- case "reopen":
210
- case "merge": return "state_change";
211
- case "update":
212
- if (payload.changes?.labels) return "label";
213
- if (payload.changes?.assignees || payload.changes?.reviewers) return "assignment";
214
- return "other";
215
- default: return "other";
216
- }
217
- default: return "other";
218
- }
219
- }
220
- function translateGitLabWebhook(instance, delivery) {
221
- const event = headerValue(delivery.headers, EVENT_HEADER);
222
- if (!event) throw new WebhookVerificationError(`Missing ${EVENT_HEADER} header`, {
223
- forge: FORGE,
224
- instance
225
- });
226
- const deliveryId = headerValue(delivery.headers, "x-gitlab-event-uuid") ?? crypto.randomUUID();
227
- const payload = JSON.parse(bodyText(delivery.body));
228
- const repo = payload.project?.path_with_namespace ? toRepoRef(instance, payload.project.path_with_namespace, payload.project.id) : payload.path_with_namespace ? toRepoRef(instance, payload.path_with_namespace, payload.project_id) : void 0;
229
- const user = payload.user?.username ? toActor(instance, {
230
- id: payload.user.id ?? 0,
231
- ...payload.user,
232
- username: payload.user.username
233
- }) : void 0;
234
- const attributes = payload.object_attributes;
235
- const subject = payload.object_kind === "note" ? payload.merge_request ? {
236
- kind: "pull_request",
237
- iid: payload.merge_request.iid
238
- } : payload.issue ? {
239
- kind: "issue",
240
- iid: payload.issue.iid
241
- } : void 0 : payload.object_kind === "merge_request" && attributes?.iid !== void 0 ? {
242
- kind: "pull_request",
243
- iid: attributes.iid
244
- } : payload.object_kind === "issue" && attributes?.iid !== void 0 ? {
245
- kind: "issue",
246
- iid: attributes.iid
247
- } : void 0;
248
- const thread = repo && subject ? {
249
- forge: FORGE,
250
- instance,
251
- repo,
252
- kind: subject.kind,
253
- number: String(subject.iid)
254
- } : void 0;
255
- const commit = repo && !thread && payload.object_kind === "note" && payload.commit?.id ? {
256
- forge: FORGE,
257
- instance,
258
- repo,
259
- sha: payload.commit.id
260
- } : void 0;
261
- const snapshot = thread && snapshotOf(instance, payload.object_kind === "note" ? payload.merge_request ?? payload.issue : attributes);
262
- const level = repoLevel(instance, payload, user?.login ?? payload.user_username ?? "someone", repo);
263
- if (level) return [{
264
- forge: FORGE,
265
- instance,
266
- id: deliveryId,
267
- kind: level.kind,
268
- action: level.action,
269
- kindRaw: payload.object_kind ?? payload.event_name ?? event,
270
- summary: level.summary,
271
- ...eventTime(toDate(repoLevelTime(payload))),
272
- actor: user,
273
- repo,
274
- detail: level.detail,
275
- source: "webhook",
276
- payload
277
- }];
278
- const time = eventTime(toDate(threadTime(payload)));
279
- const changes = changeEvents(instance, payload, user?.login ?? "someone");
280
- if (changes.length) return changes.map((change, index) => ({
281
- forge: FORGE,
282
- instance,
283
- id: changes.length === 1 ? deliveryId : `${deliveryId}:${index}`,
284
- ...change,
285
- kindRaw: `${payload.object_kind}.update`,
286
- actionRaw: "update",
287
- ...time,
288
- actor: user,
289
- repo,
290
- thread,
291
- threadSnapshot: snapshot,
292
- source: "webhook",
293
- payload
294
- }));
295
- const kind = eventKindFor(payload);
296
- const action = attributes?.action;
297
- return [{
298
- forge: FORGE,
299
- instance,
300
- id: deliveryId,
301
- kind,
302
- kindRaw: action ? `${payload.object_kind}.${action}` : payload.object_kind ?? event,
303
- action: action === "update" && attributes?.oldrev ? "synchronised" : action === "merge" ? "merged" : eventAction(action),
304
- actionRaw: action,
305
- detail: kind === "review_comment" ? {
306
- type: kind,
307
- comment: thread && attributes?.id !== void 0 ? {
308
- forge: FORGE,
309
- instance,
310
- thread,
311
- id: String(attributes.id)
312
- } : void 0,
313
- body: attributes?.note
314
- } : kind === "comment" ? {
315
- type: kind,
316
- comment: attributes?.id === void 0 ? void 0 : thread ? {
317
- forge: FORGE,
318
- instance,
319
- thread,
320
- id: String(attributes.id)
321
- } : commit && {
322
- forge: "gitlab",
323
- instance,
324
- commit,
325
- id: String(attributes.id)
326
- },
327
- body: attributes?.note
328
- } : kind === "state_change" ? {
329
- type: "state_change",
330
- state: action === "merge" ? "merged" : action === "close" ? "closed" : "open"
331
- } : kind === "review" ? {
332
- type: "review",
333
- state: "approved",
334
- stateRaw: action,
335
- review: thread && payload.user?.username ? {
336
- forge: FORGE,
337
- instance,
338
- thread,
339
- id: approvalId(payload.user)
340
- } : void 0
341
- } : void 0,
342
- summary: payload.object_kind === "note" ? `${user?.login ?? "someone"} commented` : `${user?.login ?? "someone"} ${action ? `${action} ` : ""}${payload.object_kind ?? event}`.trim(),
343
- ...time,
344
- actor: user,
345
- repo,
346
- thread,
347
- commit,
348
- threadSnapshot: snapshot,
349
- source: "webhook",
350
- payload
351
- }];
352
- }
353
- //#endregion
354
- export { translateGitLabWebhook };
@@ -1,214 +0,0 @@
1
- import { It as toDate, U as WebhookVerificationError } from "./shared-DalXdP0i.js";
2
- import { _ as reviewState, a as eventAction, g as refEvent, l as firstHeader, n as bodyText, s as eventTime, y as snapshotOfThread } from "./webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js";
3
- import { i as toThread, n as toActor, r as toRepoRef, t as FORGEJO_HEADERS } from "./forgejo-BN8ItCfl-Bbn4vhDd.js";
4
- //#region ../forge/dist/events-CRaLy7U3-3PNNp5WZ.js
5
- const EVENT_KINDS = {
6
- issue_comment: "comment",
7
- pull_request_comment: "comment",
8
- pull_request_review_comment: "review_comment",
9
- pull_request_review_approved: "review",
10
- pull_request_review_rejected: "review",
11
- pull_request_review_comment_created: "review_comment",
12
- pull_request_label: "label",
13
- issue_label: "label",
14
- issue_assign: "assignment",
15
- pull_request_assign: "assignment"
16
- };
17
- function eventKindFor(event, payload) {
18
- const mapped = EVENT_KINDS[event];
19
- if (mapped) return mapped;
20
- if (event === "issues" || event === "pull_request") switch (payload.action) {
21
- case "label_updated":
22
- case "label_cleared": return "label";
23
- case "assigned":
24
- case "unassigned": return "assignment";
25
- case "opened":
26
- case "closed":
27
- case "reopened":
28
- case "merged": return "state_change";
29
- default: return "other";
30
- }
31
- return "other";
32
- }
33
- const ZERO_SHA = /^0+$/;
34
- function repoLevel(origin, event, payload, who) {
35
- switch (event) {
36
- case "push": return refEvent(who, {
37
- ref: payload.ref ?? "",
38
- before: payload.before,
39
- after: payload.after,
40
- deleted: Boolean(payload.after && ZERO_SHA.test(payload.after)),
41
- commits: (payload.commits ?? []).map((commit) => ({
42
- sha: commit.id,
43
- message: commit.message,
44
- author: commit.author?.username ?? commit.author?.name,
45
- url: commit.url
46
- })),
47
- commitCount: payload.total_commits
48
- });
49
- case "create":
50
- case "delete": return {
51
- kind: "ref",
52
- action: event === "create" ? "created" : "deleted",
53
- detail: {
54
- type: "ref",
55
- ref: payload.ref ?? "",
56
- refType: payload.ref_type ?? "branch"
57
- },
58
- summary: `${who} ${event === "create" ? "created" : "deleted"} ${payload.ref_type ?? "ref"} ${payload.ref ?? ""}`.trim()
59
- };
60
- case "fork": return {
61
- kind: "fork",
62
- action: "created",
63
- detail: {
64
- type: "fork",
65
- fork: payload.repository ? toRepoRef(origin, payload.repository) : void 0
66
- },
67
- summary: `${who} forked the repository${payload.repository ? ` to ${payload.repository.full_name}` : ""}`
68
- };
69
- case "wiki": return {
70
- kind: "wiki",
71
- action: eventAction(payload.action) ?? "other",
72
- detail: {
73
- type: "wiki",
74
- title: payload.page
75
- },
76
- summary: `${who} ${payload.action ?? "edited"} wiki page ${payload.page ?? ""}`.trim()
77
- };
78
- case "release":
79
- if (!payload.release || !payload.repository) return;
80
- return {
81
- kind: "release",
82
- action: eventAction(payload.action) ?? "other",
83
- detail: {
84
- type: "release",
85
- release: {
86
- ...origin,
87
- repo: toRepoRef(origin, payload.repository),
88
- id: String(payload.release.id),
89
- tag: payload.release.tag_name
90
- },
91
- tag: payload.release.tag_name,
92
- name: payload.release.name,
93
- body: payload.release.body || void 0,
94
- isPrerelease: payload.release.prerelease,
95
- isDraft: payload.release.draft,
96
- url: payload.release.html_url
97
- },
98
- summary: `${who} ${payload.action ?? "published"} ${payload.release.name || payload.release.tag_name || "a release"}`
99
- };
100
- default: return;
101
- }
102
- }
103
- function detailOf(kind, event, thread, origin, payload) {
104
- const comment = payload.comment;
105
- const commentRef = comment?.id !== void 0 && thread ? {
106
- ...origin,
107
- thread,
108
- id: String(comment.id)
109
- } : void 0;
110
- switch (kind) {
111
- case "comment": return {
112
- type: "comment",
113
- comment: commentRef,
114
- body: comment?.body
115
- };
116
- case "review_comment": return {
117
- type: "review_comment",
118
- comment: commentRef,
119
- body: comment?.body,
120
- path: comment?.path,
121
- line: comment?.line
122
- };
123
- case "review": {
124
- const stateRaw = event.replace("pull_request_review_", "");
125
- return {
126
- type: "review",
127
- state: reviewState(stateRaw === "rejected" ? "changes_requested" : stateRaw),
128
- stateRaw,
129
- body: payload.review?.content
130
- };
131
- }
132
- case "label": return payload.label?.name ? {
133
- type: "label",
134
- label: payload.label.name
135
- } : void 0;
136
- case "assignment": return {
137
- type: "assignment",
138
- assignee: toActor(origin, payload.assignee)
139
- };
140
- case "state_change": return {
141
- type: "state_change",
142
- state: payload.pull_request?.merged ? "merged" : payload.action === "closed" ? "closed" : "open",
143
- draft: payload.pull_request?.draft
144
- };
145
- default: return;
146
- }
147
- }
148
- /** The time of the change a thread event reports, else the time its thread last changed, unless the event is a deletion. */
149
- function threadTime({ action, comment, pull_request: pull }, subject) {
150
- if (action === "deleted") return;
151
- let own;
152
- if (comment) own = action === "edited" ? comment.updated_at : comment.created_at;
153
- else if (action === "opened") own = subject?.created_at;
154
- else if (action === "closed" || action === "merged") own = pull?.merged_at ?? subject?.closed_at;
155
- return toDate(own ?? subject?.updated_at);
156
- }
157
- function translateForgejoWebhook(origin, delivery, names = FORGEJO_HEADERS) {
158
- const event = firstHeader(delivery, names.event);
159
- if (!event) throw new WebhookVerificationError(`Missing ${names.event[0]} header`, origin);
160
- const deliveryId = firstHeader(delivery, names.delivery) ?? crypto.randomUUID();
161
- const payload = JSON.parse(bodyText(delivery.body));
162
- const source = event === "fork" ? payload.forkee : payload.repository;
163
- const repo = source ? toRepoRef(origin, source) : void 0;
164
- const actor = toActor(origin, payload.sender);
165
- const who = actor?.login ?? "someone";
166
- const level = repoLevel(origin, event, payload, who);
167
- if (level) return [{
168
- ...origin,
169
- id: deliveryId,
170
- kind: level.kind,
171
- action: level.action,
172
- kindRaw: payload.action ? `${event}.${payload.action}` : event,
173
- summary: level.summary,
174
- ...eventTime(toDate(payload.head_commit?.timestamp ?? payload.commits?.at(-1)?.timestamp ?? (payload.action === "published" ? payload.release?.published_at : void 0) ?? (event === "fork" ? payload.repository?.created_at : void 0))),
175
- actor,
176
- repo,
177
- detail: level.detail,
178
- source: "webhook",
179
- payload
180
- }];
181
- const subject = payload.pull_request ?? payload.issue;
182
- const isPull = Boolean(payload.pull_request || payload.is_pull || payload.issue?.pull_request);
183
- const thread = repo && subject ? {
184
- ...origin,
185
- repo,
186
- kind: isPull ? "pull_request" : "issue",
187
- number: String(subject.number)
188
- } : void 0;
189
- const normalised = thread && subject && toThread(thread, subject);
190
- const kind = eventKindFor(event, payload);
191
- return [{
192
- ...origin,
193
- id: deliveryId,
194
- kind,
195
- kindRaw: payload.action ? `${event}.${payload.action}` : event,
196
- action: payload.action === "closed" && payload.pull_request?.merged ? "merged" : eventAction(payload.action),
197
- actionRaw: payload.action,
198
- detail: detailOf(kind, event, thread, origin, payload),
199
- summary: `${who} ${payload.action ? `${payload.action} ` : ""}${event}`.trim(),
200
- ...eventTime(threadTime(payload, subject)),
201
- actor,
202
- repo,
203
- thread,
204
- threadSnapshot: normalised && snapshotOfThread({
205
- ...normalised,
206
- isDraft: isPull ? subject?.draft ?? subject?.pull_request?.draft : false,
207
- labels: subject?.labels && normalised.labels
208
- }),
209
- source: "webhook",
210
- payload
211
- }];
212
- }
213
- //#endregion
214
- export { translateForgejoWebhook };