@vite-hub/forge 0.5.0 → 0.6.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/dist/{association-Ds6Tgs0W-Cu9_YCGq.js → association-Ds6Tgs0W-CgBVH3ii.js} +1 -2
- package/dist/build/node.d.ts +1 -3
- package/dist/build/node.js +3 -5
- package/dist/build.d.ts +1 -1
- package/dist/build.js +1 -2
- package/dist/{definition-0wjaAw2i-BwSDtp9h.js → definition-BQFdu9ti-WxMjcAEl.js} +8 -8
- package/dist/{events-DW3SFUDA-D2rhS9D-.js → events-BL0zcgMf-9TwyYtCt.js} +3 -5
- package/dist/{events-uCMi3LHU-Bz79PQtq.js → events-DDdJnmD2-BSMoOqjV.js} +4 -5
- package/dist/{events-DjRw3KSr-C72gY7Vu.js → events-DHqSJ5KI-z2-5_1vo.js} +59 -60
- package/dist/{events-DmSWTdpS-oDiTlP1L.js → events-DXE-Ul2S-BzTkugIK.js} +4 -5
- package/dist/{feed-BlzdKdNv-DbxuSgsx.js → feed-B1OiHFg0-DevZZe0y.js} +3 -5
- package/dist/{feed-CIaAZINm-Dpe9DxwK.js → feed-DROLF1tb-CtRfA_7N.js} +3 -5
- package/dist/{feed-BwdcTgZq-CbyczJHA.js → feed-iWegqepj-ConxMpg4.js} +3 -5
- package/dist/{forgejo-DgNfNjcW.js → forgejo-4sbZukng.js} +3 -4
- package/dist/{gitea-Zpwj_XHC.js → gitea-Cj7qy2X3.js} +3 -4
- package/dist/{gitee-BXyl2_3W-dQOAjWqr.js → gitee-CKt4pEC0-BuLWggck.js} +2 -3
- package/dist/{github-CUiEF2FK.js → github-CHzhqYOr.js} +377 -293
- package/dist/{gitlab-zvWb9zOi.js → gitlab-CS0shW2u.js} +12 -10
- package/dist/{graphql-BDhuP5jN-BSpB8lWf.js → graphql-DxRA9BGO-BBbmTmWi.js} +43 -33
- package/dist/{identity-CmVEBLP5.js → identity-BwC2_3S9.js} +1 -2
- package/dist/{identity-CNTWZZuv.d.ts → identity-D2-HaDku.d.ts} +0 -2
- package/dist/index.d.ts +35 -38
- package/dist/index.js +26 -45
- package/dist/model-Biiu1CfI-CVLamGai.js +288 -0
- package/dist/{templates-BGDqQMu4-PSB43E1j.js → templates-0m5QBVIh-D1fZeoC-.js} +3 -3
- package/dist/{webhooks-Bc6QhmI8-CNgCERCq.js → webhooks-Bc6QhmI8-eK71_mJE.js} +1034 -98
- package/package.json +6 -6
- package/dist/events-C6C7lk1x-J8VCAjEX.js +0 -131
- package/dist/knot-bGebBK_B-CeDHcJUz.js +0 -350
- package/dist/tangled-8lg_73Wi-bSufNXiN.js +0 -43
- package/dist/utils-DC7MBR65-B7Vr2hFm.js +0 -1214
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/forge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "One Forge identity for ViteHub apps: GitHub App installation tokens and GitHub, GitLab, Forgejo and Gitea providers from one set of env names.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"forge",
|
|
@@ -47,17 +47,17 @@
|
|
|
47
47
|
"./package.json": "./package.json"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@vite-hub/runtime": "0.
|
|
50
|
+
"@vite-hub/runtime": "0.6.0",
|
|
51
51
|
"nostics": "1.4.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@types/node": "^24.19.
|
|
54
|
+
"@types/node": "^24.19.2",
|
|
55
55
|
"@vite-hub/internal": "0.0.1",
|
|
56
|
-
"forges": "0.
|
|
56
|
+
"forges": "0.4.1",
|
|
57
57
|
"publint": "^0.3.25",
|
|
58
58
|
"typescript": "^6.0.3",
|
|
59
|
-
"vite-plus": "^
|
|
60
|
-
"vitest": "
|
|
59
|
+
"vite-plus": "^1.7.0",
|
|
60
|
+
"vitest": "5.1.0"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=24.15.0"
|
|
@@ -1,131 +0,0 @@
|
|
|
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 { n as toActor, t as FORGE } from "./tangled-8lg_73Wi-bSufNXiN.js";
|
|
4
|
-
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/events-C6C7lk1x.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 };
|
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
import { $ as toDate, d as NotFoundError, g as UnsupportedOperationError, tt as toMergeError } from "./utils-DC7MBR65-B7Vr2hFm.js";
|
|
2
|
-
import { S as toFileContent, p as fromBase64 } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
|
|
3
|
-
import { t as FORGE } from "./tangled-8lg_73Wi-bSufNXiN.js";
|
|
4
|
-
String.raw`[\w:.-]+\/[\w.-]+`;
|
|
5
|
-
/**
|
|
6
|
-
* The path of a repository's page. Tangled addresses a repository by its
|
|
7
|
-
* owner's handle, and redirects a path that names the owner's DID.
|
|
8
|
-
*/
|
|
9
|
-
const repoPath = (repo) => `/${encodeURIComponent(repo.ownerHandle ?? repo.owner).replaceAll("%3A", ":")}/${encodeURIComponent(repo.name)}`;
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/knot-bGebBK_B.mjs
|
|
12
|
-
const DEFAULT_PAGE = 30;
|
|
13
|
-
const TREE_TYPES = {
|
|
14
|
-
"0040000": "directory",
|
|
15
|
-
"0120000": "symlink",
|
|
16
|
-
"0160000": "submodule"
|
|
17
|
-
};
|
|
18
|
-
function hex(hash) {
|
|
19
|
-
if (typeof hash === "string" || hash === void 0) return hash ?? "";
|
|
20
|
-
return hash.map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
21
|
-
}
|
|
22
|
-
function signature({ Name, Email, When }) {
|
|
23
|
-
return {
|
|
24
|
-
name: Name,
|
|
25
|
-
email: Email,
|
|
26
|
-
date: toDate(When)
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function fragmentPatch(fragments) {
|
|
30
|
-
return fragments.map((fragment) => {
|
|
31
|
-
return `@@ -${fragment.OldPosition},${fragment.OldLines} +${fragment.NewPosition},${fragment.NewLines} @@${fragment.Comment ? ` ${fragment.Comment}` : ""}\n` + (fragment.Lines ?? []).map((line) => `${line.Op === 1 ? "-" : line.Op === 2 ? "+" : " "}${line.Line}`).join("");
|
|
32
|
-
}).join("");
|
|
33
|
-
}
|
|
34
|
-
function changedFile(file) {
|
|
35
|
-
const fragments = file.fragments ?? [];
|
|
36
|
-
const status = file.isNew ? "added" : file.isDelete ? "removed" : file.isRename ? "renamed" : file.isCopy ? "copied" : "modified";
|
|
37
|
-
return {
|
|
38
|
-
path: file.isDelete ? file.oldName : file.newName,
|
|
39
|
-
previousPath: file.isRename || file.isCopy ? file.oldName : void 0,
|
|
40
|
-
status,
|
|
41
|
-
additions: fragments.reduce((sum, fragment) => sum + fragment.LinesAdded, 0),
|
|
42
|
-
deletions: fragments.reduce((sum, fragment) => sum + fragment.LinesDeleted, 0),
|
|
43
|
-
patch: file.isBinary || !fragments.length ? void 0 : fragmentPatch(fragments),
|
|
44
|
-
sha: file.sha || void 0,
|
|
45
|
-
isBinary: file.isBinary || void 0
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const fromDiff = (file) => changedFile({
|
|
49
|
-
oldName: file.name.old,
|
|
50
|
-
newName: file.name.new,
|
|
51
|
-
isNew: file.is_new,
|
|
52
|
-
isDelete: file.is_delete,
|
|
53
|
-
isCopy: file.is_copy,
|
|
54
|
-
isRename: file.is_rename,
|
|
55
|
-
isBinary: file.is_binary,
|
|
56
|
-
fragments: file.text_fragments
|
|
57
|
-
});
|
|
58
|
-
const fromPatch = (file) => changedFile({
|
|
59
|
-
oldName: file.OldName,
|
|
60
|
-
newName: file.NewName,
|
|
61
|
-
isNew: file.IsNew,
|
|
62
|
-
isDelete: file.IsDelete,
|
|
63
|
-
isCopy: file.IsCopy,
|
|
64
|
-
isRename: file.IsRename,
|
|
65
|
-
isBinary: file.IsBinary,
|
|
66
|
-
sha: file.NewOIDPrefix,
|
|
67
|
-
fragments: file.TextFragments
|
|
68
|
-
});
|
|
69
|
-
function stats(files) {
|
|
70
|
-
const additions = files.reduce((sum, file) => sum + (file.additions ?? 0), 0);
|
|
71
|
-
const deletions = files.reduce((sum, file) => sum + (file.deletions ?? 0), 0);
|
|
72
|
-
return {
|
|
73
|
-
additions,
|
|
74
|
-
deletions,
|
|
75
|
-
total: additions + deletions
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/** Offset pagination, as knots page branches, tags and commits. */
|
|
79
|
-
function offsetPage(items, offset, limit) {
|
|
80
|
-
return {
|
|
81
|
-
items,
|
|
82
|
-
cursor: items.length >= limit ? { token: String(offset + items.length) } : void 0
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function offsetOf(options) {
|
|
86
|
-
const offset = Number(options.cursor?.token ?? 0);
|
|
87
|
-
return Number.isInteger(offset) && offset > 0 ? offset : 0;
|
|
88
|
-
}
|
|
89
|
-
/** Reads git contents from the knot named in each repo record. */
|
|
90
|
-
function createTangledContents({ fetcher, instance, webUrl, context, canonicalRepo, serviceAuth }) {
|
|
91
|
-
async function knotFor(repo, signal) {
|
|
92
|
-
const { ref, record } = await canonicalRepo(repo, signal);
|
|
93
|
-
const { knot, repoDid, name } = record.value;
|
|
94
|
-
const origin = /^https?:\/\//.test(knot) ? knot.replace(/\/$/, "") : `https://${knot}`;
|
|
95
|
-
return {
|
|
96
|
-
ref: repoDid ? {
|
|
97
|
-
...ref,
|
|
98
|
-
externalId: repoDid
|
|
99
|
-
} : ref,
|
|
100
|
-
record,
|
|
101
|
-
repo: repoDid ?? `${ref.owner}/${name ?? ref.name}`,
|
|
102
|
-
call: async (nsid, query) => (await fetcher.json(`${origin}/xrpc/${nsid}`, {
|
|
103
|
-
query,
|
|
104
|
-
signal
|
|
105
|
-
})).data,
|
|
106
|
-
/** Calls a knot procedure as the signed-in account. */
|
|
107
|
-
post: async (nsid, json, mapError) => {
|
|
108
|
-
const token = await serviceAuth(`did:web:${encodeURIComponent(new URL(origin).host)}`, nsid, signal);
|
|
109
|
-
await fetcher.raw(`${origin}/xrpc/${nsid}`, {
|
|
110
|
-
method: "POST",
|
|
111
|
-
json,
|
|
112
|
-
headers: { authorization: `Bearer ${token}` },
|
|
113
|
-
mapError,
|
|
114
|
-
signal
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
const pageUrl = (repo, section, ref, path) => `${webUrl}${repoPath(repo)}/${section}/${encodeURIComponent(ref ?? "HEAD")}/${path.split("/").map(encodeURIComponent).join("/")}`;
|
|
120
|
-
function toCommit(repo, raw, files) {
|
|
121
|
-
const sha = raw.this ?? hex(raw.hash);
|
|
122
|
-
return {
|
|
123
|
-
ref: {
|
|
124
|
-
forge: FORGE,
|
|
125
|
-
instance,
|
|
126
|
-
repo,
|
|
127
|
-
sha
|
|
128
|
-
},
|
|
129
|
-
sha,
|
|
130
|
-
message: raw.message,
|
|
131
|
-
author: raw.author && signature(raw.author),
|
|
132
|
-
committer: raw.committer && signature(raw.committer),
|
|
133
|
-
parents: (raw.parent_hashes ?? []).map(hex),
|
|
134
|
-
url: `${webUrl}${repoPath(repo)}/commit/${sha}`,
|
|
135
|
-
...files ? {
|
|
136
|
-
files,
|
|
137
|
-
stats: stats(files)
|
|
138
|
-
} : {},
|
|
139
|
-
raw
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function fromHeader(repo, header) {
|
|
143
|
-
const files = (header.Files ?? []).map(fromPatch);
|
|
144
|
-
const author = header.Author && {
|
|
145
|
-
...signature(header.Author),
|
|
146
|
-
date: toDate(header.AuthorDate)
|
|
147
|
-
};
|
|
148
|
-
const committer = header.Committer && {
|
|
149
|
-
...signature(header.Committer),
|
|
150
|
-
date: toDate(header.CommitterDate)
|
|
151
|
-
};
|
|
152
|
-
return {
|
|
153
|
-
ref: {
|
|
154
|
-
forge: FORGE,
|
|
155
|
-
instance,
|
|
156
|
-
repo,
|
|
157
|
-
sha: header.SHA
|
|
158
|
-
},
|
|
159
|
-
sha: header.SHA,
|
|
160
|
-
message: header.Body ? `${header.Title}\n\n${header.Body}` : header.Title,
|
|
161
|
-
author: author || void 0,
|
|
162
|
-
committer: committer || void 0,
|
|
163
|
-
parents: [],
|
|
164
|
-
url: `${webUrl}${repoPath(repo)}/commit/${header.SHA}`,
|
|
165
|
-
files,
|
|
166
|
-
stats: stats(files),
|
|
167
|
-
raw: {
|
|
168
|
-
...header,
|
|
169
|
-
Files: void 0
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
async defaultBranch(repo, signal) {
|
|
175
|
-
const knot = await knotFor(repo, signal);
|
|
176
|
-
return (await knot.call("sh.tangled.repo.getDefaultBranch", { repo: knot.repo })).name || void 0;
|
|
177
|
-
},
|
|
178
|
-
async file(repo, path, options = {}) {
|
|
179
|
-
const knot = await knotFor(repo, options.signal);
|
|
180
|
-
const blob = await knot.call("sh.tangled.repo.blob", {
|
|
181
|
-
repo: knot.repo,
|
|
182
|
-
ref: options.ref,
|
|
183
|
-
path
|
|
184
|
-
});
|
|
185
|
-
if (blob.submodule || blob.content === void 0) throw new NotFoundError(`${path} is a submodule, not a file`, 404, "", context);
|
|
186
|
-
const bytes = blob.encoding === "base64" ? fromBase64(blob.content) : new TextEncoder().encode(blob.content);
|
|
187
|
-
return toFileContent(bytes, {
|
|
188
|
-
path,
|
|
189
|
-
size: blob.size,
|
|
190
|
-
url: pageUrl(knot.ref, "blob", options.ref, path)
|
|
191
|
-
}, options, context);
|
|
192
|
-
},
|
|
193
|
-
async treePage(repo, options = {}) {
|
|
194
|
-
const knot = await knotFor(repo, options.signal);
|
|
195
|
-
const parent = options.path?.replace(/^\/|\/$/g, "") ?? "";
|
|
196
|
-
const items = ((await knot.call("sh.tangled.repo.tree", {
|
|
197
|
-
repo: knot.repo,
|
|
198
|
-
ref: options.ref,
|
|
199
|
-
path: parent || void 0
|
|
200
|
-
})).files ?? []).map((entry) => {
|
|
201
|
-
const path = parent ? `${parent}/${entry.name}` : entry.name;
|
|
202
|
-
const type = TREE_TYPES[entry.mode] ?? "file";
|
|
203
|
-
return {
|
|
204
|
-
path,
|
|
205
|
-
type,
|
|
206
|
-
size: type === "file" ? entry.size : void 0,
|
|
207
|
-
mode: entry.mode.replace(/^0+(?=\d{6}$)/, ""),
|
|
208
|
-
url: pageUrl(knot.ref, type === "directory" ? "tree" : "blob", options.ref, path)
|
|
209
|
-
};
|
|
210
|
-
});
|
|
211
|
-
const warnings = options.recursive ? [{
|
|
212
|
-
code: "recursive_unsupported",
|
|
213
|
-
message: "Knots list one level of a tree; read subdirectories separately"
|
|
214
|
-
}] : [];
|
|
215
|
-
return warnings.length ? {
|
|
216
|
-
items,
|
|
217
|
-
warnings
|
|
218
|
-
} : { items };
|
|
219
|
-
},
|
|
220
|
-
async branchesPage(repo, options = {}) {
|
|
221
|
-
const knot = await knotFor(repo, options.signal);
|
|
222
|
-
const offset = offsetOf(options);
|
|
223
|
-
const limit = Math.min(options.perPage ?? DEFAULT_PAGE, 100);
|
|
224
|
-
return offsetPage(((await knot.call("sh.tangled.repo.branches", {
|
|
225
|
-
repo: knot.repo,
|
|
226
|
-
limit,
|
|
227
|
-
cursor: offset || void 0
|
|
228
|
-
})).branches ?? []).map((branch) => ({
|
|
229
|
-
name: branch.reference.name,
|
|
230
|
-
sha: branch.reference.hash,
|
|
231
|
-
isDefault: branch.is_default ?? false,
|
|
232
|
-
url: `${webUrl}${repoPath(knot.ref)}/tree/${encodeURIComponent(branch.reference.name)}`,
|
|
233
|
-
raw: {
|
|
234
|
-
...branch,
|
|
235
|
-
commit: void 0
|
|
236
|
-
}
|
|
237
|
-
})), offset, limit);
|
|
238
|
-
},
|
|
239
|
-
async tagsPage(repo, options = {}) {
|
|
240
|
-
const knot = await knotFor(repo, options.signal);
|
|
241
|
-
const offset = offsetOf(options);
|
|
242
|
-
const limit = Math.min(options.perPage ?? DEFAULT_PAGE, 100);
|
|
243
|
-
return offsetPage(((await knot.call("sh.tangled.repo.tags", {
|
|
244
|
-
repo: knot.repo,
|
|
245
|
-
limit,
|
|
246
|
-
cursor: offset || void 0
|
|
247
|
-
})).tags ?? []).map((tag) => ({
|
|
248
|
-
name: tag.name,
|
|
249
|
-
sha: tag.tag ? hex(tag.tag.Target) : tag.hash,
|
|
250
|
-
url: `${webUrl}${repoPath(knot.ref)}/tree/${encodeURIComponent(tag.name)}`,
|
|
251
|
-
raw: tag
|
|
252
|
-
})), offset, limit);
|
|
253
|
-
},
|
|
254
|
-
async resolveRef(repo, ref, options = {}) {
|
|
255
|
-
const knot = await knotFor(repo, options.signal);
|
|
256
|
-
const commit = (await knot.call("sh.tangled.repo.log", {
|
|
257
|
-
repo: knot.repo,
|
|
258
|
-
ref,
|
|
259
|
-
limit: 1
|
|
260
|
-
})).commits?.[0];
|
|
261
|
-
if (!commit) throw new NotFoundError(`No commit at ${ref}`, 404, "", context);
|
|
262
|
-
return commit.this ?? hex(commit.hash);
|
|
263
|
-
},
|
|
264
|
-
async commitsPage(repo, query = {}) {
|
|
265
|
-
const knot = await knotFor(repo, query.signal);
|
|
266
|
-
const offset = offsetOf(query);
|
|
267
|
-
const limit = query.perPage ?? DEFAULT_PAGE;
|
|
268
|
-
const page = offsetPage(((await knot.call("sh.tangled.repo.log", {
|
|
269
|
-
repo: knot.repo,
|
|
270
|
-
ref: query.ref,
|
|
271
|
-
limit,
|
|
272
|
-
cursor: offset || void 0
|
|
273
|
-
})).commits ?? []).map((commit) => toCommit(knot.ref, commit)), offset, limit);
|
|
274
|
-
const ignored = [
|
|
275
|
-
"path",
|
|
276
|
-
"author",
|
|
277
|
-
"since",
|
|
278
|
-
"until"
|
|
279
|
-
].filter((key) => query[key] !== void 0);
|
|
280
|
-
return ignored.length && !offset ? {
|
|
281
|
-
...page,
|
|
282
|
-
warnings: [{
|
|
283
|
-
code: "filter_unsupported",
|
|
284
|
-
message: `Knots do not filter commits by ${ignored.join(", ")}; those filters were ignored`
|
|
285
|
-
}]
|
|
286
|
-
} : page;
|
|
287
|
-
},
|
|
288
|
-
async commit(repo, sha, options = {}) {
|
|
289
|
-
const knot = await knotFor(repo, options.signal);
|
|
290
|
-
const { diff } = await knot.call("sh.tangled.repo.diff", {
|
|
291
|
-
repo: knot.repo,
|
|
292
|
-
ref: sha
|
|
293
|
-
});
|
|
294
|
-
return toCommit(knot.ref, diff.commit, (diff.diff ?? []).map(fromDiff));
|
|
295
|
-
},
|
|
296
|
-
async compare(repo, base, head, options = {}) {
|
|
297
|
-
const knot = await knotFor(repo, options.signal);
|
|
298
|
-
const data = await knot.call("sh.tangled.repo.compare", {
|
|
299
|
-
repo: knot.repo,
|
|
300
|
-
rev1: base,
|
|
301
|
-
rev2: head
|
|
302
|
-
});
|
|
303
|
-
const commits = (data.format_patch ?? []).map((header) => fromHeader(knot.ref, header)).toReversed();
|
|
304
|
-
return {
|
|
305
|
-
base,
|
|
306
|
-
head,
|
|
307
|
-
aheadBy: commits.length,
|
|
308
|
-
commits,
|
|
309
|
-
files: (data.combined_patch ?? []).map(fromPatch),
|
|
310
|
-
mergeBaseSha: data.merge_base || void 0,
|
|
311
|
-
raw: {
|
|
312
|
-
rev1: data.rev1,
|
|
313
|
-
rev2: data.rev2,
|
|
314
|
-
merge_base: data.merge_base
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
},
|
|
318
|
-
/** The `git format-patch` of the commits `head` has and `base` lacks, empty when there are none. */
|
|
319
|
-
async formatPatch(repo, base, head, signal) {
|
|
320
|
-
const knot = await knotFor(repo, signal);
|
|
321
|
-
return (await knot.call("sh.tangled.repo.compare", {
|
|
322
|
-
repo: knot.repo,
|
|
323
|
-
rev1: base,
|
|
324
|
-
rev2: head
|
|
325
|
-
})).patch ?? "";
|
|
326
|
-
},
|
|
327
|
-
/** Applies `patch` to `branch` on the knot, as `git am` does for a format-patch. */
|
|
328
|
-
async merge(repo, branch, patch, signal) {
|
|
329
|
-
const knot = await knotFor(repo, signal);
|
|
330
|
-
if (!knot.ref.externalId) throw new UnsupportedOperationError(`${repo.owner}/${repo.name} has no repo DID, which merging needs`, context);
|
|
331
|
-
await knot.post("sh.tangled.repo.merge", {
|
|
332
|
-
did: knot.ref.owner,
|
|
333
|
-
name: knot.record.value.name ?? knot.ref.name,
|
|
334
|
-
repo: knot.ref.externalId,
|
|
335
|
-
branch,
|
|
336
|
-
patch
|
|
337
|
-
}, toMergeError);
|
|
338
|
-
},
|
|
339
|
-
async addCollaborator(repo, subject, signal) {
|
|
340
|
-
const knot = await knotFor(repo, signal);
|
|
341
|
-
if (!knot.ref.externalId) throw new UnsupportedOperationError(`${repo.owner}/${repo.name} has no repo DID, which managing collaborators needs`, context);
|
|
342
|
-
await knot.post("sh.tangled.repo.addCollaborator", {
|
|
343
|
-
repo: knot.ref.externalId,
|
|
344
|
-
subject
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
//#endregion
|
|
350
|
-
export { createTangledContents };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/tangled-8lg_73Wi.mjs
|
|
2
|
-
const FORGE = "tangled";
|
|
3
|
-
const COLLECTIONS = {
|
|
4
|
-
repo: "sh.tangled.repo",
|
|
5
|
-
issue: "sh.tangled.repo.issue",
|
|
6
|
-
pull: "sh.tangled.repo.pull",
|
|
7
|
-
comment: "sh.tangled.feed.comment",
|
|
8
|
-
issueComment: "sh.tangled.repo.issue.comment",
|
|
9
|
-
pullComment: "sh.tangled.repo.pull.comment",
|
|
10
|
-
issueState: "sh.tangled.repo.issue.state",
|
|
11
|
-
pullStatus: "sh.tangled.repo.pull.status",
|
|
12
|
-
reaction: "sh.tangled.feed.reaction",
|
|
13
|
-
labelOp: "sh.tangled.label.op",
|
|
14
|
-
labelDefinition: "sh.tangled.label.definition",
|
|
15
|
-
subscription: "sh.tangled.feed.subscription",
|
|
16
|
-
profile: "sh.tangled.actor.profile"
|
|
17
|
-
};
|
|
18
|
-
COLLECTIONS.issue, COLLECTIONS.pull, COLLECTIONS.comment, COLLECTIONS.issueComment, COLLECTIONS.pullComment, COLLECTIONS.issueState, COLLECTIONS.pullStatus, COLLECTIONS.reaction, COLLECTIONS.labelOp;
|
|
19
|
-
function toActor(instance, identity, webUrl) {
|
|
20
|
-
const login = identity.handle ?? identity.did;
|
|
21
|
-
return {
|
|
22
|
-
forge: FORGE,
|
|
23
|
-
instance,
|
|
24
|
-
login,
|
|
25
|
-
id: identity.did,
|
|
26
|
-
url: `${webUrl}/${login}`,
|
|
27
|
-
isBotHint: false
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
Object.fromEntries(Object.entries({
|
|
31
|
-
"+1": "👍",
|
|
32
|
-
"-1": "👎",
|
|
33
|
-
"laugh": "😆",
|
|
34
|
-
"hooray": "🎉",
|
|
35
|
-
"confused": "🫤",
|
|
36
|
-
"heart": "❤️",
|
|
37
|
-
"rocket": "🚀",
|
|
38
|
-
"eyes": "👀"
|
|
39
|
-
}).map(([name, emoji]) => [emoji, name]));
|
|
40
|
-
COLLECTIONS.issueState, COLLECTIONS.pullStatus;
|
|
41
|
-
COLLECTIONS.comment, COLLECTIONS.issueComment, COLLECTIONS.comment, COLLECTIONS.pullComment;
|
|
42
|
-
//#endregion
|
|
43
|
-
export { toActor as n, FORGE as t };
|