@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,131 @@
|
|
|
1
|
+
import { $ as toDate, _ as WebhookVerificationError } from "./utils-CA_4WJhJ-DNgT61X2.js";
|
|
2
|
+
import { T as headerValue, d as eventTime, i as refEvent, u as eventAction, w as bodyText, x as threadSnapshot } from "./webhooks-DgHwxxYz-D1V2LOr1.js";
|
|
3
|
+
import { n as toActor, t as FORGE } from "./tangled-DPt_0u21-zS41xdG5.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/events-saDWbqbf.mjs
|
|
5
|
+
const EVENT_HEADER = "x-tangled-event";
|
|
6
|
+
const PULL_ACTIONS = {
|
|
7
|
+
created: "opened",
|
|
8
|
+
resubmitted: "synchronised"
|
|
9
|
+
};
|
|
10
|
+
/** A ref that did not exist before the push, or no longer exists after it. */
|
|
11
|
+
const ZERO_SHA = "0000000000000000000000000000000000000000";
|
|
12
|
+
const PULL_STATES = {
|
|
13
|
+
created: "open",
|
|
14
|
+
reopened: "open",
|
|
15
|
+
merged: "merged",
|
|
16
|
+
closed: "closed"
|
|
17
|
+
};
|
|
18
|
+
const PULL_KINDS = {
|
|
19
|
+
created: "state_change",
|
|
20
|
+
merged: "state_change",
|
|
21
|
+
closed: "state_change",
|
|
22
|
+
reopened: "state_change",
|
|
23
|
+
resubmitted: "commit"
|
|
24
|
+
};
|
|
25
|
+
function translateTangledWebhook(instance, delivery, webUrl) {
|
|
26
|
+
const event = headerValue(delivery.headers, EVENT_HEADER);
|
|
27
|
+
if (!event) throw new WebhookVerificationError(`Missing ${EVENT_HEADER} header`, {
|
|
28
|
+
forge: FORGE,
|
|
29
|
+
instance
|
|
30
|
+
});
|
|
31
|
+
const deliveryId = headerValue(delivery.headers, "x-tangled-delivery") ?? crypto.randomUUID();
|
|
32
|
+
const payload = JSON.parse(bodyText(delivery.body));
|
|
33
|
+
const ownerDid = payload.repository?.owner?.did ?? payload.repository?.full_name?.split("/")[0];
|
|
34
|
+
const repo = payload.repository && ownerDid ? {
|
|
35
|
+
forge: FORGE,
|
|
36
|
+
instance,
|
|
37
|
+
owner: ownerDid,
|
|
38
|
+
name: payload.repository.name
|
|
39
|
+
} : void 0;
|
|
40
|
+
const actorDid = payload.sender?.did ?? payload.pusher?.did;
|
|
41
|
+
const actor = actorDid ? {
|
|
42
|
+
forge: FORGE,
|
|
43
|
+
instance,
|
|
44
|
+
login: actorDid,
|
|
45
|
+
id: actorDid,
|
|
46
|
+
url: `${webUrl}/${actorDid}`,
|
|
47
|
+
isBotHint: false
|
|
48
|
+
} : void 0;
|
|
49
|
+
const who = actor?.login ?? "someone";
|
|
50
|
+
if (event.startsWith("pull_request:") && payload.pull_request) {
|
|
51
|
+
const action = payload.action ?? event.slice(13);
|
|
52
|
+
const pull = payload.pull_request;
|
|
53
|
+
const state = pull.state === "open" || pull.state === "closed" || pull.state === "merged" ? pull.state : void 0;
|
|
54
|
+
return [{
|
|
55
|
+
forge: FORGE,
|
|
56
|
+
instance,
|
|
57
|
+
id: deliveryId,
|
|
58
|
+
kind: PULL_KINDS[action] ?? "other",
|
|
59
|
+
...PULL_STATES[action] ? { detail: {
|
|
60
|
+
type: "state_change",
|
|
61
|
+
state: PULL_STATES[action]
|
|
62
|
+
} } : {},
|
|
63
|
+
kindRaw: event,
|
|
64
|
+
action: PULL_ACTIONS[action] ?? eventAction(action),
|
|
65
|
+
actionRaw: action,
|
|
66
|
+
summary: `${who} ${action === "resubmitted" ? "pushed a new round to" : action} pull request #${payload.pull_request.number}`,
|
|
67
|
+
...eventTime(action === "created" ? toDate(payload.pull_request.created_at) : void 0),
|
|
68
|
+
actor,
|
|
69
|
+
repo,
|
|
70
|
+
thread: repo ? {
|
|
71
|
+
forge: FORGE,
|
|
72
|
+
instance,
|
|
73
|
+
repo,
|
|
74
|
+
kind: "pull_request",
|
|
75
|
+
typeRaw: "sh.tangled.repo.pull",
|
|
76
|
+
displayNumber: String(payload.pull_request.number)
|
|
77
|
+
} : void 0,
|
|
78
|
+
threadSnapshot: threadSnapshot({
|
|
79
|
+
title: pull.title,
|
|
80
|
+
body: pull.body,
|
|
81
|
+
state,
|
|
82
|
+
stateRaw: pull.state,
|
|
83
|
+
author: pull.owner && toActor(instance, { did: pull.owner.did }, webUrl),
|
|
84
|
+
url: pull.html_url,
|
|
85
|
+
branches: pull.target_branch && pull.source?.branch ? {
|
|
86
|
+
head: {
|
|
87
|
+
ref: pull.source.branch,
|
|
88
|
+
sha: pull.source.sha
|
|
89
|
+
},
|
|
90
|
+
base: { ref: pull.target_branch }
|
|
91
|
+
} : void 0
|
|
92
|
+
}),
|
|
93
|
+
source: "webhook",
|
|
94
|
+
payload
|
|
95
|
+
}];
|
|
96
|
+
}
|
|
97
|
+
const base = {
|
|
98
|
+
forge: FORGE,
|
|
99
|
+
instance,
|
|
100
|
+
id: deliveryId,
|
|
101
|
+
kindRaw: event,
|
|
102
|
+
occurredAt: /* @__PURE__ */ new Date(),
|
|
103
|
+
undated: true,
|
|
104
|
+
actor,
|
|
105
|
+
repo,
|
|
106
|
+
source: "webhook",
|
|
107
|
+
payload
|
|
108
|
+
};
|
|
109
|
+
if (event === "push" && payload.ref) return [{
|
|
110
|
+
...base,
|
|
111
|
+
...refEvent(who, {
|
|
112
|
+
ref: payload.ref,
|
|
113
|
+
before: payload.before,
|
|
114
|
+
after: payload.after,
|
|
115
|
+
created: payload.before === ZERO_SHA,
|
|
116
|
+
deleted: payload.after === ZERO_SHA,
|
|
117
|
+
commits: (payload.commits ?? []).map((commit) => ({
|
|
118
|
+
sha: commit.sha ?? commit.id ?? "",
|
|
119
|
+
message: commit.message,
|
|
120
|
+
author: commit.author?.did ?? commit.author?.name
|
|
121
|
+
}))
|
|
122
|
+
})
|
|
123
|
+
}];
|
|
124
|
+
return [{
|
|
125
|
+
...base,
|
|
126
|
+
kind: "other",
|
|
127
|
+
summary: `${who} ${event}`
|
|
128
|
+
}];
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { translateTangledWebhook };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { $ as toDate } from "./utils-CA_4WJhJ-DNgT61X2.js";
|
|
2
|
+
import { d as eventTime, i as refEvent, u as eventAction } from "./webhooks-DgHwxxYz-D1V2LOr1.js";
|
|
3
|
+
import { a as toRepoRef, n as toActor, 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/feed-CmBoYS3Z.mjs
|
|
5
|
+
/** Summaries of the feed event types that have no shared kind. */
|
|
6
|
+
const FEED_SUMMARIES = { WatchEvent: "watched the repository" };
|
|
7
|
+
const THREAD_TYPES = {
|
|
8
|
+
IssueEvent: "issue",
|
|
9
|
+
IssueCommentEvent: "issue",
|
|
10
|
+
PullRequestEvent: "pull_request",
|
|
11
|
+
PullRequestCommentEvent: "pull_request"
|
|
12
|
+
};
|
|
13
|
+
function feedLevel(instance, raw, repo, who) {
|
|
14
|
+
const type = raw.type ?? "Event";
|
|
15
|
+
const payload = raw.payload ?? {};
|
|
16
|
+
switch (type) {
|
|
17
|
+
case "PushEvent": return refEvent(who, {
|
|
18
|
+
ref: payload.ref ?? "",
|
|
19
|
+
before: payload.before,
|
|
20
|
+
after: payload.after,
|
|
21
|
+
created: payload.created,
|
|
22
|
+
deleted: payload.deleted,
|
|
23
|
+
commits: payload.commits?.map((commit) => ({
|
|
24
|
+
sha: commit.sha,
|
|
25
|
+
message: commit.message,
|
|
26
|
+
author: commit.author?.name,
|
|
27
|
+
url: commit.url
|
|
28
|
+
})),
|
|
29
|
+
commitCount: payload.size
|
|
30
|
+
});
|
|
31
|
+
case "CreateEvent":
|
|
32
|
+
case "DeleteEvent": {
|
|
33
|
+
const action = type === "CreateEvent" ? "created" : "deleted";
|
|
34
|
+
return {
|
|
35
|
+
kind: "ref",
|
|
36
|
+
action,
|
|
37
|
+
detail: {
|
|
38
|
+
type: "ref",
|
|
39
|
+
ref: payload.ref ?? "",
|
|
40
|
+
refType: payload.ref_type ?? "branch"
|
|
41
|
+
},
|
|
42
|
+
summary: `${who} ${action} ${payload.ref_type ?? "ref"} ${payload.ref ?? ""}`.trim()
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
case "StarEvent": return {
|
|
46
|
+
kind: "star",
|
|
47
|
+
action: "created",
|
|
48
|
+
summary: `${who} starred the repository`
|
|
49
|
+
};
|
|
50
|
+
case "ForkEvent": return {
|
|
51
|
+
kind: "fork",
|
|
52
|
+
action: "created",
|
|
53
|
+
summary: `${who} forked the repository`
|
|
54
|
+
};
|
|
55
|
+
case "MemberEvent": return {
|
|
56
|
+
kind: "membership",
|
|
57
|
+
action: payload.action === "deleted" ? "removed" : eventAction(payload.action) ?? "other",
|
|
58
|
+
detail: {
|
|
59
|
+
type: "membership",
|
|
60
|
+
actionRaw: payload.action ?? "member",
|
|
61
|
+
member: payload.login ? toActor(instance, {
|
|
62
|
+
id: payload.id ?? 0,
|
|
63
|
+
login: payload.login,
|
|
64
|
+
name: payload.name
|
|
65
|
+
}) : void 0
|
|
66
|
+
},
|
|
67
|
+
summary: `${who} ${payload.action ?? "changed"} member ${payload.login ?? ""}`.trim()
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const kind = THREAD_TYPES[type];
|
|
71
|
+
const number = type === "IssueEvent" || type === "PullRequestEvent" ? payload.number : (payload.pull_request ?? payload.issue)?.number;
|
|
72
|
+
const thread = repo && kind && number !== void 0 ? {
|
|
73
|
+
forge: FORGE,
|
|
74
|
+
instance,
|
|
75
|
+
repo,
|
|
76
|
+
kind,
|
|
77
|
+
number: String(number)
|
|
78
|
+
} : void 0;
|
|
79
|
+
const mention = thread ? ` ${kind === "issue" ? "" : "!"}${thread.number}` : "";
|
|
80
|
+
if (type === "IssueCommentEvent" || type === "PullRequestCommentEvent") return {
|
|
81
|
+
kind: "comment",
|
|
82
|
+
action: "created",
|
|
83
|
+
thread,
|
|
84
|
+
detail: {
|
|
85
|
+
type: "comment",
|
|
86
|
+
comment: thread && payload.comment ? {
|
|
87
|
+
forge: FORGE,
|
|
88
|
+
instance,
|
|
89
|
+
thread,
|
|
90
|
+
id: String(payload.comment.id)
|
|
91
|
+
} : void 0,
|
|
92
|
+
body: payload.comment?.body
|
|
93
|
+
},
|
|
94
|
+
summary: `${who} commented${mention && ` on${mention}`}`
|
|
95
|
+
};
|
|
96
|
+
const action = eventAction(payload.action);
|
|
97
|
+
if (thread && (action === "opened" || action === "closed" || action === "reopened" || action === "merged")) return {
|
|
98
|
+
kind: "state_change",
|
|
99
|
+
action,
|
|
100
|
+
thread,
|
|
101
|
+
detail: {
|
|
102
|
+
type: "state_change",
|
|
103
|
+
state: action === "merged" ? "merged" : action === "closed" ? "closed" : "open"
|
|
104
|
+
},
|
|
105
|
+
summary: `${who} ${payload.action}${mention}`
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
kind: "other",
|
|
109
|
+
thread,
|
|
110
|
+
summary: `${who} ${FEED_SUMMARIES[type] ?? `${payload.action ?? ""} ${type}`.trim()}${mention}`
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Normalises an item of a repository's or a user's activity feed. */
|
|
114
|
+
function toFeedEvent(instance, raw) {
|
|
115
|
+
const actor = toActor(instance, raw.actor);
|
|
116
|
+
const repo = raw.repo ? toRepoRef(instance, raw.repo) : void 0;
|
|
117
|
+
const type = raw.type ?? "Event";
|
|
118
|
+
const action = raw.payload?.action;
|
|
119
|
+
return {
|
|
120
|
+
forge: FORGE,
|
|
121
|
+
instance,
|
|
122
|
+
id: raw.id ?? "",
|
|
123
|
+
kindRaw: action ? `${type}.${action}` : type,
|
|
124
|
+
actionRaw: action,
|
|
125
|
+
...feedLevel(instance, raw, repo, actor?.login ?? "someone"),
|
|
126
|
+
...eventTime(toDate(raw.created_at)),
|
|
127
|
+
actor,
|
|
128
|
+
repo,
|
|
129
|
+
source: "poll",
|
|
130
|
+
payload: raw
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
export { toFeedEvent };
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { $ as toDate } from "./utils-CA_4WJhJ-DNgT61X2.js";
|
|
2
|
+
import { d as eventTime, i as refEvent } from "./webhooks-DgHwxxYz-D1V2LOr1.js";
|
|
3
|
+
import { n as toActor, r as toRepoRef } from "./forgejo-BN8ItCfl.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/feed-DsC7Vws1.mjs
|
|
5
|
+
/** Activity types about an issue or a pull request, whose `content` starts with its number. */
|
|
6
|
+
const FEED_THREAD_OPS = {
|
|
7
|
+
create_issue: {
|
|
8
|
+
thread: "issue",
|
|
9
|
+
kind: "state_change",
|
|
10
|
+
action: "opened",
|
|
11
|
+
state: "open",
|
|
12
|
+
titled: true
|
|
13
|
+
},
|
|
14
|
+
close_issue: {
|
|
15
|
+
thread: "issue",
|
|
16
|
+
kind: "state_change",
|
|
17
|
+
action: "closed",
|
|
18
|
+
state: "closed"
|
|
19
|
+
},
|
|
20
|
+
reopen_issue: {
|
|
21
|
+
thread: "issue",
|
|
22
|
+
kind: "state_change",
|
|
23
|
+
action: "reopened",
|
|
24
|
+
state: "open"
|
|
25
|
+
},
|
|
26
|
+
comment_issue: {
|
|
27
|
+
thread: "issue",
|
|
28
|
+
kind: "comment",
|
|
29
|
+
action: "created"
|
|
30
|
+
},
|
|
31
|
+
create_pull_request: {
|
|
32
|
+
thread: "pull_request",
|
|
33
|
+
kind: "state_change",
|
|
34
|
+
action: "opened",
|
|
35
|
+
state: "open",
|
|
36
|
+
titled: true
|
|
37
|
+
},
|
|
38
|
+
close_pull_request: {
|
|
39
|
+
thread: "pull_request",
|
|
40
|
+
kind: "state_change",
|
|
41
|
+
action: "closed",
|
|
42
|
+
state: "closed"
|
|
43
|
+
},
|
|
44
|
+
reopen_pull_request: {
|
|
45
|
+
thread: "pull_request",
|
|
46
|
+
kind: "state_change",
|
|
47
|
+
action: "reopened",
|
|
48
|
+
state: "open"
|
|
49
|
+
},
|
|
50
|
+
merge_pull_request: {
|
|
51
|
+
thread: "pull_request",
|
|
52
|
+
kind: "state_change",
|
|
53
|
+
action: "merged",
|
|
54
|
+
state: "merged",
|
|
55
|
+
titled: true
|
|
56
|
+
},
|
|
57
|
+
auto_merge_pull_request: {
|
|
58
|
+
thread: "pull_request",
|
|
59
|
+
kind: "state_change",
|
|
60
|
+
action: "merged",
|
|
61
|
+
state: "merged",
|
|
62
|
+
titled: true
|
|
63
|
+
},
|
|
64
|
+
pull_request_ready_for_review: {
|
|
65
|
+
thread: "pull_request",
|
|
66
|
+
kind: "state_change",
|
|
67
|
+
action: "ready_for_review",
|
|
68
|
+
state: "open"
|
|
69
|
+
},
|
|
70
|
+
comment_pull: {
|
|
71
|
+
thread: "pull_request",
|
|
72
|
+
kind: "comment",
|
|
73
|
+
action: "created"
|
|
74
|
+
},
|
|
75
|
+
approve_pull_request: {
|
|
76
|
+
thread: "pull_request",
|
|
77
|
+
kind: "review",
|
|
78
|
+
action: "submitted",
|
|
79
|
+
review: "approved"
|
|
80
|
+
},
|
|
81
|
+
reject_pull_request: {
|
|
82
|
+
thread: "pull_request",
|
|
83
|
+
kind: "review",
|
|
84
|
+
action: "submitted",
|
|
85
|
+
review: "changes_requested"
|
|
86
|
+
},
|
|
87
|
+
pull_review_dismissed: {
|
|
88
|
+
thread: "pull_request",
|
|
89
|
+
kind: "review",
|
|
90
|
+
action: "other",
|
|
91
|
+
review: "dismissed"
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/** Splits thread activity `content` into the thread number and its text. */
|
|
95
|
+
function threadContent(content = "") {
|
|
96
|
+
if (content.startsWith("[")) try {
|
|
97
|
+
const [number = "", text = ""] = JSON.parse(content);
|
|
98
|
+
return [String(number), text];
|
|
99
|
+
} catch {
|
|
100
|
+
return ["", content];
|
|
101
|
+
}
|
|
102
|
+
const index = content.indexOf("|");
|
|
103
|
+
return index < 0 ? [content, ""] : [content.slice(0, index), content.slice(index + 1)];
|
|
104
|
+
}
|
|
105
|
+
function pushContent(content) {
|
|
106
|
+
try {
|
|
107
|
+
return content ? JSON.parse(content) : {};
|
|
108
|
+
} catch {
|
|
109
|
+
return {};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function feedLevel(origin, raw, repo, who) {
|
|
113
|
+
const ref = raw.ref_name ?? "";
|
|
114
|
+
const name = ref.replace(/^refs\/(?:heads|tags)\//, "");
|
|
115
|
+
const refType = raw.op_type === "push_tag" || raw.op_type === "delete_tag" || ref.startsWith("refs/tags/") ? "tag" : "branch";
|
|
116
|
+
switch (raw.op_type) {
|
|
117
|
+
case "commit_repo":
|
|
118
|
+
case "mirror_sync_push": {
|
|
119
|
+
const push = pushContent(raw.content);
|
|
120
|
+
return refEvent(who, {
|
|
121
|
+
ref,
|
|
122
|
+
before: /\/compare\/([0-9a-f]+)\.\.\./.exec(push.CompareURL ?? "")?.[1],
|
|
123
|
+
after: push.HeadCommit?.Sha1 ?? push.Commits?.[0]?.Sha1,
|
|
124
|
+
commits: push.Commits?.map((commit) => ({
|
|
125
|
+
sha: commit.Sha1,
|
|
126
|
+
message: commit.Message,
|
|
127
|
+
author: commit.AuthorName
|
|
128
|
+
})),
|
|
129
|
+
commitCount: push.Len
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
case "push_tag":
|
|
133
|
+
case "mirror_sync_create":
|
|
134
|
+
case "delete_tag":
|
|
135
|
+
case "delete_branch":
|
|
136
|
+
case "mirror_sync_delete": {
|
|
137
|
+
const action = raw.op_type === "push_tag" || raw.op_type === "mirror_sync_create" ? "created" : "deleted";
|
|
138
|
+
return {
|
|
139
|
+
kind: "ref",
|
|
140
|
+
action,
|
|
141
|
+
detail: {
|
|
142
|
+
type: "ref",
|
|
143
|
+
ref: name,
|
|
144
|
+
refType
|
|
145
|
+
},
|
|
146
|
+
summary: `${who} ${action} ${refType} ${name}`
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
case "create_repo": return {
|
|
150
|
+
kind: "repo",
|
|
151
|
+
action: "created",
|
|
152
|
+
summary: `${who} created the repository`
|
|
153
|
+
};
|
|
154
|
+
case "rename_repo": return {
|
|
155
|
+
kind: "repo",
|
|
156
|
+
action: "renamed",
|
|
157
|
+
detail: {
|
|
158
|
+
type: "repo_renamed",
|
|
159
|
+
from: raw.content ?? "",
|
|
160
|
+
to: raw.repo?.name ?? ""
|
|
161
|
+
},
|
|
162
|
+
summary: `${who} renamed the repository`
|
|
163
|
+
};
|
|
164
|
+
case "transfer_repo": return {
|
|
165
|
+
kind: "repo",
|
|
166
|
+
action: "transferred",
|
|
167
|
+
detail: {
|
|
168
|
+
type: "repo_transferred",
|
|
169
|
+
fromOwner: raw.content?.split("/")[0],
|
|
170
|
+
toOwner: raw.repo?.owner?.login
|
|
171
|
+
},
|
|
172
|
+
summary: `${who} transferred the repository`
|
|
173
|
+
};
|
|
174
|
+
case "publish_release": return {
|
|
175
|
+
kind: "release",
|
|
176
|
+
action: "published",
|
|
177
|
+
detail: {
|
|
178
|
+
type: "release",
|
|
179
|
+
tag: name || void 0,
|
|
180
|
+
name: raw.content || void 0
|
|
181
|
+
},
|
|
182
|
+
summary: `${who} published ${raw.content || name || "a release"}`
|
|
183
|
+
};
|
|
184
|
+
case "star_repo": return {
|
|
185
|
+
kind: "star",
|
|
186
|
+
action: "created",
|
|
187
|
+
summary: `${who} starred the repository`
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const op = FEED_THREAD_OPS[raw.op_type];
|
|
191
|
+
if (!op) return {
|
|
192
|
+
kind: "other",
|
|
193
|
+
summary: `${who} ${raw.op_type.replaceAll("_", " ")}`
|
|
194
|
+
};
|
|
195
|
+
const [number, text] = threadContent(raw.content);
|
|
196
|
+
const thread = repo && number ? {
|
|
197
|
+
...origin,
|
|
198
|
+
repo,
|
|
199
|
+
kind: op.thread,
|
|
200
|
+
number
|
|
201
|
+
} : void 0;
|
|
202
|
+
const noun = op.thread === "issue" ? "issue" : "pull request";
|
|
203
|
+
const detail = op.kind === "comment" ? {
|
|
204
|
+
type: "comment",
|
|
205
|
+
comment: thread && raw.comment ? {
|
|
206
|
+
...origin,
|
|
207
|
+
thread,
|
|
208
|
+
id: String(raw.comment.id)
|
|
209
|
+
} : void 0,
|
|
210
|
+
body: raw.comment?.body ?? text
|
|
211
|
+
} : op.review ? {
|
|
212
|
+
type: "review",
|
|
213
|
+
state: op.review,
|
|
214
|
+
stateRaw: raw.op_type,
|
|
215
|
+
body: text || void 0
|
|
216
|
+
} : {
|
|
217
|
+
type: "state_change",
|
|
218
|
+
state: op.state
|
|
219
|
+
};
|
|
220
|
+
const summary = op.kind === "comment" ? `${who} commented on ${noun} ${number}` : op.review ? `${who} reviewed ${noun} ${number} (${op.review})` : `${who} ${op.action.replaceAll("_", " ")} ${noun} ${number}`;
|
|
221
|
+
return {
|
|
222
|
+
kind: op.kind,
|
|
223
|
+
action: op.action,
|
|
224
|
+
thread,
|
|
225
|
+
...thread && op.titled && text ? { threadSnapshot: { title: text } } : {},
|
|
226
|
+
detail,
|
|
227
|
+
summary: summary.trim()
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/** Normalises an item of a repository's or a user's activity feed. */
|
|
231
|
+
function toFeedEvent(origin, raw) {
|
|
232
|
+
const actor = toActor(origin, raw.act_user);
|
|
233
|
+
const repo = raw.repo ? toRepoRef(origin, raw.repo) : void 0;
|
|
234
|
+
return {
|
|
235
|
+
...origin,
|
|
236
|
+
id: String(raw.id),
|
|
237
|
+
kindRaw: raw.op_type,
|
|
238
|
+
...feedLevel(origin, raw, repo, actor?.login ?? "someone"),
|
|
239
|
+
...eventTime(toDate(raw.created)),
|
|
240
|
+
actor,
|
|
241
|
+
repo,
|
|
242
|
+
...typeof raw.is_private === "boolean" ? { isPublic: !raw.is_private } : {},
|
|
243
|
+
source: "poll",
|
|
244
|
+
payload: raw
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
export { toFeedEvent };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { $ as toDate } from "./utils-CA_4WJhJ-DNgT61X2.js";
|
|
2
|
+
import { d as eventTime, i as refEvent, u as eventAction } from "./webhooks-DgHwxxYz-D1V2LOr1.js";
|
|
3
|
+
import { n as approvalId, r as toActor, s as toThreadKind, t as FORGE } from "./gitlab-BoDm8-BC.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/feed-Dyf730Ys.mjs
|
|
5
|
+
const FEED_STATES = {
|
|
6
|
+
opened: {
|
|
7
|
+
action: "opened",
|
|
8
|
+
state: "open"
|
|
9
|
+
},
|
|
10
|
+
closed: {
|
|
11
|
+
action: "closed",
|
|
12
|
+
state: "closed"
|
|
13
|
+
},
|
|
14
|
+
reopened: {
|
|
15
|
+
action: "reopened",
|
|
16
|
+
state: "open"
|
|
17
|
+
},
|
|
18
|
+
accepted: {
|
|
19
|
+
action: "merged",
|
|
20
|
+
state: "merged"
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function feedThread(repo, type, number) {
|
|
24
|
+
const kind = toThreadKind(type === "WorkItem" ? "Issue" : type ?? "");
|
|
25
|
+
return repo && kind && number !== null && number !== void 0 ? {
|
|
26
|
+
forge: FORGE,
|
|
27
|
+
instance: repo.instance,
|
|
28
|
+
repo,
|
|
29
|
+
kind,
|
|
30
|
+
number: String(number)
|
|
31
|
+
} : void 0;
|
|
32
|
+
}
|
|
33
|
+
function feedLevel(instance, raw, repo, who) {
|
|
34
|
+
const push = raw.push_data;
|
|
35
|
+
if (push) {
|
|
36
|
+
const tag = push.ref_type === "tag";
|
|
37
|
+
return refEvent(who, {
|
|
38
|
+
ref: `${tag ? "refs/tags/" : "refs/heads/"}${push.ref ?? ""}`,
|
|
39
|
+
refType: tag ? "tag" : "branch",
|
|
40
|
+
before: push.commit_from ?? void 0,
|
|
41
|
+
after: push.commit_to ?? void 0,
|
|
42
|
+
created: push.action === "created",
|
|
43
|
+
deleted: push.action === "removed",
|
|
44
|
+
commits: push.commit_to && push.commit_title ? [{
|
|
45
|
+
sha: push.commit_to,
|
|
46
|
+
message: push.commit_title
|
|
47
|
+
}] : [],
|
|
48
|
+
commitCount: push.commit_count
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const note = raw.note;
|
|
52
|
+
if (note) {
|
|
53
|
+
const kind = note.type === "DiffNote" || note.position ? "review_comment" : "comment";
|
|
54
|
+
if (note.noteable_type === "Commit") {
|
|
55
|
+
const commit = repo && note.commit_id ? {
|
|
56
|
+
forge: FORGE,
|
|
57
|
+
instance: repo.instance,
|
|
58
|
+
repo,
|
|
59
|
+
sha: note.commit_id
|
|
60
|
+
} : void 0;
|
|
61
|
+
return {
|
|
62
|
+
kind: "comment",
|
|
63
|
+
action: "created",
|
|
64
|
+
commit,
|
|
65
|
+
detail: {
|
|
66
|
+
type: "comment",
|
|
67
|
+
comment: commit && {
|
|
68
|
+
forge: "gitlab",
|
|
69
|
+
instance: commit.instance,
|
|
70
|
+
commit,
|
|
71
|
+
id: String(note.id)
|
|
72
|
+
},
|
|
73
|
+
body: note.body
|
|
74
|
+
},
|
|
75
|
+
summary: `${who} commented`
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const thread = feedThread(repo, note.noteable_type, note.noteable_iid);
|
|
79
|
+
return {
|
|
80
|
+
kind,
|
|
81
|
+
action: "created",
|
|
82
|
+
thread,
|
|
83
|
+
detail: {
|
|
84
|
+
type: kind,
|
|
85
|
+
comment: thread && {
|
|
86
|
+
forge: "gitlab",
|
|
87
|
+
instance: thread.instance,
|
|
88
|
+
thread,
|
|
89
|
+
id: String(note.id)
|
|
90
|
+
},
|
|
91
|
+
body: note.body
|
|
92
|
+
},
|
|
93
|
+
summary: `${who} commented`
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const thread = feedThread(repo, raw.target_type, raw.target_iid);
|
|
97
|
+
const noun = thread?.kind === "pull_request" ? "merge request" : "issue";
|
|
98
|
+
const state = FEED_STATES[raw.action_name];
|
|
99
|
+
if (thread && state) return {
|
|
100
|
+
kind: "state_change",
|
|
101
|
+
action: state.action,
|
|
102
|
+
thread,
|
|
103
|
+
detail: {
|
|
104
|
+
type: "state_change",
|
|
105
|
+
state: state.state
|
|
106
|
+
},
|
|
107
|
+
summary: `${who} ${state.action} ${noun}`
|
|
108
|
+
};
|
|
109
|
+
if (thread && raw.action_name === "approved") return {
|
|
110
|
+
kind: "review",
|
|
111
|
+
action: "submitted",
|
|
112
|
+
thread,
|
|
113
|
+
detail: {
|
|
114
|
+
type: "review",
|
|
115
|
+
state: "approved",
|
|
116
|
+
stateRaw: "approved",
|
|
117
|
+
review: {
|
|
118
|
+
forge: FORGE,
|
|
119
|
+
instance: thread.instance,
|
|
120
|
+
thread,
|
|
121
|
+
id: approvalId(raw.author ?? { username: raw.author_username })
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
summary: `${who} approved ${noun}`
|
|
125
|
+
};
|
|
126
|
+
if (raw.target_type === "Project" && (raw.action_name === "joined" || raw.action_name === "left")) return {
|
|
127
|
+
kind: "membership",
|
|
128
|
+
action: raw.action_name === "joined" ? "added" : "removed",
|
|
129
|
+
detail: {
|
|
130
|
+
type: "membership",
|
|
131
|
+
actionRaw: raw.action_name,
|
|
132
|
+
member: toActor(instance, raw.author)
|
|
133
|
+
},
|
|
134
|
+
summary: `${who} ${raw.action_name} the project`
|
|
135
|
+
};
|
|
136
|
+
if (raw.target_type === "Project" && (raw.action_name === "created" || raw.action_name === "deleted" || raw.action_name === "destroyed")) return {
|
|
137
|
+
kind: "repo",
|
|
138
|
+
action: raw.action_name === "created" ? "created" : "deleted",
|
|
139
|
+
summary: `${who} ${raw.action_name} the project`
|
|
140
|
+
};
|
|
141
|
+
if (raw.target_type === "WikiPage::Meta") {
|
|
142
|
+
const action = raw.action_name === "destroyed" ? "deleted" : eventAction(raw.action_name) ?? "other";
|
|
143
|
+
return {
|
|
144
|
+
kind: "wiki",
|
|
145
|
+
action,
|
|
146
|
+
detail: {
|
|
147
|
+
type: "wiki",
|
|
148
|
+
title: raw.target_title ?? void 0
|
|
149
|
+
},
|
|
150
|
+
summary: `${who} ${action} wiki page ${raw.target_title ?? ""}`.trim()
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
kind: "other",
|
|
155
|
+
thread,
|
|
156
|
+
summary: `${who} ${raw.action_name} ${raw.target_type ?? ""}`.trim()
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** Normalises an item of a project's or a user's activity feed; `repo` is the project, where it is known. */
|
|
160
|
+
function toFeedEvent(instance, raw, repo) {
|
|
161
|
+
const actor = toActor(instance, raw.author);
|
|
162
|
+
const level = feedLevel(instance, raw, repo, actor?.login ?? raw.author_username ?? "someone");
|
|
163
|
+
return {
|
|
164
|
+
forge: FORGE,
|
|
165
|
+
instance,
|
|
166
|
+
id: String(raw.id),
|
|
167
|
+
kindRaw: [raw.target_type, raw.action_name].filter(Boolean).join("."),
|
|
168
|
+
actionRaw: raw.action_name,
|
|
169
|
+
...level,
|
|
170
|
+
...level.thread && raw.target_title ? { threadSnapshot: { title: raw.target_title } } : {},
|
|
171
|
+
...eventTime(toDate(raw.created_at)),
|
|
172
|
+
actor,
|
|
173
|
+
repo,
|
|
174
|
+
source: "poll",
|
|
175
|
+
payload: raw
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
export { toFeedEvent };
|