@vite-hub/forge 0.0.0 → 0.3.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 +115 -0
- package/dist/association-Ds6Tgs0W-Cu9_YCGq.js +19 -0
- package/dist/build/node.d.ts +12 -0
- package/dist/build/node.js +106 -0
- package/dist/build.d.ts +2 -0
- package/dist/build.js +2 -0
- package/dist/events-C6C7lk1x-J8VCAjEX.js +131 -0
- package/dist/events-DW3SFUDA-D2rhS9D-.js +124 -0
- package/dist/events-DjRw3KSr-C72gY7Vu.js +527 -0
- package/dist/events-DmSWTdpS-BdJBABfI.js +214 -0
- package/dist/events-uCMi3LHU-Bz79PQtq.js +354 -0
- package/dist/feed-BlzdKdNv-DbxuSgsx.js +179 -0
- package/dist/feed-BwdcTgZq-Bm_c8br8.js +248 -0
- package/dist/feed-CIaAZINm-Dpe9DxwK.js +134 -0
- package/dist/forgejo-UNPc42cY.js +2324 -0
- package/dist/gitee-BXyl2_3W-dQOAjWqr.js +113 -0
- package/dist/github-CUiEF2FK.js +4186 -0
- package/dist/gitlab-zvWb9zOi.js +2589 -0
- package/dist/graphql-BDhuP5jN-BSpB8lWf.js +541 -0
- package/dist/identity-CNTWZZuv.d.ts +27 -0
- package/dist/identity-CmVEBLP5.js +38 -0
- package/dist/index.d.ts +4140 -0
- package/dist/index.js +1183 -0
- package/dist/knot-bGebBK_B-CeDHcJUz.js +350 -0
- package/dist/tangled-8lg_73Wi-bSufNXiN.js +43 -0
- package/dist/templates-BGDqQMu4-PSB43E1j.js +125 -0
- package/dist/utils-DC7MBR65-B7Vr2hFm.js +1214 -0
- package/dist/webhooks-Bc6QhmI8-CNgCERCq.js +1890 -0
- package/package.json +67 -4
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { $ as toDate, _ as WebhookVerificationError } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { _ as reviewState, d as eventTime, i as refEvent, k as bodyText, n as firstHeader, u as eventAction, v as snapshotOfThread } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { i as toThread, n as toActor, r as toRepoRef, t as FORGEJO_HEADERS } from "./forgejo-UNPc42cY.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/events-DmSWTdpS.mjs
|
|
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 };
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { $ as toDate, _ as WebhookVerificationError } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
+
import { A as headerValue, d as eventTime, i as refEvent, k as bodyText, u as eventAction, x as threadSnapshot } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
+
import { a as toRepoRef, i as toLabel, n as approvalId, o as toState, r as toActor, t as FORGE } from "./gitlab-zvWb9zOi.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/events-uCMi3LHU.mjs
|
|
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 };
|