ref0-git 0.2.0 → 0.4.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/app/apps/github/.dev.vars.example +2 -1
- package/app/apps/github/generated/git-rest.ts +191 -25
- package/app/apps/github/generated/routeTree.gen.ts +21 -0
- package/app/apps/github/package.json +1 -1
- package/app/apps/github/src/branches/branch-list.tsx +8 -4
- package/app/apps/github/src/branches/branches.ts +10 -5
- package/app/apps/github/src/camo/addresses.ts +120 -0
- package/app/apps/github/src/camo/client.ts +125 -0
- package/app/apps/github/src/camo/fetch.ts +201 -0
- package/app/apps/github/src/camo/lookup.ts +23 -0
- package/app/apps/github/src/camo/node.ts +50 -0
- package/app/apps/github/src/camo/proxy.ts +116 -0
- package/app/apps/github/src/camo/sign-images.ts +307 -0
- package/app/apps/github/src/camo/signing.ts +80 -0
- package/app/apps/github/src/clients/allowed.ts +111 -18
- package/app/apps/github/src/clients/clients.ts +76 -61
- package/app/apps/github/src/clients/transport.ts +13 -0
- package/app/apps/github/src/code/code-tree.tsx +3 -1
- package/app/apps/github/src/code/file-view.tsx +15 -6
- package/app/apps/github/src/code/files.ts +26 -19
- package/app/apps/github/src/code/go-to-file.tsx +2 -1
- package/app/apps/github/src/code/load.ts +41 -23
- package/app/apps/github/src/code/markdown-files.ts +13 -2
- package/app/apps/github/src/code/ref-pages.ts +14 -5
- package/app/apps/github/src/code/ref-switcher.tsx +4 -3
- package/app/apps/github/src/code/refs.ts +42 -8
- package/app/apps/github/src/code/repo-home.tsx +6 -2
- package/app/apps/github/src/code/repo.ts +12 -6
- package/app/apps/github/src/code/saved.ts +5 -3
- package/app/apps/github/src/code/trees.ts +11 -9
- package/app/apps/github/src/components/markdown/markdown.css +6 -0
- package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
- package/app/apps/github/src/components/owner-card.tsx +3 -1
- package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
- package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
- package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
- package/app/apps/github/src/components/signin/device-card.tsx +9 -2
- package/app/apps/github/src/components/user-avatar.tsx +2 -1
- package/app/apps/github/src/context/context.ts +13 -0
- package/app/apps/github/src/diffs/blobs.ts +37 -14
- package/app/apps/github/src/diffs/diff-job.ts +53 -0
- package/app/apps/github/src/diffs/diff-worker.ts +6 -0
- package/app/apps/github/src/diffs/diffing.ts +136 -0
- package/app/apps/github/src/diffs/files.ts +4 -3
- package/app/apps/github/src/diffs/hunks.tsx +101 -53
- package/app/apps/github/src/diffs/patch.ts +20 -11
- package/app/apps/github/src/history/commit-diff.ts +10 -5
- package/app/apps/github/src/history/commit-list.tsx +3 -1
- package/app/apps/github/src/history/commit-page.tsx +4 -2
- package/app/apps/github/src/history/history.ts +12 -10
- package/app/apps/github/src/hooks/allowed.ts +9 -9
- package/app/apps/github/src/hooks/avatars.ts +3 -3
- package/app/apps/github/src/hooks/open-counts.ts +5 -4
- package/app/apps/github/src/hooks/profiles.ts +26 -12
- package/app/apps/github/src/hooks/repos.ts +78 -25
- package/app/apps/github/src/inbox/count.ts +30 -29
- package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
- package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
- package/app/apps/github/src/inbox/marks.ts +26 -15
- package/app/apps/github/src/inbox/release-tags.ts +7 -6
- package/app/apps/github/src/inbox/subjects.ts +5 -4
- package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
- package/app/apps/github/src/inbox/subscriptions.ts +95 -35
- package/app/apps/github/src/inbox/threads.ts +6 -6
- package/app/apps/github/src/issues/changes.ts +40 -16
- package/app/apps/github/src/issues/counts.ts +8 -5
- package/app/apps/github/src/issues/issue-list.tsx +20 -6
- package/app/apps/github/src/issues/issue-page.tsx +30 -14
- package/app/apps/github/src/issues/issues.ts +195 -46
- package/app/apps/github/src/issues/label-dialog.tsx +8 -11
- package/app/apps/github/src/issues/labels-page.tsx +35 -3
- package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
- package/app/apps/github/src/issues/milestones-page.tsx +269 -0
- package/app/apps/github/src/issues/new-issue.tsx +3 -1
- package/app/apps/github/src/issues/sidebar.tsx +8 -6
- package/app/apps/github/src/markdown/README.md +22 -17
- package/app/apps/github/src/markdown/context.ts +83 -10
- package/app/apps/github/src/markdown/images.ts +3 -2
- package/app/apps/github/src/markdown/lookup.ts +17 -11
- package/app/apps/github/src/markdown/page-budget.ts +50 -0
- package/app/apps/github/src/markdown/patches.ts +74 -32
- package/app/apps/github/src/markdown/query.ts +7 -2
- package/app/apps/github/src/markdown/remote.ts +106 -0
- package/app/apps/github/src/markdown/render.ts +101 -24
- package/app/apps/github/src/markdown/texts.ts +43 -0
- package/app/apps/github/src/markdown/words-module.d.ts +5 -0
- package/app/apps/github/src/markdown/words-plugin.ts +135 -0
- package/app/apps/github/src/names/repos.ts +1 -1
- package/app/apps/github/src/palette/palette.tsx +28 -10
- package/app/apps/github/src/palette/rows.tsx +93 -40
- package/app/apps/github/src/palette/server.ts +10 -7
- package/app/apps/github/src/palette/targets.ts +1 -0
- package/app/apps/github/src/policy.ts +137 -61
- package/app/apps/github/src/private-repos.ts +5 -5
- package/app/apps/github/src/pulls/compare-page.tsx +6 -3
- package/app/apps/github/src/pulls/files-tab.tsx +480 -214
- package/app/apps/github/src/pulls/held-summary.ts +178 -0
- package/app/apps/github/src/pulls/live.ts +6 -4
- package/app/apps/github/src/pulls/merge-box.tsx +17 -10
- package/app/apps/github/src/pulls/pull-list.tsx +6 -3
- package/app/apps/github/src/pulls/pull-page.tsx +19 -10
- package/app/apps/github/src/pulls/pull.ts +68 -40
- package/app/apps/github/src/pulls/pulls.ts +39 -22
- package/app/apps/github/src/pulls/review-drafts.ts +131 -0
- package/app/apps/github/src/pulls/review.ts +374 -99
- package/app/apps/github/src/pulls/threads.tsx +152 -0
- package/app/apps/github/src/queue/queue-page.tsx +15 -8
- package/app/apps/github/src/queue/queue.ts +35 -20
- package/app/apps/github/src/releases/latest-release.tsx +3 -1
- package/app/apps/github/src/releases/overview.tsx +4 -2
- package/app/apps/github/src/releases/release-form.tsx +8 -5
- package/app/apps/github/src/releases/release-list.tsx +8 -5
- package/app/apps/github/src/releases/release-view.tsx +1 -0
- package/app/apps/github/src/releases/releases.ts +33 -23
- package/app/apps/github/src/releases/tag-list.tsx +3 -1
- package/app/apps/github/src/router.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
- package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
- package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
- package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
- package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
- package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
- package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
- package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
- package/app/apps/github/src/routes/-nav.tsx +10 -2
- package/app/apps/github/src/routes/-root-testing.ts +29 -6
- package/app/apps/github/src/routes/__root.tsx +9 -4
- package/app/apps/github/src/routes/index.tsx +3 -1
- package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
- package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
- package/app/apps/github/src/seed/acme.ts +1 -1
- package/app/apps/github/src/seed/seed.ts +199 -120
- package/app/apps/github/src/server.ts +24 -15
- package/app/apps/github/src/settings/account-avatar.tsx +4 -1
- package/app/apps/github/src/settings/general-settings.tsx +3 -1
- package/app/apps/github/src/settings/general.ts +4 -4
- package/app/apps/github/src/settings/hook-form.tsx +3 -1
- package/app/apps/github/src/settings/hook-list.tsx +5 -2
- package/app/apps/github/src/settings/hooks.ts +7 -7
- package/app/apps/github/src/settings/org-settings.tsx +3 -1
- package/app/apps/github/src/settings/orgs.ts +21 -11
- package/app/apps/github/src/settings/settings-layout.tsx +3 -1
- package/app/apps/github/src/signin/approval.ts +4 -3
- package/app/apps/github/src/signin/auth.ts +9 -2
- package/app/apps/github/src/signin/device-code.ts +8 -3
- package/app/apps/github/src/signin/device-prompt.ts +28 -3
- package/app/apps/github/src/signin/revoke.ts +36 -0
- package/app/apps/github/tsconfig.json +4 -1
- package/app/apps/github/vite.config.ts +8 -0
- package/app/pnpm-workspace.yaml +9 -5
- package/app/tsconfig.base.json +1 -0
- package/dist/cli/child.mjs +1 -1
- package/dist/cli/credentials.mjs +4 -4
- package/dist/cli/documents.mjs +32 -22
- package/dist/cli/events.mjs +1 -1
- package/dist/cli/failure.mjs +20 -7
- package/dist/cli/folders.mjs +2 -2
- package/dist/cli/git-remote-ref0.mjs +47 -22
- package/dist/cli/git.mjs +26 -5
- package/dist/cli/helpers.mjs +168 -35
- package/dist/cli/hosts.mjs +3 -3
- package/dist/cli/output.mjs +2 -2
- package/dist/cli/prompt.mjs +1 -1
- package/dist/cli/queue.mjs +7 -7
- package/dist/cli/ref0-git.mjs +2 -2
- package/dist/cli/repos.mjs +35 -18
- package/dist/cli/resources.mjs +5 -5
- package/dist/cli/retry-after.mjs +8 -0
- package/dist/cli/setup.mjs +172 -66
- package/dist/cli/sign-in.mjs +65 -23
- package/dist/cli/sign-ins.mjs +70 -13
- package/dist/cli/sqlite.mjs +2 -2
- package/dist/cli/tokens.mjs +3 -3
- package/dist/cli/vendor.mjs +1 -1
- package/dist/init/app.mjs +18 -20
- package/dist/init/choices.mjs +1 -1
- package/dist/init/cloudflare.mjs +15 -19
- package/dist/init/create.mjs +4 -3
- package/dist/init/detect.mjs +4 -4
- package/dist/init/files.mjs +121 -9
- package/dist/init/frameworks.mjs +16 -0
- package/dist/init/git-module.mjs +22 -7
- package/dist/init/jsonc.mjs +9 -7
- package/dist/init/metadata.mjs +9 -3
- package/dist/init/mounts.mjs +13 -10
- package/dist/init/next.mjs +3 -5
- package/dist/init/node-app.mjs +3 -3
- package/dist/init/node.mjs +41 -42
- package/dist/init/nuxt.mjs +153 -27
- package/dist/init/stores.mjs +14 -9
- package/dist/init/sveltekit.mjs +4 -2
- package/dist/init/template.mjs +9 -6
- package/dist/init/templates.mjs +64 -48
- package/dist/init/vercel.mjs +37 -36
- package/dist/init/versions.mjs +3 -3
- package/package.json +6 -5
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { Fragment, useState, type ReactNode } from 'react';
|
|
12
12
|
|
|
13
13
|
import { day } from '../code/controls.tsx';
|
|
14
|
+
import { useClients } from '../clients/clients.ts';
|
|
14
15
|
import type { RepoPlace } from '../code/places.ts';
|
|
15
16
|
import { Markdown } from '../components/markdown/markdown.tsx';
|
|
16
17
|
import { RelativeTime } from '../components/relative-time.tsx';
|
|
@@ -40,13 +41,14 @@ import {
|
|
|
40
41
|
changeIssue,
|
|
41
42
|
commentsOf,
|
|
42
43
|
editComment,
|
|
43
|
-
|
|
44
|
+
issueKey,
|
|
44
45
|
type Issue,
|
|
45
46
|
type IssueChange,
|
|
46
47
|
type Numbered,
|
|
47
48
|
} from './issues.ts';
|
|
48
49
|
import { HotkeyHint, hotkeys } from '../components/hotkeys/hotkeys.tsx';
|
|
49
50
|
import { MarkdownEditor } from '../components/markdown/editor.tsx';
|
|
51
|
+
import type { TextAddress } from '../markdown/texts.ts';
|
|
50
52
|
import { issueHolding, stateChange, useChange, useShown, type Holding } from './changes.ts';
|
|
51
53
|
import { Sidebar } from './sidebar.tsx';
|
|
52
54
|
import { fills, tones } from '../components/tones.ts';
|
|
@@ -74,6 +76,7 @@ export function Comment({
|
|
|
74
76
|
standing,
|
|
75
77
|
created,
|
|
76
78
|
body,
|
|
79
|
+
from,
|
|
77
80
|
save,
|
|
78
81
|
}: {
|
|
79
82
|
readonly repo: string;
|
|
@@ -86,6 +89,8 @@ export function Comment({
|
|
|
86
89
|
readonly standing?: ReviewStanding | undefined;
|
|
87
90
|
readonly created: string;
|
|
88
91
|
readonly body: string;
|
|
92
|
+
/** Where the text is kept, which the image proxy signs its images for. */
|
|
93
|
+
readonly from: TextAddress;
|
|
89
94
|
/** Saves new text, for a viewer the drop-in lets edit it. */
|
|
90
95
|
readonly save: ((body: string) => Promise<void>) | undefined;
|
|
91
96
|
}) {
|
|
@@ -143,7 +148,7 @@ export function Comment({
|
|
|
143
148
|
body.trim() === '' ? (
|
|
144
149
|
<p className="text-sm text-muted-foreground">No description provided.</p>
|
|
145
150
|
) : (
|
|
146
|
-
<Markdown text={body} context={{ kind: 'comment', repo }} />
|
|
151
|
+
<Markdown text={body} context={{ kind: 'comment', repo }} from={from} />
|
|
147
152
|
)
|
|
148
153
|
) : (
|
|
149
154
|
<form
|
|
@@ -303,21 +308,22 @@ export function Conversation({
|
|
|
303
308
|
/** What shows between the conversation and the comment box, such as a pull request's merge box. */
|
|
304
309
|
readonly children?: ReactNode;
|
|
305
310
|
}) {
|
|
311
|
+
const clients = useClients();
|
|
306
312
|
const client = useQueryClient();
|
|
307
313
|
const { viewer } = useRouteContext({ from: '__root__' });
|
|
308
|
-
const comments = useInfiniteQuery(commentsOf(place, issue.number));
|
|
314
|
+
const comments = useInfiniteQuery(commentsOf(clients, place, issue.number));
|
|
309
315
|
const repo = `${place.owner}/${place.repo}`;
|
|
310
316
|
const [draft, setDraft] = useState('');
|
|
311
317
|
const { commit, changing } = useChange(place, issue.number, holding);
|
|
312
318
|
|
|
313
319
|
const refreshComments = () =>
|
|
314
|
-
client.invalidateQueries({ queryKey: commentsOf(place, issue.number).queryKey });
|
|
320
|
+
client.invalidateQueries({ queryKey: commentsOf(clients, place, issue.number).queryKey });
|
|
315
321
|
|
|
316
322
|
const commented = useMutation({
|
|
317
323
|
mutationFn: async (close: boolean) => {
|
|
318
|
-
if (draft.trim() !== '') await addComment(place, issue.number, draft);
|
|
324
|
+
if (draft.trim() !== '') await addComment(clients, place, issue.number, draft);
|
|
319
325
|
|
|
320
|
-
if (close) commit(stateChange(changing, issue.state === 'open' ? 'closed' : 'open'));
|
|
326
|
+
if (close) commit(stateChange(clients, changing, issue.state === 'open' ? 'closed' : 'open'));
|
|
321
327
|
else await refreshComments();
|
|
322
328
|
},
|
|
323
329
|
onSuccess: async () => {
|
|
@@ -327,7 +333,14 @@ export function Conversation({
|
|
|
327
333
|
});
|
|
328
334
|
|
|
329
335
|
const canUpdate = allowed.has('issue.update');
|
|
336
|
+
// An issue's author edits its text, closes it, and reopens it once they closed it themselves,
|
|
337
|
+
// as GitHub lets them (Q857).
|
|
338
|
+
const canEdit = allowed.has('issue.author');
|
|
330
339
|
const open = issue.state === 'open';
|
|
340
|
+
const closedByViewer = viewer !== null && issue.closedBy === viewer.login;
|
|
341
|
+
// A comment's author edits it too (Q857): the server checks it's theirs again.
|
|
342
|
+
const ownComments = viewer !== null && allowed.has('comment.author');
|
|
343
|
+
const canShut = canUpdate || (canEdit && (open || closedByViewer));
|
|
331
344
|
const loaded = comments.data?.pages.flatMap((page) => page.comments) ?? [];
|
|
332
345
|
// While more comments wait on a page, an event after the last one loaded waits with them.
|
|
333
346
|
const last = loaded.at(-1);
|
|
@@ -347,10 +360,11 @@ export function Conversation({
|
|
|
347
360
|
upload={comment.pictures.get(comment.author)}
|
|
348
361
|
created={comment.created}
|
|
349
362
|
body={comment.body}
|
|
363
|
+
from={{ kind: 'issue-comment', repo, id: comment.id }}
|
|
350
364
|
save={
|
|
351
|
-
allowed.has('comment.update')
|
|
365
|
+
allowed.has('comment.update') || (ownComments && comment.author === viewer?.login)
|
|
352
366
|
? async (body) => {
|
|
353
|
-
await editComment(place, comment.id, body);
|
|
367
|
+
await editComment(clients, place, comment.id, body);
|
|
354
368
|
await refreshComments();
|
|
355
369
|
}
|
|
356
370
|
: undefined
|
|
@@ -371,7 +385,8 @@ export function Conversation({
|
|
|
371
385
|
upload={issue.pictures.get(issue.author)}
|
|
372
386
|
created={issue.created}
|
|
373
387
|
body={issue.body}
|
|
374
|
-
|
|
388
|
+
from={{ kind: 'issue', repo, number: issue.number }}
|
|
389
|
+
save={canEdit ? (body) => change({ body }) : undefined}
|
|
375
390
|
/>
|
|
376
391
|
{(timeline.length > 0 ||
|
|
377
392
|
comments.error !== null ||
|
|
@@ -415,7 +430,7 @@ export function Conversation({
|
|
|
415
430
|
placeholder="Leave a comment"
|
|
416
431
|
/>
|
|
417
432
|
<div className="flex justify-end gap-2">
|
|
418
|
-
{
|
|
433
|
+
{canShut && !settled && (
|
|
419
434
|
<Button
|
|
420
435
|
variant="outline"
|
|
421
436
|
disabled={commented.isPending}
|
|
@@ -482,26 +497,27 @@ export function IssuePage({
|
|
|
482
497
|
readonly place: RepoPlace;
|
|
483
498
|
readonly issue: Issue;
|
|
484
499
|
}) {
|
|
500
|
+
const clients = useClients();
|
|
485
501
|
const client = useQueryClient();
|
|
486
502
|
const issue = useShown(place, held);
|
|
487
503
|
const allowed = useAllowed(place, issue.number);
|
|
488
504
|
const holding = issueHolding(client, place, issue.number);
|
|
489
505
|
|
|
490
506
|
const change = async (asked: IssueChange) => {
|
|
491
|
-
const changed = await changeIssue(place, issue.number, asked);
|
|
507
|
+
const changed = await changeIssue(clients, place, issue.number, asked);
|
|
492
508
|
const numbered: Numbered = { kind: 'issue', issue: changed };
|
|
493
|
-
client.setQueryData(
|
|
509
|
+
client.setQueryData<Numbered>(issueKey(place, issue.number), numbered);
|
|
494
510
|
await client.invalidateQueries({ queryKey: ['issues', place.owner, place.repo] });
|
|
495
511
|
};
|
|
496
512
|
|
|
497
|
-
const
|
|
513
|
+
const canEdit = allowed.has('issue.author');
|
|
498
514
|
const open = issue.state === 'open';
|
|
499
515
|
const StateIcon = open ? CircleDotIcon : CircleCheckIcon;
|
|
500
516
|
|
|
501
517
|
return (
|
|
502
518
|
<div className="flex flex-col gap-section">
|
|
503
519
|
<div className="flex flex-col gap-2 border-b pb-3">
|
|
504
|
-
<Title issue={issue} save={
|
|
520
|
+
<Title issue={issue} save={canEdit ? (title) => change({ title }) : undefined} />
|
|
505
521
|
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
|
|
506
522
|
<Badge className={open ? fills.open : fills.closed}>
|
|
507
523
|
<StateIcon data-icon="inline-start" />
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { components, operations } from '@octokit/openapi-types';
|
|
2
|
-
import { queryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { type QueryClient, queryOptions } from '@tanstack/react-query';
|
|
3
3
|
import * as Option from 'effect/Option';
|
|
4
4
|
import * as Schema from 'effect/Schema';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import type { Clients } from '../clients/clients.ts';
|
|
7
7
|
import type { RepoPlace } from '../code/places.ts';
|
|
8
8
|
import { everyPage, failure } from '../hooks/answers.ts';
|
|
9
9
|
import { type Pictures, picturesOf } from '../hooks/avatars.ts';
|
|
@@ -37,6 +37,8 @@ export interface Issue {
|
|
|
37
37
|
readonly body: string;
|
|
38
38
|
readonly state: 'open' | 'closed';
|
|
39
39
|
readonly author: string;
|
|
40
|
+
/** Who closed it, by login, if the answer named them. */
|
|
41
|
+
readonly closedBy: string | null;
|
|
40
42
|
readonly created: string;
|
|
41
43
|
readonly comments: number;
|
|
42
44
|
readonly labels: readonly Label[];
|
|
@@ -89,7 +91,10 @@ export type IssueFields = Pick<
|
|
|
89
91
|
| 'comments'
|
|
90
92
|
| 'labels'
|
|
91
93
|
| 'milestone'
|
|
92
|
-
> & {
|
|
94
|
+
> & {
|
|
95
|
+
readonly assignees?: RestIssue['assignees'] | null;
|
|
96
|
+
readonly closed_by?: RestIssue['closed_by'];
|
|
97
|
+
};
|
|
93
98
|
|
|
94
99
|
export const issueOf = (issue: IssueFields): Issue => ({
|
|
95
100
|
number: issue.number,
|
|
@@ -97,6 +102,7 @@ export const issueOf = (issue: IssueFields): Issue => ({
|
|
|
97
102
|
body: issue.body ?? '',
|
|
98
103
|
state: issue.state === 'closed' ? 'closed' : 'open',
|
|
99
104
|
author: issue.user?.login ?? 'ghost',
|
|
105
|
+
closedBy: issue.closed_by?.login ?? null,
|
|
100
106
|
created: issue.created_at,
|
|
101
107
|
comments: issue.comments,
|
|
102
108
|
labels: issue.labels.map(labelOf),
|
|
@@ -127,17 +133,21 @@ export interface Vocabulary {
|
|
|
127
133
|
readonly assignees: readonly string[];
|
|
128
134
|
}
|
|
129
135
|
|
|
136
|
+
/** The key of `vocabularyOf`'s read: what changes a label or a milestone reads it again by. */
|
|
137
|
+
export const vocabularyKey = (place: RepoPlace) =>
|
|
138
|
+
['issue-vocabulary', place.owner, place.repo] as const;
|
|
139
|
+
|
|
130
140
|
/** The repo's labels, milestones and assignees. */
|
|
131
|
-
export const vocabularyOf = (place: RepoPlace) =>
|
|
141
|
+
export const vocabularyOf = (clients: Clients, place: RepoPlace) =>
|
|
132
142
|
queryOptions({
|
|
133
|
-
queryKey:
|
|
143
|
+
queryKey: vocabularyKey(place),
|
|
134
144
|
queryFn: async (): Promise<Vocabulary> => {
|
|
135
145
|
const path = { path: place };
|
|
136
146
|
// `after` is the drop-in's cursor, which GitHub's types don't name: a spread passes it.
|
|
137
147
|
const paging = (after: string | undefined) => ({ ...{ per_page: 100, after } });
|
|
138
148
|
const [labels, milestones, assignees] = await Promise.all([
|
|
139
149
|
everyPage(async (after) => {
|
|
140
|
-
const answer = await github.GET('/repos/{owner}/{repo}/labels', {
|
|
150
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/labels', {
|
|
141
151
|
params: { ...path, query: paging(after) },
|
|
142
152
|
});
|
|
143
153
|
if (answer.data === undefined) throw failure("The labels didn't load", answer);
|
|
@@ -145,7 +155,7 @@ export const vocabularyOf = (place: RepoPlace) =>
|
|
|
145
155
|
return { rows: answer.data.map(labelOf), link: answer.response.headers.get('link') };
|
|
146
156
|
}),
|
|
147
157
|
everyPage(async (after) => {
|
|
148
|
-
const answer = await github.GET('/repos/{owner}/{repo}/milestones', {
|
|
158
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/milestones', {
|
|
149
159
|
params: { ...path, query: { ...paging(after), state: 'all' } },
|
|
150
160
|
});
|
|
151
161
|
if (answer.data === undefined) throw failure("The milestones didn't load", answer);
|
|
@@ -159,7 +169,7 @@ export const vocabularyOf = (place: RepoPlace) =>
|
|
|
159
169
|
return { rows, link: answer.response.headers.get('link') };
|
|
160
170
|
}),
|
|
161
171
|
everyPage(async (after) => {
|
|
162
|
-
const answer = await github.GET('/repos/{owner}/{repo}/assignees', {
|
|
172
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/assignees', {
|
|
163
173
|
params: { ...path, query: paging(after) },
|
|
164
174
|
});
|
|
165
175
|
if (answer.data === undefined) throw failure("The assignees didn't load", answer);
|
|
@@ -232,11 +242,11 @@ export type Lister = (
|
|
|
232
242
|
|
|
233
243
|
/** The repo's issue list under `query`, a page from `after`, the drop-in's cursor. */
|
|
234
244
|
export const listedBy =
|
|
235
|
-
(place: RepoPlace, query: ListQuery, what: string): Lister =>
|
|
245
|
+
(clients: Clients, place: RepoPlace, query: ListQuery, what: string): Lister =>
|
|
236
246
|
async (after) => {
|
|
237
247
|
// `after` is the drop-in's cursor, which GitHub's types don't name: a spread passes it.
|
|
238
248
|
const paging = { ...query, after };
|
|
239
|
-
const answer = await github.GET('/repos/{owner}/{repo}/issues', {
|
|
249
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/issues', {
|
|
240
250
|
params: { path: place, query: { ...paging } },
|
|
241
251
|
});
|
|
242
252
|
if (answer.data === undefined) throw failure(`${what} didn't load`, answer);
|
|
@@ -249,10 +259,10 @@ export const listedBy =
|
|
|
249
259
|
* first unless `q` names a `sort:`, as `GET /search/issues` orders them.
|
|
250
260
|
*/
|
|
251
261
|
export const searchedBy =
|
|
252
|
-
(q: string, what: string): Lister =>
|
|
262
|
+
(clients: Clients, q: string, what: string): Lister =>
|
|
253
263
|
async (after) => {
|
|
254
264
|
const page = after === undefined ? 1 : Number(after);
|
|
255
|
-
const answer = await github.GET('/search/issues', {
|
|
265
|
+
const answer = await clients.github.GET('/search/issues', {
|
|
256
266
|
params: { query: { q, per_page: issuesPerPage, page } },
|
|
257
267
|
});
|
|
258
268
|
if (answer.data === undefined) throw failure(`${what} didn't load`, answer);
|
|
@@ -296,6 +306,7 @@ export const readOn = async <Row>(
|
|
|
296
306
|
* `undefined` when no issue can match.
|
|
297
307
|
*/
|
|
298
308
|
export const listerOf = (
|
|
309
|
+
clients: Clients,
|
|
299
310
|
place: RepoPlace,
|
|
300
311
|
filter: IssueFilter,
|
|
301
312
|
query: ListQuery | undefined,
|
|
@@ -303,13 +314,13 @@ export const listerOf = (
|
|
|
303
314
|
what: string,
|
|
304
315
|
): Lister | undefined => {
|
|
305
316
|
if (filter.words.length === 0)
|
|
306
|
-
return query === undefined ? undefined : listedBy(place, query, what);
|
|
317
|
+
return query === undefined ? undefined : listedBy(clients, place, query, what);
|
|
307
318
|
|
|
308
319
|
if (searched === undefined) {
|
|
309
320
|
throw new Error(`${what} didn't load: search can't read a name holding a quote`);
|
|
310
321
|
}
|
|
311
322
|
|
|
312
|
-
return searchedBy(searched, what);
|
|
323
|
+
return searchedBy(clients, searched, what);
|
|
313
324
|
};
|
|
314
325
|
|
|
315
326
|
/**
|
|
@@ -318,6 +329,7 @@ export const listerOf = (
|
|
|
318
329
|
* pull requests alone.
|
|
319
330
|
*/
|
|
320
331
|
export const issuePage = async (
|
|
332
|
+
clients: Clients,
|
|
321
333
|
place: RepoPlace,
|
|
322
334
|
filter: IssueFilter,
|
|
323
335
|
vocabulary: Vocabulary,
|
|
@@ -325,6 +337,7 @@ export const issuePage = async (
|
|
|
325
337
|
): Promise<IssuePage> => {
|
|
326
338
|
const what = 'The issues';
|
|
327
339
|
const lister = listerOf(
|
|
340
|
+
clients,
|
|
328
341
|
place,
|
|
329
342
|
filter,
|
|
330
343
|
listQuery(filter, vocabulary),
|
|
@@ -352,10 +365,15 @@ export const issueLists = (place: RepoPlace) =>
|
|
|
352
365
|
['issues', place.owner, place.repo, 'list'] as const;
|
|
353
366
|
|
|
354
367
|
/** The repo's issues under `filter`, a page at a time as the reader asks for more. */
|
|
355
|
-
export const issueList = (
|
|
368
|
+
export const issueList = (
|
|
369
|
+
clients: Clients,
|
|
370
|
+
place: RepoPlace,
|
|
371
|
+
filter: IssueFilter,
|
|
372
|
+
vocabulary: Vocabulary,
|
|
373
|
+
) => ({
|
|
356
374
|
queryKey: [...issueLists(place), filter] as const,
|
|
357
375
|
queryFn: ({ pageParam }: { readonly pageParam: string | undefined }) =>
|
|
358
|
-
issuePage(place, filter, vocabulary, pageParam),
|
|
376
|
+
issuePage(clients, place, filter, vocabulary, pageParam),
|
|
359
377
|
initialPageParam: firstPage,
|
|
360
378
|
getNextPageParam: (last: IssuePage) => last.next,
|
|
361
379
|
staleTime: 10_000,
|
|
@@ -375,12 +393,12 @@ const authorsPerPage = 100;
|
|
|
375
393
|
* first. The drop-in lists no repo's authors and searches no people, so the Author menu reads
|
|
376
394
|
* them from the repo's issue list, which holds its pull requests too, as GitHub's does.
|
|
377
395
|
*/
|
|
378
|
-
export const authorsOf = (place: RepoPlace) => ({
|
|
396
|
+
export const authorsOf = (clients: Clients, place: RepoPlace) => ({
|
|
379
397
|
queryKey: ['issue-authors', place.owner, place.repo] as const,
|
|
380
398
|
queryFn: async ({ pageParam }: { readonly pageParam: string | undefined }) => {
|
|
381
399
|
// `after` is the drop-in's cursor, which GitHub's types don't name: a spread passes it.
|
|
382
400
|
const paging = { ...{ per_page: authorsPerPage, after: pageParam } };
|
|
383
|
-
const answer = await github.GET('/repos/{owner}/{repo}/issues', {
|
|
401
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/issues', {
|
|
384
402
|
params: { path: place, query: { ...paging, state: 'all' } },
|
|
385
403
|
});
|
|
386
404
|
if (answer.data === undefined) throw failure("The authors didn't load", answer);
|
|
@@ -400,12 +418,16 @@ export const authorsOf = (place: RepoPlace) => ({
|
|
|
400
418
|
*/
|
|
401
419
|
export type Numbered = { readonly kind: 'issue' | 'pull'; readonly issue: Issue } | null;
|
|
402
420
|
|
|
421
|
+
/** The key of `issueAt`'s read of the issue `number`. */
|
|
422
|
+
export const issueKey = (place: RepoPlace, number: number) =>
|
|
423
|
+
['issue', place.owner, place.repo, number] as const;
|
|
424
|
+
|
|
403
425
|
/** The issue `number`, or what else the number is. */
|
|
404
|
-
export const issueAt = (place: RepoPlace, number: number) =>
|
|
426
|
+
export const issueAt = (clients: Clients, place: RepoPlace, number: number) =>
|
|
405
427
|
queryOptions({
|
|
406
|
-
queryKey:
|
|
428
|
+
queryKey: issueKey(place, number),
|
|
407
429
|
queryFn: async (): Promise<Numbered> => {
|
|
408
|
-
const answer = await github.GET('/repos/{owner}/{repo}/issues/{issue_number}', {
|
|
430
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/issues/{issue_number}', {
|
|
409
431
|
params: { path: { ...place, issue_number: number } },
|
|
410
432
|
});
|
|
411
433
|
if (answer.response.status === 404) return null;
|
|
@@ -426,13 +448,16 @@ export interface CommentPage {
|
|
|
426
448
|
}
|
|
427
449
|
|
|
428
450
|
/** An issue's comments, oldest first, 100 a page as the reader asks for more. */
|
|
429
|
-
export const commentsOf = (place: RepoPlace, number: number) => ({
|
|
451
|
+
export const commentsOf = (clients: Clients, place: RepoPlace, number: number) => ({
|
|
430
452
|
queryKey: ['issue-comments', place.owner, place.repo, number] as const,
|
|
431
453
|
queryFn: async ({ pageParam }: { readonly pageParam: string | undefined }) => {
|
|
432
454
|
const paging = { per_page: 100, after: pageParam };
|
|
433
|
-
const answer = await github.GET(
|
|
434
|
-
|
|
435
|
-
|
|
455
|
+
const answer = await clients.github.GET(
|
|
456
|
+
'/repos/{owner}/{repo}/issues/{issue_number}/comments',
|
|
457
|
+
{
|
|
458
|
+
params: { path: { ...place, issue_number: number }, query: { ...paging } },
|
|
459
|
+
},
|
|
460
|
+
);
|
|
436
461
|
if (answer.data === undefined) throw failure("The comments didn't load", answer);
|
|
437
462
|
|
|
438
463
|
const page: CommentPage = {
|
|
@@ -454,8 +479,8 @@ export interface Written {
|
|
|
454
479
|
}
|
|
455
480
|
|
|
456
481
|
/** Files a new issue, and answers its number. */
|
|
457
|
-
export const createIssue = async (place: RepoPlace, written: Written) => {
|
|
458
|
-
const answer = await github.POST('/repos/{owner}/{repo}/issues', {
|
|
482
|
+
export const createIssue = async (clients: Clients, place: RepoPlace, written: Written) => {
|
|
483
|
+
const answer = await clients.github.POST('/repos/{owner}/{repo}/issues', {
|
|
459
484
|
params: { path: place },
|
|
460
485
|
body: written,
|
|
461
486
|
});
|
|
@@ -481,14 +506,19 @@ type IssueBody = NonNullable<
|
|
|
481
506
|
>['content']['application/json'];
|
|
482
507
|
|
|
483
508
|
/** Changes the issue `number`, and answers it as it is after. */
|
|
484
|
-
export const changeIssue = async (
|
|
509
|
+
export const changeIssue = async (
|
|
510
|
+
clients: Clients,
|
|
511
|
+
place: RepoPlace,
|
|
512
|
+
number: number,
|
|
513
|
+
change: IssueChange,
|
|
514
|
+
) => {
|
|
485
515
|
const { labels, assignees, ...fields } = change;
|
|
486
516
|
const body: IssueBody = { ...fields };
|
|
487
517
|
if (labels !== undefined) body.labels = [...labels];
|
|
488
518
|
|
|
489
519
|
if (assignees !== undefined) body.assignees = [...assignees];
|
|
490
520
|
|
|
491
|
-
const answer = await github.PATCH('/repos/{owner}/{repo}/issues/{issue_number}', {
|
|
521
|
+
const answer = await clients.github.PATCH('/repos/{owner}/{repo}/issues/{issue_number}', {
|
|
492
522
|
params: { path: { ...place, issue_number: number } },
|
|
493
523
|
body,
|
|
494
524
|
});
|
|
@@ -498,8 +528,13 @@ export const changeIssue = async (place: RepoPlace, number: number, change: Issu
|
|
|
498
528
|
};
|
|
499
529
|
|
|
500
530
|
/** Comments on the issue `number`. */
|
|
501
|
-
export const addComment = async (
|
|
502
|
-
|
|
531
|
+
export const addComment = async (
|
|
532
|
+
clients: Clients,
|
|
533
|
+
place: RepoPlace,
|
|
534
|
+
number: number,
|
|
535
|
+
body: string,
|
|
536
|
+
) => {
|
|
537
|
+
const answer = await clients.github.POST('/repos/{owner}/{repo}/issues/{issue_number}/comments', {
|
|
503
538
|
params: { path: { ...place, issue_number: number } },
|
|
504
539
|
body: { body },
|
|
505
540
|
});
|
|
@@ -509,8 +544,8 @@ export const addComment = async (place: RepoPlace, number: number, body: string)
|
|
|
509
544
|
};
|
|
510
545
|
|
|
511
546
|
/** Rewrites the comment `id`. */
|
|
512
|
-
export const editComment = async (place: RepoPlace, id: number, body: string) => {
|
|
513
|
-
const answer = await github.PATCH('/repos/{owner}/{repo}/issues/comments/{comment_id}', {
|
|
547
|
+
export const editComment = async (clients: Clients, place: RepoPlace, id: number, body: string) => {
|
|
548
|
+
const answer = await clients.github.PATCH('/repos/{owner}/{repo}/issues/comments/{comment_id}', {
|
|
514
549
|
params: { path: { ...place, comment_id: id } },
|
|
515
550
|
body: { body },
|
|
516
551
|
});
|
|
@@ -527,8 +562,8 @@ const labelBody = (label: Label) => ({
|
|
|
527
562
|
});
|
|
528
563
|
|
|
529
564
|
/** Makes a label in the repo, so an issue can carry it. */
|
|
530
|
-
export const createLabel = async (place: RepoPlace, label: Label) => {
|
|
531
|
-
const answer = await github.POST('/repos/{owner}/{repo}/labels', {
|
|
565
|
+
export const createLabel = async (clients: Clients, place: RepoPlace, label: Label) => {
|
|
566
|
+
const answer = await clients.github.POST('/repos/{owner}/{repo}/labels', {
|
|
532
567
|
params: { path: place },
|
|
533
568
|
body: labelBody(label),
|
|
534
569
|
});
|
|
@@ -538,8 +573,8 @@ export const createLabel = async (place: RepoPlace, label: Label) => {
|
|
|
538
573
|
};
|
|
539
574
|
|
|
540
575
|
/** Changes the label named `name` to `label`, which may rename it. */
|
|
541
|
-
export const editLabel = async (place: RepoPlace, name: string, label: Label) => {
|
|
542
|
-
const answer = await github.PATCH('/repos/{owner}/{repo}/labels/{name}', {
|
|
576
|
+
export const editLabel = async (clients: Clients, place: RepoPlace, name: string, label: Label) => {
|
|
577
|
+
const answer = await clients.github.PATCH('/repos/{owner}/{repo}/labels/{name}', {
|
|
543
578
|
params: { path: { ...place, name } },
|
|
544
579
|
body: { new_name: label.name, color: label.color, description: label.description ?? '' },
|
|
545
580
|
});
|
|
@@ -548,19 +583,133 @@ export const editLabel = async (place: RepoPlace, name: string, label: Label) =>
|
|
|
548
583
|
return labelOf(answer.data);
|
|
549
584
|
};
|
|
550
585
|
|
|
586
|
+
/** Deletes the label named `name`: the issues and pull requests that held it show it no more. */
|
|
587
|
+
export const deleteLabel = async (clients: Clients, place: RepoPlace, name: string) => {
|
|
588
|
+
const answer = await clients.github.DELETE('/repos/{owner}/{repo}/labels/{name}', {
|
|
589
|
+
params: { path: { ...place, name } },
|
|
590
|
+
});
|
|
591
|
+
if (!answer.response.ok) throw failure("The label wasn't deleted", answer);
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
/** A milestone as its page shows it: its description, due date and how far along its issues are. */
|
|
595
|
+
export interface MilestoneDetail extends Milestone {
|
|
596
|
+
readonly description: string | null;
|
|
597
|
+
/** When it's due, as the drop-in answers it, or `null`. */
|
|
598
|
+
readonly dueOn: string | null;
|
|
599
|
+
readonly closedAt: string | null;
|
|
600
|
+
/** Its open and closed issues and pull requests. */
|
|
601
|
+
readonly open: number;
|
|
602
|
+
readonly closed: number;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
type RestMilestone = components['schemas']['milestone'];
|
|
606
|
+
|
|
607
|
+
const milestoneOf = (held: RestMilestone): MilestoneDetail => ({
|
|
608
|
+
number: held.number,
|
|
609
|
+
title: held.title,
|
|
610
|
+
state: held.state,
|
|
611
|
+
description: held.description === null || held.description === '' ? null : held.description,
|
|
612
|
+
dueOn: held.due_on,
|
|
613
|
+
closedAt: held.closed_at,
|
|
614
|
+
open: held.open_issues,
|
|
615
|
+
closed: held.closed_issues,
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* The repo's milestones, open and closed, in the drop-in's order, soonest due first. The drop-in
|
|
620
|
+
* keeps at most `pagesMost` pages of them. Its key is under the vocabulary's, so whatever reads the
|
|
621
|
+
* vocabulary again, such as a milestone made in an issue's picker, reads these again too.
|
|
622
|
+
*/
|
|
623
|
+
export const milestonesOf = (clients: Clients, place: RepoPlace) =>
|
|
624
|
+
queryOptions({
|
|
625
|
+
queryKey: [...vocabularyKey(place), 'milestones'],
|
|
626
|
+
queryFn: async () => {
|
|
627
|
+
const read = await everyPage(async (after) => {
|
|
628
|
+
const answer = await clients.github.GET('/repos/{owner}/{repo}/milestones', {
|
|
629
|
+
params: { path: place, query: { ...{ per_page: 100, after }, state: 'all' } },
|
|
630
|
+
});
|
|
631
|
+
if (answer.data === undefined) throw failure("The milestones didn't load", answer);
|
|
632
|
+
|
|
633
|
+
return { rows: answer.data.map(milestoneOf), link: answer.response.headers.get('link') };
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
return read.rows;
|
|
637
|
+
},
|
|
638
|
+
staleTime: 30_000,
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
/** A milestone's fields as a person writes them: its due date as `YYYY-MM-DD`, a day in UTC. */
|
|
642
|
+
export interface MilestoneFields {
|
|
643
|
+
readonly title: string;
|
|
644
|
+
readonly description: string | null;
|
|
645
|
+
readonly due: string | null;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/** A due date's field, as a string GitHub's types can't check against their own. */
|
|
649
|
+
const dueKey: string = 'due_on';
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* The fields as a write sends them: no description is an empty one, and a due date is that day's
|
|
653
|
+
* start in UTC, as GitHub stores one. GitHub's types take no `null` for a due date, which GitHub
|
|
654
|
+
* and the drop-in read as none, so a computed key passes it.
|
|
655
|
+
*/
|
|
656
|
+
const milestoneBody = ({ title, description, due }: MilestoneFields) => ({
|
|
657
|
+
title,
|
|
658
|
+
description: description ?? '',
|
|
659
|
+
[dueKey]: due === null ? null : `${due}T00:00:00Z`,
|
|
660
|
+
});
|
|
661
|
+
|
|
551
662
|
/** Makes a milestone in the repo, so an issue can be in it. */
|
|
552
|
-
export const createMilestone = async (
|
|
553
|
-
|
|
663
|
+
export const createMilestone = async (
|
|
664
|
+
clients: Clients,
|
|
665
|
+
place: RepoPlace,
|
|
666
|
+
fields: MilestoneFields,
|
|
667
|
+
) => {
|
|
668
|
+
const answer = await clients.github.POST('/repos/{owner}/{repo}/milestones', {
|
|
554
669
|
params: { path: place },
|
|
555
|
-
body:
|
|
670
|
+
body: milestoneBody(fields),
|
|
556
671
|
});
|
|
557
672
|
if (answer.data === undefined) throw failure("The milestone wasn't created", answer);
|
|
558
673
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
title: answer.data.title,
|
|
562
|
-
state: answer.data.state,
|
|
563
|
-
};
|
|
674
|
+
return milestoneOf(answer.data);
|
|
675
|
+
};
|
|
564
676
|
|
|
565
|
-
|
|
677
|
+
/** Changes the milestone `number` to `fields`, or closes or reopens it as `state` says. */
|
|
678
|
+
export const editMilestone = async (
|
|
679
|
+
clients: Clients,
|
|
680
|
+
place: RepoPlace,
|
|
681
|
+
number: number,
|
|
682
|
+
change: MilestoneFields | { readonly state: 'open' | 'closed' },
|
|
683
|
+
) => {
|
|
684
|
+
const answer = await clients.github.PATCH('/repos/{owner}/{repo}/milestones/{milestone_number}', {
|
|
685
|
+
params: { path: { ...place, milestone_number: number } },
|
|
686
|
+
body: 'state' in change ? { state: change.state } : milestoneBody(change),
|
|
687
|
+
});
|
|
688
|
+
if (answer.data === undefined) throw failure("The milestone didn't change", answer);
|
|
689
|
+
|
|
690
|
+
return milestoneOf(answer.data);
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
/** Deletes the milestone `number`: its issues and pull requests stay, in no milestone. */
|
|
694
|
+
export const deleteMilestone = async (clients: Clients, place: RepoPlace, number: number) => {
|
|
695
|
+
const answer = await clients.github.DELETE(
|
|
696
|
+
'/repos/{owner}/{repo}/milestones/{milestone_number}',
|
|
697
|
+
{
|
|
698
|
+
params: { path: { ...place, milestone_number: number } },
|
|
699
|
+
},
|
|
700
|
+
);
|
|
701
|
+
if (!answer.response.ok) throw failure("The milestone wasn't deleted", answer);
|
|
566
702
|
};
|
|
703
|
+
|
|
704
|
+
/** The reads that show issues and pull requests, by the first part of their keys. */
|
|
705
|
+
const issueReads = new Set<unknown>(['issue', 'issues', 'pull', 'pulls']);
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Reads again every issue and pull request of the repo, which then show a label or a milestone as
|
|
709
|
+
* it now is.
|
|
710
|
+
*/
|
|
711
|
+
export const readIssuesAgain = (client: QueryClient, place: RepoPlace) =>
|
|
712
|
+
client.invalidateQueries({
|
|
713
|
+
predicate: ({ queryKey: [kind, owner, repo] }) =>
|
|
714
|
+
issueReads.has(kind) && owner === place.owner && repo === place.repo,
|
|
715
|
+
});
|
|
@@ -5,6 +5,7 @@ import { toast } from 'sonner';
|
|
|
5
5
|
|
|
6
6
|
import { cn } from '#/lib/cn';
|
|
7
7
|
|
|
8
|
+
import { useClients } from '../clients/clients.ts';
|
|
8
9
|
import type { RepoPlace } from '../code/places.ts';
|
|
9
10
|
import { Alert, AlertDescription } from '../components/ui/alert.tsx';
|
|
10
11
|
import { Button } from '../components/ui/button.tsx';
|
|
@@ -30,7 +31,7 @@ import {
|
|
|
30
31
|
InputGroupInput,
|
|
31
32
|
InputGroupText,
|
|
32
33
|
} from '../components/ui/input-group.tsx';
|
|
33
|
-
import { createLabel, editLabel,
|
|
34
|
+
import { createLabel, editLabel, readIssuesAgain, vocabularyKey, type Label } from './issues.ts';
|
|
34
35
|
import { LabelBadge } from './parts.tsx';
|
|
35
36
|
|
|
36
37
|
/** The swatches the colour offers: GitHub's label picker's sixteen, dark row then light. */
|
|
@@ -68,9 +69,6 @@ const randomColor = () =>
|
|
|
68
69
|
.toString(16)
|
|
69
70
|
.padStart(6, '0');
|
|
70
71
|
|
|
71
|
-
/** The reads that show issues' and pull requests' labels, by the first part of their keys. */
|
|
72
|
-
const labelled = new Set<unknown>(['issue', 'issues', 'pull', 'pulls']);
|
|
73
|
-
|
|
74
72
|
/** The longest name and description GitHub keeps for a label. */
|
|
75
73
|
const longest = { name: 50, description: 100 } as const;
|
|
76
74
|
|
|
@@ -146,6 +144,7 @@ function LabelForm({
|
|
|
146
144
|
readonly onSaved: (label: Label) => void;
|
|
147
145
|
readonly onCancel: () => void;
|
|
148
146
|
}) {
|
|
147
|
+
const clients = useClients();
|
|
149
148
|
const client = useQueryClient();
|
|
150
149
|
const [name, setName] = useState(editing?.name ?? typedName.trim());
|
|
151
150
|
const [description, setDescription] = useState(editing?.description ?? '');
|
|
@@ -176,20 +175,18 @@ function LabelForm({
|
|
|
176
175
|
|
|
177
176
|
const save = useMutation({
|
|
178
177
|
mutationFn: () =>
|
|
179
|
-
editing === undefined
|
|
178
|
+
editing === undefined
|
|
179
|
+
? createLabel(clients, place, label)
|
|
180
|
+
: editLabel(clients, place, editing.name, label),
|
|
180
181
|
onSuccess: async (saved) => {
|
|
181
182
|
toast.success(
|
|
182
183
|
editing === undefined ? `Created the label ${saved.name}` : `Saved the label ${saved.name}`,
|
|
183
184
|
);
|
|
184
185
|
onSaved(saved);
|
|
185
|
-
await client.invalidateQueries({ queryKey:
|
|
186
|
+
await client.invalidateQueries({ queryKey: vocabularyKey(place) });
|
|
186
187
|
|
|
187
188
|
// A change shows on every issue and pull request that holds the label, so each is read again.
|
|
188
|
-
if (editing !== undefined)
|
|
189
|
-
await client.invalidateQueries({
|
|
190
|
-
predicate: ({ queryKey: [kind, owner, repo] }) =>
|
|
191
|
-
labelled.has(kind) && owner === place.owner && repo === place.repo,
|
|
192
|
-
});
|
|
189
|
+
if (editing !== undefined) await readIssuesAgain(client, place);
|
|
193
190
|
},
|
|
194
191
|
});
|
|
195
192
|
|