@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,527 +0,0 @@
1
- import { Bt as toPullStats, It as toDate, U as WebhookVerificationError } from "./shared-DalXdP0i.js";
2
- import { S as threadSnapshot, _ as reviewState, 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 toLabels, n as toActor, o as toThreadState, r as toIssueType, t as FORGE } from "./github-DtncTfmv-Du2S8lGF.js";
4
- //#region ../forge/dist/events-CeChclTf-CX-gD8oy.js
5
- const EVENT_HEADER = "x-github-event";
6
- const DELIVERY_HEADER = "x-github-delivery";
7
- function visibilityChange(isPublic, who, payload) {
8
- return {
9
- kind: "repo",
10
- action: "edited",
11
- detail: {
12
- type: "repo_visibility",
13
- isPublic
14
- },
15
- summary: `${who} made the repository ${isPublic ? "public" : "private"}`,
16
- occurredAt: toDate(payload.repository?.updated_at)
17
- };
18
- }
19
- function repoLevel(instance, event, payload, who, repo) {
20
- switch (event) {
21
- case "push": return {
22
- ...refEvent(who, {
23
- ref: payload.ref ?? "",
24
- before: payload.before,
25
- after: payload.after ?? payload.head,
26
- deleted: payload.deleted,
27
- forced: payload.forced,
28
- commits: payload.commits?.map((commit) => ({
29
- sha: commit.id ?? commit.sha ?? "",
30
- message: commit.message,
31
- author: commit.author?.username ?? commit.author?.name,
32
- url: commit.url
33
- })),
34
- commitCount: payload.size
35
- }),
36
- occurredAt: payload.deleted ? void 0 : pushedAt(payload.repository?.pushed_at) ?? toDate(payload.head_commit?.timestamp)
37
- };
38
- case "create":
39
- case "delete":
40
- if (payload.ref_type === "repository") return {
41
- kind: "repo",
42
- action: event === "create" ? "created" : "deleted",
43
- summary: `${who} ${event === "create" ? "created" : "deleted"} the repository`
44
- };
45
- return {
46
- kind: "ref",
47
- action: event === "create" ? "created" : "deleted",
48
- detail: {
49
- type: "ref",
50
- ref: payload.ref ?? "",
51
- refType: payload.ref_type ?? "branch"
52
- },
53
- summary: `${who} ${event === "create" ? "created" : "deleted"} ${payload.ref_type ?? "ref"} ${payload.ref ?? ""}`.trim()
54
- };
55
- case "repository":
56
- if (payload.action === "renamed") return {
57
- kind: "repo",
58
- action: "renamed",
59
- detail: {
60
- type: "repo_renamed",
61
- from: payload.changes?.repository?.name?.from ?? "",
62
- to: payload.repository?.name ?? ""
63
- },
64
- summary: `${who} renamed the repository`,
65
- occurredAt: toDate(payload.repository?.updated_at)
66
- };
67
- if (payload.action === "transferred") {
68
- const from = payload.changes?.owner?.from;
69
- return {
70
- kind: "repo",
71
- action: "transferred",
72
- detail: {
73
- type: "repo_transferred",
74
- fromOwner: (from?.organization ?? from?.user)?.login,
75
- toOwner: payload.repository?.owner?.login
76
- },
77
- summary: `${who} transferred the repository`,
78
- occurredAt: toDate(payload.repository?.updated_at)
79
- };
80
- }
81
- if (payload.action === "archived" || payload.action === "unarchived") return {
82
- kind: "repo",
83
- action: payload.action,
84
- detail: {
85
- type: "repo_archived",
86
- archived: payload.action === "archived"
87
- },
88
- summary: `${who} ${payload.action} the repository`,
89
- occurredAt: toDate(payload.repository?.updated_at)
90
- };
91
- if (payload.action === "publicized" || payload.action === "privatized") return visibilityChange(payload.action === "publicized", who, payload);
92
- return;
93
- case "public": return visibilityChange(true, who, payload);
94
- case "star":
95
- case "watch": return {
96
- kind: "star",
97
- action: payload.action === "deleted" ? "deleted" : "created",
98
- summary: `${who} ${payload.action === "deleted" ? "unstarred" : "starred"} the repository`,
99
- occurredAt: toDate(payload.starred_at)
100
- };
101
- case "fork": return {
102
- kind: "fork",
103
- action: "created",
104
- detail: {
105
- type: "fork",
106
- fork: payload.forkee ? toRepoRef(instance, payload.forkee) : void 0
107
- },
108
- summary: `${who} forked the repository${payload.forkee ? ` to ${payload.forkee.full_name}` : ""}`,
109
- occurredAt: toDate(payload.forkee?.created_at)
110
- };
111
- case "gollum": {
112
- const page = payload.pages?.[0];
113
- return {
114
- kind: "wiki",
115
- action: eventAction(page?.action) ?? "edited",
116
- detail: {
117
- type: "wiki",
118
- title: page?.title ?? page?.page_name,
119
- url: page?.html_url
120
- },
121
- summary: `${who} ${page?.action ?? "edited"} wiki page ${page?.title ?? page?.page_name ?? ""}`.trim()
122
- };
123
- }
124
- case "installation":
125
- case "installation_repositories": return {
126
- kind: "installation",
127
- detail: {
128
- type: "installation",
129
- actionRaw: payload.action ?? event,
130
- installationId: payload.installation ? String(payload.installation.id) : void 0,
131
- added: (payload.repositories_added ?? (payload.action === "created" ? payload.repositories : void 0) ?? []).map((repo) => toRepoRef(instance, repo)),
132
- removed: (payload.repositories_removed ?? []).map((repo) => toRepoRef(instance, repo))
133
- },
134
- summary: `${who} ${payload.action ?? "changed"} the installation`
135
- };
136
- case "member":
137
- case "membership": return {
138
- kind: "membership",
139
- detail: {
140
- type: "membership",
141
- actionRaw: payload.action ?? event,
142
- member: toActor(instance, payload.member ?? payload.membership?.user)
143
- },
144
- summary: `${who} ${payload.action ?? "changed"} a member`
145
- };
146
- case "release":
147
- if (!payload.release || !repo) return;
148
- return {
149
- kind: "release",
150
- action: eventAction(payload.action) ?? "other",
151
- detail: {
152
- type: "release",
153
- release: {
154
- forge: FORGE,
155
- instance,
156
- repo,
157
- id: String(payload.release.id),
158
- tag: payload.release.tag_name
159
- },
160
- tag: payload.release.tag_name,
161
- name: payload.release.name ?? void 0,
162
- body: payload.release.body ?? void 0,
163
- isPrerelease: payload.release.prerelease,
164
- isDraft: payload.release.draft,
165
- url: payload.release.html_url
166
- },
167
- summary: `${who} ${payload.action ?? "published"} ${payload.release.name || payload.release.tag_name || "a release"}`,
168
- occurredAt: payload.action === "published" ? toDate(payload.release.published_at) : void 0
169
- };
170
- default: return;
171
- }
172
- }
173
- const THREAD_EVENT_KIND = {
174
- issue_comment: "comment",
175
- discussion_comment: "comment",
176
- commit_comment: "comment",
177
- pull_request_review: "review",
178
- pull_request_review_comment: "review_comment"
179
- };
180
- function threadOf(payload, repo, instance) {
181
- if (!repo) return;
182
- const candidates = [
183
- ["pull_request", payload.pull_request],
184
- ["discussion", payload.discussion],
185
- [payload.issue?.pull_request ? "pull_request" : "issue", payload.issue]
186
- ];
187
- for (const [kind, subject] of candidates) if (subject) return {
188
- forge: FORGE,
189
- instance,
190
- repo,
191
- kind,
192
- number: String(subject.number),
193
- externalId: subject.node_id
194
- };
195
- }
196
- /** The commit of a comment on a commit, which names no thread. */
197
- function commitOf(payload, thread, repo, instance) {
198
- return !thread && repo && payload.comment?.commit_id ? {
199
- forge: FORGE,
200
- instance,
201
- repo,
202
- sha: payload.comment.commit_id
203
- } : void 0;
204
- }
205
- /** The repository a pull request's head is on. Activity feeds name it by an API `url` alone. */
206
- function headRepo(instance, repo) {
207
- if (repo?.full_name) return toRepoRef(instance, repo);
208
- const [, owner, name] = repo?.url?.match(/\/repos\/([^/]+)\/([^/]+)$/) ?? [];
209
- return owner && name ? {
210
- forge: FORGE,
211
- instance,
212
- owner,
213
- name,
214
- externalId: repo?.id === void 0 ? void 0 : String(repo.id)
215
- } : void 0;
216
- }
217
- function snapshotOf(instance, payload) {
218
- const raw = payload.pull_request ?? payload.discussion ?? payload.issue;
219
- return raw && threadSnapshot({
220
- title: raw.title,
221
- body: raw.body ?? void 0,
222
- state: raw.state === void 0 ? void 0 : toThreadState({
223
- state: raw.state,
224
- merged: raw.merged ?? void 0,
225
- merged_at: raw.merged_at,
226
- pull_request: raw.pull_request
227
- }),
228
- stateRaw: raw.state,
229
- stateReason: raw.state_reason ?? void 0,
230
- isDraft: raw.draft,
231
- author: toActor(instance, raw.user),
232
- labels: raw.labels && toLabels(raw.labels),
233
- issueType: toIssueType(raw.type),
234
- url: raw.html_url,
235
- branches: raw.head && raw.base ? {
236
- head: {
237
- ref: raw.head.ref,
238
- sha: raw.head.sha,
239
- repo: headRepo(instance, raw.head.repo)
240
- },
241
- base: {
242
- ref: raw.base.ref,
243
- sha: raw.base.sha
244
- },
245
- mergeCommitSha: raw.merge_commit_sha ?? void 0
246
- } : void 0,
247
- stats: toPullStats({
248
- additions: raw.additions,
249
- deletions: raw.deletions,
250
- changedFileCount: raw.changed_files,
251
- commitCount: raw.commits
252
- }),
253
- mergedBy: toActor(instance, raw.merged_by)
254
- });
255
- }
256
- function eventKindFor(event, payload) {
257
- const mapped = THREAD_EVENT_KIND[event];
258
- if (mapped) return mapped;
259
- if (event === "issues" || event === "pull_request" || event === "discussion") switch (payload.action) {
260
- case "labeled":
261
- case "unlabeled": return "label";
262
- case "typed":
263
- case "untyped": return "issue_type";
264
- case "assigned":
265
- case "unassigned": return "assignment";
266
- case "closed":
267
- case "reopened":
268
- case "opened":
269
- case "merged":
270
- case "ready_for_review":
271
- case "converted_to_draft": return "state_change";
272
- case "synchronize": return "commit";
273
- case "review_requested":
274
- case "review_request_removed": return "assignment";
275
- default: return "other";
276
- }
277
- if (event.endsWith("reaction")) return "reaction";
278
- return "other";
279
- }
280
- function summarise(event, payload, actor) {
281
- if (event === "issues" && (payload.action === "typed" || payload.action === "untyped")) return `${actor} ${payload.action === "typed" ? "set" : "removed"} the issue type ${payload.type?.name ?? ""}`.trim();
282
- switch (event) {
283
- case "issue_comment":
284
- case "discussion_comment":
285
- case "commit_comment": return `${actor} ${payload.action ?? "created"} a comment`;
286
- case "pull_request_review": return `${actor} ${payload.action ?? "submitted"} a review (${payload.review?.state ?? "commented"})`;
287
- case "pull_request_review_comment": return `${actor} ${payload.action ?? "created"} a review comment`;
288
- case "label": return `${actor} ${payload.action ?? "changed"} label ${payload.label?.name ?? ""}`.trim();
289
- default: return `${actor} ${payload.action ? `${payload.action} ` : ""}${event}`.trim();
290
- }
291
- }
292
- function pushedAt(value) {
293
- return typeof value === "number" ? /* @__PURE__ */ new Date(value * 1e3) : toDate(value);
294
- }
295
- /** The time of the change a thread event reports, else the time its thread last changed, unless the event is a deletion. */
296
- function threadTime(payload) {
297
- if (payload.action === "deleted") return;
298
- const subject = payload.pull_request ?? payload.discussion ?? payload.issue;
299
- return toDate(ownTime(payload, subject) ?? subject?.updated_at);
300
- }
301
- function ownTime({ action, comment, review, pull_request: pull }, subject) {
302
- if (comment) return action === "edited" ? comment.updated_at : comment.created_at;
303
- if (review) return action === "submitted" ? review.submitted_at : void 0;
304
- if (action === "opened") return subject?.created_at;
305
- return action === "closed" ? pull?.merged_at ?? subject?.closed_at : void 0;
306
- }
307
- function actionOf(event, payload) {
308
- if (event === "pull_request" && payload.action === "closed" && payload.pull_request?.merged) return "merged";
309
- return eventAction(payload.action);
310
- }
311
- function detailOf(kind, thread, commit, instance, payload) {
312
- const comment = payload.comment;
313
- const commentRef = comment?.id !== void 0 && thread ? {
314
- forge: FORGE,
315
- instance,
316
- thread,
317
- id: thread.kind === "discussion" && comment.node_id ? comment.node_id : String(comment.id)
318
- } : void 0;
319
- switch (kind) {
320
- case "comment": return {
321
- type: "comment",
322
- comment: commentRef ?? (comment?.id !== void 0 && commit ? {
323
- forge: "github",
324
- instance,
325
- commit,
326
- id: String(comment.id)
327
- } : void 0),
328
- body: comment?.body
329
- };
330
- case "review_comment": return {
331
- type: "review_comment",
332
- comment: commentRef,
333
- body: comment?.body,
334
- path: comment?.path,
335
- line: comment?.line ?? void 0
336
- };
337
- case "review": return {
338
- type: "review",
339
- state: reviewState(payload.review?.state),
340
- stateRaw: payload.review?.state,
341
- body: payload.review?.body ?? void 0,
342
- review: payload.review?.id !== void 0 && thread ? {
343
- forge: FORGE,
344
- instance,
345
- thread,
346
- id: String(payload.review.id)
347
- } : void 0
348
- };
349
- case "label": return payload.label?.name ? {
350
- type: "label",
351
- label: payload.label.name
352
- } : void 0;
353
- case "issue_type": return payload.type ? {
354
- type: "issue_type",
355
- issueType: toIssueType(payload.type)
356
- } : void 0;
357
- case "assignment": return {
358
- type: "assignment",
359
- assignee: toActor(instance, payload.assignee ?? payload.requested_reviewer ?? void 0)
360
- };
361
- case "state_change": {
362
- const pull = payload.pull_request;
363
- const state = pull?.merged || payload.action === "merged" ? "merged" : payload.action === "closed" ? "closed" : "open";
364
- const reason = payload.action === "closed" || payload.action === "reopened" ? payload.issue?.state_reason ?? void 0 : void 0;
365
- return {
366
- type: "state_change",
367
- state,
368
- draft: pull?.draft,
369
- reason
370
- };
371
- }
372
- default: return;
373
- }
374
- }
375
- /** Normalises a GitHub event, named as a webhook names it, from a webhook delivery or an activity feed. */
376
- function toGitHubEvent(instance, event, payload, context) {
377
- const { actor, repo } = context;
378
- const level = repoLevel(instance, event, payload, actor?.login ?? "someone", repo);
379
- if (level) return {
380
- forge: FORGE,
381
- instance,
382
- id: context.id,
383
- kind: level.kind,
384
- action: level.action,
385
- kindRaw: context.kindRaw,
386
- actionRaw: context.actionRaw,
387
- summary: level.summary,
388
- ...eventTime(context.occurredAt ?? level.occurredAt),
389
- actor,
390
- repo,
391
- detail: level.detail,
392
- installationId: context.installationId,
393
- source: context.source,
394
- payload: context.payload ?? payload
395
- };
396
- const thread = threadOf(payload, repo, instance);
397
- const commit = commitOf(payload, thread, repo, instance);
398
- const kind = eventKindFor(event, payload);
399
- return {
400
- forge: FORGE,
401
- instance,
402
- id: context.id,
403
- kind,
404
- kindRaw: context.kindRaw,
405
- action: actionOf(event, payload),
406
- actionRaw: context.actionRaw,
407
- detail: detailOf(kind, thread, commit, instance, payload),
408
- summary: summarise(event, payload, actor?.login ?? "someone"),
409
- ...eventTime(context.occurredAt ?? threadTime(payload)),
410
- actor,
411
- repo,
412
- thread,
413
- commit,
414
- threadSnapshot: snapshotOf(instance, payload),
415
- installationId: context.installationId,
416
- source: context.source,
417
- payload: context.payload ?? payload
418
- };
419
- }
420
- function translateGitHubWebhook(instance, delivery) {
421
- const event = headerValue(delivery.headers, EVENT_HEADER);
422
- if (!event) throw new WebhookVerificationError(`Missing ${EVENT_HEADER} header`, {
423
- forge: FORGE,
424
- instance
425
- });
426
- const payload = JSON.parse(bodyText(delivery.body));
427
- const id = headerValue(delivery.headers, DELIVERY_HEADER) ?? crypto.randomUUID();
428
- return perPage(event, payload).map(([page, suffix]) => toGitHubEvent(instance, event, page, {
429
- id: `${id}${suffix}`,
430
- kindRaw: verbOf(page) ? `${event}.${verbOf(page)}` : event,
431
- actionRaw: verbOf(page),
432
- source: "webhook",
433
- actor: toActor(instance, payload.sender),
434
- repo: payload.repository ? toRepoRef(instance, payload.repository) : void 0,
435
- installationId: payload.installation ? String(payload.installation.id) : void 0
436
- }));
437
- }
438
- /** The payload's verb; a wiki page's action is on the page. */
439
- function verbOf(payload) {
440
- return payload.action ?? payload.pages?.[0]?.action;
441
- }
442
- /** A `gollum` event can cover several wiki pages; each page is an event of its own, with an id suffix when there are several. */
443
- function perPage(event, payload) {
444
- const pages = event === "gollum" ? payload.pages ?? [] : [];
445
- return pages.length > 1 ? pages.map((page, index) => [{
446
- ...payload,
447
- pages: [page]
448
- }, `:${index}`]) : [[payload, ""]];
449
- }
450
- /** Activity feed event types and the webhook events they correspond to. */
451
- const FEED_EVENTS = {
452
- CommitCommentEvent: "commit_comment",
453
- CreateEvent: "create",
454
- DeleteEvent: "delete",
455
- DiscussionEvent: "discussion",
456
- IssueCommentEvent: "issue_comment",
457
- IssuesEvent: "issues",
458
- MemberEvent: "member",
459
- PullRequestEvent: "pull_request",
460
- PullRequestReviewCommentEvent: "pull_request_review_comment",
461
- PullRequestReviewEvent: "pull_request_review",
462
- PushEvent: "push",
463
- ReleaseEvent: "release",
464
- ForkEvent: "fork",
465
- GollumEvent: "gollum",
466
- PublicEvent: "public",
467
- WatchEvent: "watch"
468
- };
469
- /** Summaries of the feed event types that have no shared kind. */
470
- const FEED_SUMMARIES = { SponsorshipEvent: "changed a sponsorship" };
471
- /** Normalises an item of an activity feed into one event per wiki page, and one event otherwise. */
472
- function toFeedEvents(instance, raw) {
473
- const pages = raw.type === "GollumEvent" ? perPage("gollum", raw.payload ?? {}) : [];
474
- return pages.length > 1 ? pages.map(([payload, suffix]) => ({
475
- ...toFeedEvent(instance, {
476
- ...raw,
477
- payload
478
- }),
479
- id: `${raw.id}${suffix}`,
480
- payload: raw
481
- })) : [toFeedEvent(instance, raw)];
482
- }
483
- /** Normalises an item of a repository's or an account's activity feed. */
484
- function toFeedEvent(instance, raw) {
485
- const type = raw.type ?? "Event";
486
- const payload = raw.payload ?? {};
487
- const [owner = "", name = ""] = raw.repo?.name.split("/") ?? [];
488
- const repo = raw.repo ? {
489
- forge: FORGE,
490
- instance,
491
- owner,
492
- name,
493
- externalId: String(raw.repo.id)
494
- } : void 0;
495
- const actor = toActor(instance, raw.actor);
496
- const visibility = typeof raw.public === "boolean" ? { isPublic: raw.public } : {};
497
- const context = {
498
- id: raw.id,
499
- kindRaw: verbOf(payload) ? `${type}.${verbOf(payload)}` : type,
500
- actionRaw: verbOf(payload),
501
- source: "poll",
502
- actor,
503
- repo,
504
- occurredAt: toDate(raw.created_at),
505
- payload: raw
506
- };
507
- const event = FEED_EVENTS[type];
508
- if (!event) return {
509
- forge: FORGE,
510
- instance,
511
- ...context,
512
- kind: "other",
513
- summary: `${actor?.login ?? "someone"} ${FEED_SUMMARIES[type] ?? type}`,
514
- ...eventTime(context.occurredAt),
515
- ...visibility,
516
- payload: raw
517
- };
518
- return {
519
- ...toGitHubEvent(instance, event, type === "PullRequestReviewEvent" && payload.action === "created" ? {
520
- ...payload,
521
- action: "submitted"
522
- } : payload, context),
523
- ...visibility
524
- };
525
- }
526
- //#endregion
527
- export { toFeedEvents, translateGitHubWebhook };