@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,527 @@
|
|
|
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 };
|