@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.
@@ -0,0 +1,541 @@
1
+ import { $ as toDate, rt as toPullStats } from "./utils-DC7MBR65-B7Vr2hFm.js";
2
+ import { d as eventTime } from "./webhooks-Bc6QhmI8-CNgCERCq.js";
3
+ import { t as toAuthorAssociation } from "./association-Ds6Tgs0W-Cu9_YCGq.js";
4
+ //#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/graphql-BDhuP5jN.mjs
5
+ const FORGE = "github";
6
+ const ACTOR_FIELDS = `__typename login avatarUrl url ... on User { databaseId name } ... on Bot { databaseId }`;
7
+ const USER_FIELDS = `__typename login avatarUrl url databaseId name`;
8
+ const DISCUSSION_FIELDS = `id number title body closed stateReason url createdAt updatedAt closedAt locked
9
+ author { ${ACTOR_FIELDS} } authorAssociation
10
+ labels(first: 50) { nodes { name color description } }
11
+ comments { totalCount }`;
12
+ const DISCUSSION_THREAD = `query DiscussionThread($owner: String!, $name: String!, $number: Int!) {
13
+ repository(owner: $owner, name: $name) {
14
+ discussion(number: $number) {
15
+ ${DISCUSSION_FIELDS}
16
+ }
17
+ }
18
+ }`;
19
+ const DISCUSSIONS_LIST = `query DiscussionsList($owner: String!, $name: String!, $first: Int!, $after: String, $field: DiscussionOrderField!, $direction: OrderDirection!) {
20
+ repository(owner: $owner, name: $name) {
21
+ discussions(first: $first, after: $after, orderBy: { field: $field, direction: $direction }) {
22
+ pageInfo { hasNextPage endCursor }
23
+ nodes {
24
+ ${DISCUSSION_FIELDS}
25
+ }
26
+ }
27
+ }
28
+ }`;
29
+ const UPDATE_DISCUSSION = `mutation UpdateDiscussion($id: ID!, $title: String, $body: String) {
30
+ updateDiscussion(input: { discussionId: $id, title: $title, body: $body }) { discussion { ${DISCUSSION_FIELDS} } }
31
+ }`;
32
+ const COMMENT_FIELDS = `id databaseId body createdAt updatedAt url author { ${ACTOR_FIELDS} } authorAssociation`;
33
+ const UPDATE_DISCUSSION_COMMENT = `mutation UpdateDiscussionComment($id: ID!, $body: String!) {
34
+ updateDiscussionComment(input: { commentId: $id, body: $body }) { comment { ${COMMENT_FIELDS} } }
35
+ }`;
36
+ const DELETE_DISCUSSION_COMMENT = `mutation DeleteDiscussionComment($id: ID!) {
37
+ deleteDiscussionComment(input: { id: $id }) { comment { id } }
38
+ }`;
39
+ const GET_DISCUSSION_COMMENT = `query GetDiscussionComment($id: ID!) {
40
+ node(id: $id) { ...on DiscussionComment { ${COMMENT_FIELDS} } }
41
+ }`;
42
+ const SUBSCRIPTION_STATE = `query SubscriptionState($owner: String!, $name: String!, $number: Int!, $discussion: Boolean!) {
43
+ repository(owner: $owner, name: $name) {
44
+ issueOrPullRequest(number: $number) @skip(if: $discussion) {
45
+ ... on Issue { id viewerSubscription }
46
+ ... on PullRequest { id viewerSubscription }
47
+ }
48
+ discussion(number: $number) @include(if: $discussion) { id viewerSubscription }
49
+ }
50
+ }`;
51
+ const UPDATE_SUBSCRIPTION = `mutation UpdateSubscription($id: ID!, $state: SubscriptionState!) {
52
+ updateSubscription(input: { subscribableId: $id, state: $state }) { subscribable { viewerSubscription } }
53
+ }`;
54
+ const GIT_ACTOR_FIELDS = `name email date user { ${USER_FIELDS} }`;
55
+ const CREATE_COMMIT_ON_BRANCH = `mutation CreateCommitOnBranch($input: CreateCommitOnBranchInput!) {
56
+ createCommitOnBranch(input: $input) {
57
+ commit { oid message url author { ${GIT_ACTOR_FIELDS} } committer { ${GIT_ACTOR_FIELDS} } parents(first: 2) { nodes { oid } } }
58
+ }
59
+ }`;
60
+ function toCommitSignature(instance, raw) {
61
+ return {
62
+ actor: toGraphQLActor(instance, raw?.user),
63
+ name: raw?.name ?? void 0,
64
+ email: raw?.email ?? void 0,
65
+ date: toDate(raw?.date)
66
+ };
67
+ }
68
+ function toGraphQLCommit(repo, raw) {
69
+ return {
70
+ ref: {
71
+ forge: FORGE,
72
+ instance: repo.instance,
73
+ repo,
74
+ sha: raw.oid
75
+ },
76
+ sha: raw.oid,
77
+ message: raw.message,
78
+ author: toCommitSignature(repo.instance, raw.author),
79
+ committer: toCommitSignature(repo.instance, raw.committer),
80
+ parents: raw.parents.nodes.map((parent) => parent.oid),
81
+ url: raw.url,
82
+ raw
83
+ };
84
+ }
85
+ const SPONSORABLE = `query Sponsorable($login: String!) {
86
+ repositoryOwner(login: $login) {
87
+ ... on Sponsorable { hasSponsorsListing }
88
+ }
89
+ }`;
90
+ const ISSUE_FIELDS = `id number title body state stateReason createdAt updatedAt closedAt url locked
91
+ author { ${ACTOR_FIELDS} } authorAssociation
92
+ assignees(first: 20) { nodes { ${USER_FIELDS} } }
93
+ labels(first: 50) { nodes { name color description } }
94
+ comments { totalCount }
95
+ participants(first: 20) { nodes { ${USER_FIELDS} } }
96
+ milestone { number title state description dueOn url }
97
+ issueType { id name description color isEnabled }
98
+ viewerSubscription`;
99
+ const PULL_FIELDS = `id number title body state isDraft createdAt updatedAt closedAt mergedAt url locked
100
+ author { ${ACTOR_FIELDS} } authorAssociation
101
+ mergedBy { ${ACTOR_FIELDS} }
102
+ assignees(first: 20) { nodes { ${USER_FIELDS} } }
103
+ labels(first: 50) { nodes { name color description } }
104
+ comments { totalCount }
105
+ participants(first: 20) { nodes { ${USER_FIELDS} } }
106
+ milestone { number title state description dueOn url }
107
+ viewerSubscription
108
+ headRefName headRefOid baseRefName baseRefOid
109
+ headRepository { databaseId name owner { login } }
110
+ mergeCommit { oid }
111
+ additions deletions changedFiles
112
+ commits(last: 1) { totalCount nodes { commit { statusCheckRollup { state contexts { totalCount checkRunCountsByState { state count } statusContextCountsByState { state count } } } } } }
113
+ reviewRequests(first: 20) { nodes { requestedReviewer { __typename ... on User { login databaseId avatarUrl url } ... on Bot { login databaseId avatarUrl url } ... on Team { slug databaseId name url } } } }
114
+ timelineItems(itemTypes: [REVIEW_REQUESTED_EVENT], last: 20) { nodes { ... on ReviewRequestedEvent { createdAt requestedReviewer { __typename ... on User { login } ... on Bot { login } ... on Team { slug } } } } }`;
115
+ const REFERENCE_PAGE = "first: $first, after: $after) { pageInfo { hasNextPage endCursor }";
116
+ const REFERENCE_REPOSITORY = "repository { databaseId name owner { login } }";
117
+ const CLOSING_ISSUES = `query ClosingIssues($owner: String!, $name: String!, $number: Int!, $first: Int!, $after: String) {
118
+ repository(owner: $owner, name: $name) {
119
+ thread: pullRequest(number: $number) {
120
+ references: closingIssuesReferences(${REFERENCE_PAGE} nodes { __typename ${REFERENCE_REPOSITORY} ${ISSUE_FIELDS} } }
121
+ }
122
+ }
123
+ }`;
124
+ const CLOSING_PULL_REQUESTS = `query ClosingPullRequests($owner: String!, $name: String!, $number: Int!, $first: Int!, $after: String) {
125
+ repository(owner: $owner, name: $name) {
126
+ thread: issue(number: $number) {
127
+ references: closedByPullRequestsReferences(includeClosedPrs: true, ${REFERENCE_PAGE} nodes { __typename ${REFERENCE_REPOSITORY} ${PULL_FIELDS} } }
128
+ }
129
+ }
130
+ }`;
131
+ /** One aliased query reading many issues, pull requests and discussions. */
132
+ function threadsBatchQuery(refs) {
133
+ const variables = {};
134
+ const declarations = [];
135
+ const fields = refs.map((ref, index) => {
136
+ variables[`o${index}`] = ref.repo.owner;
137
+ variables[`n${index}`] = ref.repo.name;
138
+ variables[`k${index}`] = Number(ref.number);
139
+ declarations.push(`$o${index}: String!`, `$n${index}: String!`, `$k${index}: Int!`);
140
+ return `t${index}: repository(owner: $o${index}, name: $n${index}) { ${ref.kind === "discussion" ? `discussion(number: $k${index}) { ${DISCUSSION_FIELDS} }` : `issueOrPullRequest(number: $k${index}) { __typename ... on Issue { ${ISSUE_FIELDS} } ... on PullRequest { ${PULL_FIELDS} } }`} }`;
141
+ });
142
+ return {
143
+ query: `query ThreadsBatch(${declarations.join(", ")}) {\n ${fields.join("\n ")}\n}`,
144
+ variables
145
+ };
146
+ }
147
+ /** A GraphQL milestone as the model holds it. */
148
+ function toGraphQLMilestone(raw) {
149
+ return raw ? {
150
+ id: String(raw.number),
151
+ title: raw.title,
152
+ state: raw.state === "CLOSED" ? "closed" : "open",
153
+ description: raw.description ?? void 0,
154
+ dueOn: toDate(raw.dueOn),
155
+ url: raw.url,
156
+ raw
157
+ } : void 0;
158
+ }
159
+ function toGraphQLIssueType(raw) {
160
+ return raw ? {
161
+ id: raw.id,
162
+ name: raw.name,
163
+ description: raw.description || void 0,
164
+ colour: raw.color?.toLowerCase(),
165
+ enabled: raw.isEnabled,
166
+ raw
167
+ } : void 0;
168
+ }
169
+ function toViewerSubscription(value) {
170
+ return value === "SUBSCRIBED" ? "subscribed" : value === "IGNORED" ? "ignored" : value === "UNSUBSCRIBED" ? "none" : void 0;
171
+ }
172
+ const FAILED_RUNS = /* @__PURE__ */ new Set([
173
+ "FAILURE",
174
+ "TIMED_OUT",
175
+ "CANCELLED",
176
+ "ACTION_REQUIRED",
177
+ "STARTUP_FAILURE"
178
+ ]);
179
+ const FAILED_STATUSES = /* @__PURE__ */ new Set(["FAILURE", "ERROR"]);
180
+ function toRollupSummary(rollup, url) {
181
+ const failed = (rollup.contexts.checkRunCountsByState ?? []).filter(({ state }) => FAILED_RUNS.has(state)).reduce((sum, { count }) => sum + count, 0) + (rollup.contexts.statusContextCountsByState ?? []).filter(({ state }) => FAILED_STATUSES.has(state)).reduce((sum, { count }) => sum + count, 0);
182
+ return {
183
+ state: rollup.state === "SUCCESS" ? "success" : rollup.state === "FAILURE" || rollup.state === "ERROR" ? "failure" : rollup.state === "PENDING" || rollup.state === "EXPECTED" ? "pending" : "unknown",
184
+ stateRaw: rollup.state.toLowerCase(),
185
+ total: rollup.contexts.totalCount,
186
+ failed,
187
+ ...url ? { url: `${url}/checks` } : {}
188
+ };
189
+ }
190
+ function toGraphQLThread(ref, raw) {
191
+ const instance = ref.instance;
192
+ const isPull = raw.__typename === "PullRequest";
193
+ const kind = isPull ? "pull_request" : "issue";
194
+ const state = raw.state === "MERGED" ? "merged" : raw.state === "OPEN" ? "open" : raw.state === "CLOSED" ? "closed" : "unknown";
195
+ const requestedAt = /* @__PURE__ */ new Map();
196
+ for (const { createdAt, requestedReviewer } of raw.timelineItems?.nodes ?? []) {
197
+ const name = requestedReviewer?.slug ?? requestedReviewer?.login;
198
+ if (createdAt && name) requestedAt.set(`${requestedReviewer.__typename}:${name}`, createdAt);
199
+ }
200
+ const reviewers = (raw.reviewRequests?.nodes ?? []).flatMap(({ requestedReviewer: reviewer }) => {
201
+ if (!reviewer) return [];
202
+ const isTeam = reviewer.__typename === "Team";
203
+ const actor = isTeam ? {
204
+ forge: FORGE,
205
+ instance,
206
+ login: reviewer.slug ?? "",
207
+ id: String(reviewer.databaseId ?? reviewer.slug),
208
+ name: reviewer.name,
209
+ url: reviewer.url,
210
+ typeRaw: "Team",
211
+ isBotHint: false
212
+ } : toGraphQLActor(instance, reviewer);
213
+ const at = requestedAt.get(`${reviewer.__typename}:${isTeam ? reviewer.slug : reviewer.login}`);
214
+ return [{
215
+ actor,
216
+ state: "pending",
217
+ stateRaw: "requested",
218
+ ...isTeam ? { isTeam: true } : {},
219
+ ...at ? { requestedAt: new Date(at) } : {}
220
+ }];
221
+ });
222
+ return {
223
+ ref: {
224
+ ...ref,
225
+ kind,
226
+ externalId: raw.id
227
+ },
228
+ kind,
229
+ title: raw.title,
230
+ body: raw.body,
231
+ state,
232
+ stateRaw: raw.state.toLowerCase(),
233
+ stateReason: raw.stateReason?.toLowerCase() ?? void 0,
234
+ isDraft: raw.isDraft ?? false,
235
+ author: toGraphQLActor(instance, raw.author),
236
+ ...toAuthorAssociation(raw.authorAssociation),
237
+ assignees: (raw.assignees?.nodes ?? []).flatMap((actor) => toGraphQLActor(instance, actor) ?? []),
238
+ participants: (raw.participants?.nodes ?? []).flatMap((actor) => toGraphQLActor(instance, actor) ?? []),
239
+ milestone: toGraphQLMilestone(raw.milestone),
240
+ issueType: toGraphQLIssueType(raw.issueType),
241
+ subscription: toViewerSubscription(raw.viewerSubscription),
242
+ reviewers,
243
+ labels: (raw.labels?.nodes ?? []).map((label) => ({
244
+ name: label.name,
245
+ colour: label.color,
246
+ description: label.description ?? void 0
247
+ })),
248
+ url: raw.url,
249
+ createdAt: toDate(raw.createdAt),
250
+ updatedAt: toDate(raw.updatedAt),
251
+ closedAt: toDate(raw.closedAt),
252
+ mergedAt: toDate(raw.mergedAt),
253
+ mergedBy: toGraphQLActor(instance, raw.mergedBy),
254
+ lastActivityAt: toDate(raw.updatedAt),
255
+ locked: raw.locked,
256
+ commentCount: raw.comments?.totalCount,
257
+ ...isPull && raw.commits?.nodes[0]?.commit.statusCheckRollup ? { checks: toRollupSummary(raw.commits.nodes[0].commit.statusCheckRollup, raw.url) } : {},
258
+ branches: isPull && raw.headRefName && raw.baseRefName ? {
259
+ head: {
260
+ ref: raw.headRefName,
261
+ sha: raw.headRefOid,
262
+ repo: raw.headRepository ? {
263
+ forge: FORGE,
264
+ instance,
265
+ owner: raw.headRepository.owner.login,
266
+ name: raw.headRepository.name,
267
+ externalId: raw.headRepository.databaseId === void 0 ? void 0 : String(raw.headRepository.databaseId)
268
+ } : void 0
269
+ },
270
+ base: {
271
+ ref: raw.baseRefName,
272
+ sha: raw.baseRefOid
273
+ },
274
+ mergeCommitSha: raw.mergeCommit?.oid
275
+ } : void 0,
276
+ stats: toPullStats({
277
+ additions: raw.additions,
278
+ deletions: raw.deletions,
279
+ changedFileCount: raw.changedFiles,
280
+ commitCount: raw.commits?.totalCount
281
+ }),
282
+ raw
283
+ };
284
+ }
285
+ /** Lists recent discussions in several repositories at once, for resolving notification subjects. */
286
+ function recentDiscussionsQuery(repos) {
287
+ const variables = {};
288
+ const declarations = [];
289
+ const fields = repos.map((repo, index) => {
290
+ variables[`o${index}`] = repo.owner;
291
+ variables[`n${index}`] = repo.name;
292
+ declarations.push(`$o${index}: String!`, `$n${index}: String!`);
293
+ return `r${index}: repository(owner: $o${index}, name: $n${index}) { discussions(first: 50, orderBy: { field: UPDATED_AT, direction: DESC }) { nodes { id number title updatedAt } } }`;
294
+ });
295
+ return {
296
+ query: `query RecentDiscussions(${declarations.join(", ")}) {\n ${fields.join("\n ")}\n}`,
297
+ variables
298
+ };
299
+ }
300
+ const DISCUSSION_COMMENTS = `query DiscussionComments($owner: String!, $name: String!, $number: Int!, $after: String) {
301
+ repository(owner: $owner, name: $name) {
302
+ discussion(number: $number) {
303
+ comments(first: 50, after: $after) {
304
+ pageInfo { hasNextPage endCursor }
305
+ nodes {
306
+ id databaseId body createdAt url
307
+ author { ${ACTOR_FIELDS} } authorAssociation
308
+ replies(first: 50) { nodes { id databaseId body createdAt url author { ${ACTOR_FIELDS} } authorAssociation } }
309
+ }
310
+ }
311
+ }
312
+ }
313
+ }`;
314
+ const ADD_DISCUSSION_COMMENT = `mutation AddDiscussionComment($id: ID!, $body: String!) {
315
+ addDiscussionComment(input: { discussionId: $id, body: $body }) { comment { ${COMMENT_FIELDS} } }
316
+ }`;
317
+ const CLOSE_DISCUSSION = `mutation CloseDiscussion($id: ID!, $reason: DiscussionCloseReason) {
318
+ closeDiscussion(input: { discussionId: $id, reason: $reason }) { discussion { ${DISCUSSION_FIELDS} } }
319
+ }`;
320
+ const REOPEN_DISCUSSION = `mutation ReopenDiscussion($id: ID!) {
321
+ reopenDiscussion(input: { discussionId: $id }) { discussion { ${DISCUSSION_FIELDS} } }
322
+ }`;
323
+ function toGraphQLActor(instance, actor) {
324
+ if (!actor) return;
325
+ const isBot = actor.__typename === "Bot";
326
+ const slug = isBot ? actor.login.replace(/\[bot\]$/, "") : void 0;
327
+ return {
328
+ forge: FORGE,
329
+ instance,
330
+ login: slug ? `${slug}[bot]` : actor.login,
331
+ id: String(actor.databaseId ?? actor.login),
332
+ name: actor.name,
333
+ avatarUrl: actor.avatarUrl,
334
+ url: actor.url,
335
+ typeRaw: actor.__typename,
336
+ isBotHint: isBot || actor.login.endsWith("[bot]"),
337
+ ...slug ? { app: { slug } } : {}
338
+ };
339
+ }
340
+ function toDiscussionThread(ref, raw) {
341
+ return {
342
+ ref: {
343
+ ...ref,
344
+ externalId: raw.id
345
+ },
346
+ kind: "discussion",
347
+ title: raw.title,
348
+ body: raw.body,
349
+ state: raw.closed ? "closed" : "open",
350
+ stateRaw: raw.closed ? "closed" : "open",
351
+ stateReason: raw.stateReason?.toLowerCase(),
352
+ isDraft: false,
353
+ author: toGraphQLActor(ref.instance, raw.author),
354
+ ...toAuthorAssociation(raw.authorAssociation),
355
+ assignees: [],
356
+ reviewers: [],
357
+ lastActivityAt: toDate(raw.updatedAt),
358
+ url: raw.url,
359
+ createdAt: toDate(raw.createdAt),
360
+ updatedAt: toDate(raw.updatedAt),
361
+ closedAt: toDate(raw.closedAt),
362
+ labels: (raw.labels?.nodes ?? []).map((label) => ({
363
+ name: label.name,
364
+ colour: label.color,
365
+ description: label.description ?? void 0
366
+ })),
367
+ locked: raw.locked,
368
+ commentCount: raw.comments?.totalCount,
369
+ raw
370
+ };
371
+ }
372
+ function toDiscussionCommentEvent(ref, comment, isReply) {
373
+ const actor = toGraphQLActor(ref.instance, comment.author);
374
+ return {
375
+ forge: FORGE,
376
+ instance: ref.instance,
377
+ id: comment.id,
378
+ kind: "comment",
379
+ kindRaw: isReply ? "DiscussionCommentReply" : "DiscussionComment",
380
+ summary: `${actor?.login ?? "someone"} ${isReply ? "replied" : "commented"}`,
381
+ ...eventTime(toDate(comment.createdAt), /* @__PURE__ */ new Date(0)),
382
+ actor,
383
+ repo: ref.repo,
384
+ thread: ref,
385
+ detail: {
386
+ type: "comment",
387
+ comment: {
388
+ forge: FORGE,
389
+ instance: ref.instance,
390
+ thread: ref,
391
+ id: comment.id
392
+ },
393
+ body: comment.body ?? void 0
394
+ },
395
+ source: "poll",
396
+ payload: comment
397
+ };
398
+ }
399
+ function toDiscussionComment(thread, raw) {
400
+ return {
401
+ ref: {
402
+ forge: FORGE,
403
+ instance: thread.instance,
404
+ thread,
405
+ id: raw.id
406
+ },
407
+ body: raw.body ?? "",
408
+ author: toGraphQLActor(thread.instance, raw.author),
409
+ ...toAuthorAssociation(raw.authorAssociation),
410
+ createdAt: toDate(raw.createdAt),
411
+ updatedAt: toDate(raw.updatedAt),
412
+ url: raw.url,
413
+ raw
414
+ };
415
+ }
416
+ const REPOSITORY_ID = `query RepositoryId($owner: String!, $name: String!) {
417
+ repository(owner: $owner, name: $name) { id }
418
+ }`;
419
+ const UPDATE_REFS = `mutation UpdateRefs($input: UpdateRefsInput!) {
420
+ updateRefs(input: $input) { clientMutationId }
421
+ }`;
422
+ const TRANSFER_ISSUE = `mutation TransferIssue($issue: ID!, $repo: ID!) {
423
+ transferIssue(input: { issueId: $issue, repositoryId: $repo }) { issue { id number } }
424
+ }`;
425
+ const MARK_DUPLICATE = `mutation MarkDuplicate($canonical: ID!, $duplicate: ID!) {
426
+ closeIssue(input: { issueId: $duplicate, stateReason: DUPLICATE, duplicateIssueId: $canonical }) { issue { __typename } }
427
+ }`;
428
+ const NODE_REACTIONS = `query NodeReactions($id: ID!, $after: String) {
429
+ node(id: $id) {
430
+ ... on Reactable {
431
+ reactions(first: 100, after: $after) {
432
+ totalCount
433
+ pageInfo { hasNextPage endCursor }
434
+ nodes { content createdAt user { __typename login databaseId name avatarUrl url } }
435
+ }
436
+ }
437
+ }
438
+ }`;
439
+ const ADD_REACTION = `mutation AddReaction($id: ID!, $content: ReactionContent!) {
440
+ addReaction(input: { subjectId: $id, content: $content }) { reaction { content } }
441
+ }`;
442
+ const REMOVE_REACTION = `mutation RemoveReaction($id: ID!, $content: ReactionContent!) {
443
+ removeReaction(input: { subjectId: $id, content: $content }) { reaction { content } }
444
+ }`;
445
+ /** The GraphQL `ReactionContent` enum, by the model's name for each reaction. */
446
+ const REACTION_CONTENT = {
447
+ "+1": "THUMBS_UP",
448
+ "-1": "THUMBS_DOWN",
449
+ "laugh": "LAUGH",
450
+ "confused": "CONFUSED",
451
+ "heart": "HEART",
452
+ "hooray": "HOORAY",
453
+ "rocket": "ROCKET",
454
+ "eyes": "EYES"
455
+ };
456
+ /** The model's name for each GraphQL `ReactionContent` value. */
457
+ const GRAPHQL_REACTIONS = Object.fromEntries(Object.entries(REACTION_CONTENT).map(([content, graphql]) => [graphql, content]));
458
+ const REVIEW_THREADS = `query ReviewThreads($owner: String!, $name: String!, $number: Int!, $after: String) {
459
+ repository(owner: $owner, name: $name) {
460
+ pullRequest(number: $number) {
461
+ reviewThreads(first: 100, after: $after) {
462
+ pageInfo { hasNextPage endCursor }
463
+ nodes { id isResolved comments(first: 100) { nodes { databaseId } } }
464
+ }
465
+ }
466
+ }
467
+ }`;
468
+ const REVIEW_THREAD_PAGE = `query ReviewThreadPage($owner: String!, $name: String!, $number: Int!, $first: Int!, $after: String) {
469
+ repository(owner: $owner, name: $name) {
470
+ pullRequest(number: $number) {
471
+ reviewThreads(first: $first, after: $after) {
472
+ pageInfo { hasNextPage endCursor }
473
+ nodes {
474
+ id isResolved isOutdated path line startLine originalLine originalStartLine diffSide
475
+ comments(first: 100) {
476
+ nodes { databaseId body path line originalLine createdAt url replyTo { databaseId } author { ${ACTOR_FIELDS} } }
477
+ }
478
+ }
479
+ }
480
+ }
481
+ }
482
+ }`;
483
+ /** An outdated conversation can lose its `line` on the current diff, so it falls back to the line its comments were written on. */
484
+ function toReviewThread(ref, raw) {
485
+ const side = raw.diffSide === "LEFT" ? "left" : raw.diffSide === "RIGHT" ? "right" : void 0;
486
+ const thread = {
487
+ id: raw.id,
488
+ resolved: raw.isResolved
489
+ };
490
+ return {
491
+ id: raw.id,
492
+ resolved: raw.isResolved,
493
+ outdated: raw.isOutdated,
494
+ path: raw.path ?? void 0,
495
+ line: raw.line ?? raw.originalLine ?? void 0,
496
+ startLine: raw.startLine ?? raw.originalStartLine ?? void 0,
497
+ side,
498
+ comments: raw.comments.nodes.map((comment) => ({
499
+ ...comment.databaseId === null ? {} : { ref: {
500
+ forge: FORGE,
501
+ instance: ref.instance,
502
+ thread: ref,
503
+ id: String(comment.databaseId)
504
+ } },
505
+ body: comment.body ?? "",
506
+ author: toGraphQLActor(ref.instance, comment.author),
507
+ path: comment.path ?? void 0,
508
+ line: comment.line ?? comment.originalLine ?? void 0,
509
+ side,
510
+ inReplyTo: typeof comment.replyTo?.databaseId === "number" ? String(comment.replyTo.databaseId) : void 0,
511
+ thread,
512
+ createdAt: toDate(comment.createdAt),
513
+ url: comment.url,
514
+ raw: comment
515
+ })),
516
+ raw
517
+ };
518
+ }
519
+ const RESOLVE_REVIEW_THREAD = `mutation ResolveReviewThread($id: ID!) {
520
+ resolveReviewThread(input: { threadId: $id }) { thread { isResolved } }
521
+ }`;
522
+ const UNRESOLVE_REVIEW_THREAD = `mutation UnresolveReviewThread($id: ID!) {
523
+ unresolveReviewThread(input: { threadId: $id }) { thread { isResolved } }
524
+ }`;
525
+ const LOCK_LOCKABLE = `mutation LockLockable($id: ID!) {
526
+ lockLockable(input: { lockableId: $id }) { lockedRecord { locked } }
527
+ }`;
528
+ const UNLOCK_LOCKABLE = `mutation UnlockLockable($id: ID!) {
529
+ unlockLockable(input: { lockableId: $id }) { unlockedRecord { locked } }
530
+ }`;
531
+ const MINIMIZE_COMMENT = `mutation MinimizeComment($id: ID!, $classifier: ReportedContentClassifiers!) {
532
+ minimizeComment(input: { subjectId: $id, classifier: $classifier }) { minimizedComment { isMinimized } }
533
+ }`;
534
+ const UNMINIMIZE_COMMENT = `mutation UnminimizeComment($id: ID!) {
535
+ unminimizeComment(input: { subjectId: $id }) { unminimizedComment { isMinimized } }
536
+ }`;
537
+ const UPDATE_PULL_REQUEST_BRANCH = `mutation UpdatePullRequestBranch($id: ID!, $sha: GitObjectID, $method: PullRequestBranchUpdateMethod) {
538
+ updatePullRequestBranch(input: { pullRequestId: $id, expectedHeadOid: $sha, updateMethod: $method }) { pullRequest { headRefOid } }
539
+ }`;
540
+ //#endregion
541
+ export { ADD_DISCUSSION_COMMENT, ADD_REACTION, CLOSE_DISCUSSION, CLOSING_ISSUES, CLOSING_PULL_REQUESTS, CREATE_COMMIT_ON_BRANCH, DELETE_DISCUSSION_COMMENT, DISCUSSIONS_LIST, DISCUSSION_COMMENTS, DISCUSSION_THREAD, GET_DISCUSSION_COMMENT, GRAPHQL_REACTIONS, LOCK_LOCKABLE, MARK_DUPLICATE, MINIMIZE_COMMENT, NODE_REACTIONS, REACTION_CONTENT, REMOVE_REACTION, REOPEN_DISCUSSION, REPOSITORY_ID, RESOLVE_REVIEW_THREAD, REVIEW_THREADS, REVIEW_THREAD_PAGE, SPONSORABLE, SUBSCRIPTION_STATE, TRANSFER_ISSUE, UNLOCK_LOCKABLE, UNMINIMIZE_COMMENT, UNRESOLVE_REVIEW_THREAD, UPDATE_DISCUSSION, UPDATE_DISCUSSION_COMMENT, UPDATE_PULL_REQUEST_BRANCH, UPDATE_REFS, UPDATE_SUBSCRIPTION, recentDiscussionsQuery, threadsBatchQuery, toDiscussionComment, toDiscussionCommentEvent, toDiscussionThread, toGraphQLActor, toGraphQLCommit, toGraphQLMilestone, toGraphQLThread, toReviewThread, toViewerSubscription };
@@ -0,0 +1,27 @@
1
+ //#region src/build/identity.d.ts
2
+ /** The build of an app: the commit and branch, the GitHub repository, and the pull request when the host names it. */
3
+ interface ForgeBuild {
4
+ commit?: string;
5
+ branch?: string;
6
+ /** The GitHub repository, as `owner/name`. */
7
+ repository?: string;
8
+ /** The pull request that the build previews, when the host names it. Never trust it to grant access. */
9
+ pullRequest?: number;
10
+ }
11
+ /** The repository and commit a page says it was built from. A claim, not a proof: check it against the Forge. */
12
+ interface BuildIdentity {
13
+ /** `owner/name`. */
14
+ repository: string;
15
+ /** The full commit SHA, lowercase. */
16
+ commit: string;
17
+ }
18
+ /** The `name` of the `<meta>` tag that holds a page's {@link BuildIdentity}. */
19
+ declare const buildMetaName = "vitehub:build";
20
+ /** The identity of a build, when it has a valid repository and a full commit SHA. */
21
+ declare function buildIdentity(build: ForgeBuild): BuildIdentity | undefined;
22
+ /** The `content` of the `vitehub:build` meta tag, or `undefined` when the build has no identity. */
23
+ declare function buildMetaContent(build: ForgeBuild): string | undefined;
24
+ /** The identity in a `vitehub:build` meta tag's `content`, or `undefined` when it is missing or malformed. */
25
+ declare function parseBuildMeta(content: string | null | undefined): BuildIdentity | undefined;
26
+ //#endregion
27
+ export { buildMetaName as a, buildMetaContent as i, ForgeBuild as n, parseBuildMeta as o, buildIdentity as r, BuildIdentity as t };
@@ -0,0 +1,38 @@
1
+ //#region src/build/identity.ts
2
+ /** The `name` of the `<meta>` tag that holds a page's {@link BuildIdentity}. */
3
+ const buildMetaName = "vitehub:build";
4
+ const repositoryPattern = /^[\w.-]+\/[\w.-]+$/;
5
+ const commitPattern = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
6
+ /** The identity of a build, when it has a valid repository and a full commit SHA. */
7
+ function buildIdentity(build) {
8
+ const repository = build.repository?.trim();
9
+ const commit = build.commit?.trim().toLowerCase();
10
+ if (!repository || !repositoryPattern.test(repository) || !commit || !commitPattern.test(commit)) return void 0;
11
+ return {
12
+ repository,
13
+ commit
14
+ };
15
+ }
16
+ /** The `content` of the `vitehub:build` meta tag, or `undefined` when the build has no identity. */
17
+ function buildMetaContent(build) {
18
+ const identity = buildIdentity(build);
19
+ return identity ? JSON.stringify(identity) : void 0;
20
+ }
21
+ /** The identity in a `vitehub:build` meta tag's `content`, or `undefined` when it is missing or malformed. */
22
+ function parseBuildMeta(content) {
23
+ if (!content) return void 0;
24
+ let value;
25
+ try {
26
+ value = JSON.parse(content);
27
+ } catch {
28
+ return;
29
+ }
30
+ if (!value || typeof value !== "object") return void 0;
31
+ const { repository, commit } = value;
32
+ return typeof repository === "string" && typeof commit === "string" ? buildIdentity({
33
+ repository,
34
+ commit
35
+ }) : void 0;
36
+ }
37
+ //#endregion
38
+ export { parseBuildMeta as i, buildMetaContent as n, buildMetaName as r, buildIdentity as t };