@vite-hub/forge 0.0.0-stage → 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/LICENSE +201 -0
- package/README.md +78 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh.js +19 -0
- package/dist/events-7EBoeIPd-A2RUkJi5.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy.js +527 -0
- package/dist/events-DudKM7vq-Cj_PCDdt.js +124 -0
- package/dist/events-saDWbqbf-VX_k8jtr.js +131 -0
- package/dist/feed-CmBoYS3Z-CuC4i0fH.js +134 -0
- package/dist/feed-DsC7Vws1-M_de2nSK.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6.js +179 -0
- package/dist/forgejo-BN8ItCfl.js +2282 -0
- package/dist/gitee-DExkQP6X-BxJS2dRY.js +113 -0
- package/dist/github-DtncTfmv.js +4161 -0
- package/dist/gitlab-BoDm8-BC.js +2532 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM.js +489 -0
- package/dist/index.d.ts +3918 -0
- package/dist/index.js +681 -0
- package/dist/knot-BpyTK9D7-CVIsX4I2.js +343 -0
- package/dist/tangled-DPt_0u21-zS41xdG5.js +43 -0
- package/dist/templates-Bn8a-pd2-D9DhJEVD.js +125 -0
- package/dist/utils-CA_4WJhJ-DNgT61X2.js +1517 -0
- package/dist/webhooks-DgHwxxYz-D1V2LOr1.js +1569 -0
- package/package.json +56 -3
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { $ as toDate, _ as WebhookVerificationError, rt as toPullStats } from "./utils-CA_4WJhJ-DNgT61X2.js";
|
|
2
|
+
import { T as headerValue, _ as reviewState, d as eventTime, i as refEvent, u as eventAction, w as bodyText, x as threadSnapshot } from "./webhooks-DgHwxxYz-D1V2LOr1.js";
|
|
3
|
+
import { a as toRepoRef, i as toLabels, n as toActor, o as toThreadState, r as toIssueType, t as FORGE } from "./github-DtncTfmv.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/events-CeChclTf.mjs
|
|
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 };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { $ as toDate } from "./utils-CA_4WJhJ-DNgT61X2.js";
|
|
2
|
+
import { T as headerValue, d as eventTime, i as refEvent, v as snapshotOfThread, w as bodyText } from "./webhooks-DgHwxxYz-D1V2LOr1.js";
|
|
3
|
+
import { a as toRepoRef, i as toPullThread, n as toActor, r as toIssueThread, t as FORGE } from "./gitee-DExkQP6X-BxJS2dRY.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/events-DudKM7vq.mjs
|
|
5
|
+
const STATES = {
|
|
6
|
+
open: "open",
|
|
7
|
+
reopen: "open",
|
|
8
|
+
close: "closed",
|
|
9
|
+
merge: "merged"
|
|
10
|
+
};
|
|
11
|
+
const KINDS = {
|
|
12
|
+
open: "state_change",
|
|
13
|
+
close: "state_change",
|
|
14
|
+
reopen: "state_change",
|
|
15
|
+
merge: "state_change",
|
|
16
|
+
state_change: "state_change",
|
|
17
|
+
approved: "review",
|
|
18
|
+
tested: "review",
|
|
19
|
+
assign: "assignment",
|
|
20
|
+
label: "label"
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The time of the change a delivery reports, else the time its subject last
|
|
24
|
+
* changed, else the time of the pushed head commit.
|
|
25
|
+
*/
|
|
26
|
+
function giteeTime(hook, payload) {
|
|
27
|
+
const { action, comment, issue, pull_request: pull } = payload;
|
|
28
|
+
const subject = pull ?? issue;
|
|
29
|
+
let own;
|
|
30
|
+
if (hook === "note_hooks" || hook === "Note Hook") own = comment?.created_at;
|
|
31
|
+
else if (action === "open") own = subject?.created_at;
|
|
32
|
+
else if (action === "merge") own = pull?.merged_at;
|
|
33
|
+
else if (action === "close") own = pull ? pull.closed_at : issue?.finished_at;
|
|
34
|
+
return toDate(own ?? subject?.updated_at ?? payload.head_commit?.timestamp ?? payload.commits?.at(-1)?.timestamp);
|
|
35
|
+
}
|
|
36
|
+
function translateGiteeWebhook(instance, delivery) {
|
|
37
|
+
const payload = JSON.parse(bodyText(delivery.body));
|
|
38
|
+
const hook = payload.hook_name ?? headerValue(delivery.headers, "x-gitee-event") ?? "";
|
|
39
|
+
const rawRepo = payload.repository ?? payload.project;
|
|
40
|
+
const repo = rawRepo ? toRepoRef(instance, rawRepo) : void 0;
|
|
41
|
+
const actor = toActor(instance, payload.sender ?? payload.user ?? payload.comment?.user);
|
|
42
|
+
const who = actor?.login ?? "someone";
|
|
43
|
+
const base = {
|
|
44
|
+
forge: FORGE,
|
|
45
|
+
instance,
|
|
46
|
+
id: headerValue(delivery.headers, "x-gitee-delivery") ?? `${hook}:${payload.timestamp ?? Date.now()}`,
|
|
47
|
+
kindRaw: payload.action ? `${hook}.${payload.action}` : hook,
|
|
48
|
+
...eventTime(giteeTime(hook, payload)),
|
|
49
|
+
actor,
|
|
50
|
+
repo,
|
|
51
|
+
source: "webhook",
|
|
52
|
+
payload
|
|
53
|
+
};
|
|
54
|
+
if (hook === "push_hooks" || hook === "tag_push_hooks" || hook === "Push Hook" || hook === "Tag Push Hook") return [{
|
|
55
|
+
...base,
|
|
56
|
+
...refEvent(who, {
|
|
57
|
+
ref: payload.ref ?? "",
|
|
58
|
+
before: payload.before,
|
|
59
|
+
after: payload.after,
|
|
60
|
+
created: payload.created,
|
|
61
|
+
deleted: payload.deleted,
|
|
62
|
+
commits: (payload.commits ?? []).map((commit) => ({
|
|
63
|
+
sha: commit.id,
|
|
64
|
+
message: commit.message,
|
|
65
|
+
author: commit.author?.username ?? commit.author?.name,
|
|
66
|
+
url: commit.url
|
|
67
|
+
}))
|
|
68
|
+
})
|
|
69
|
+
}];
|
|
70
|
+
const thread = repo && payload.pull_request ? {
|
|
71
|
+
forge: FORGE,
|
|
72
|
+
instance,
|
|
73
|
+
repo,
|
|
74
|
+
kind: "pull_request",
|
|
75
|
+
number: String(payload.pull_request.number)
|
|
76
|
+
} : repo && payload.issue ? {
|
|
77
|
+
forge: FORGE,
|
|
78
|
+
instance,
|
|
79
|
+
repo,
|
|
80
|
+
kind: "issue",
|
|
81
|
+
number: payload.issue.number
|
|
82
|
+
} : void 0;
|
|
83
|
+
const raw = payload.pull_request ?? payload.issue;
|
|
84
|
+
const normalised = thread && (payload.pull_request ? toPullThread(thread, payload.pull_request) : payload.issue && toIssueThread(thread, payload.issue));
|
|
85
|
+
const threadSnapshot = normalised && snapshotOfThread({
|
|
86
|
+
...normalised,
|
|
87
|
+
isDraft: payload.pull_request ? payload.pull_request.draft ?? void 0 : false,
|
|
88
|
+
labels: raw?.labels ? normalised.labels : void 0
|
|
89
|
+
});
|
|
90
|
+
if (hook === "note_hooks" || hook === "Note Hook") {
|
|
91
|
+
const comment = thread && payload.comment ? {
|
|
92
|
+
forge: FORGE,
|
|
93
|
+
instance,
|
|
94
|
+
thread,
|
|
95
|
+
id: String(payload.comment.id)
|
|
96
|
+
} : void 0;
|
|
97
|
+
return [{
|
|
98
|
+
...base,
|
|
99
|
+
kind: "comment",
|
|
100
|
+
thread,
|
|
101
|
+
threadSnapshot,
|
|
102
|
+
detail: {
|
|
103
|
+
type: "comment",
|
|
104
|
+
comment,
|
|
105
|
+
body: payload.comment?.body
|
|
106
|
+
},
|
|
107
|
+
summary: `${who} commented${thread ? ` on ${thread.kind === "issue" ? "" : "!"}${thread.number}` : ""}`
|
|
108
|
+
}];
|
|
109
|
+
}
|
|
110
|
+
const state = STATES[payload.action ?? ""];
|
|
111
|
+
return [{
|
|
112
|
+
...base,
|
|
113
|
+
kind: KINDS[payload.action ?? ""] ?? "other",
|
|
114
|
+
thread,
|
|
115
|
+
threadSnapshot,
|
|
116
|
+
...state ? { detail: {
|
|
117
|
+
type: "state_change",
|
|
118
|
+
state
|
|
119
|
+
} } : {},
|
|
120
|
+
summary: `${who} ${payload.action ?? "changed"} ${thread ? `${thread.kind === "issue" ? "" : "!"}${thread.number}` : hook}`
|
|
121
|
+
}];
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { translateGiteeWebhook };
|