Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The mod uses GitHub CLI (`gh`) on the machine hosting the repository, so local a
- **Automatic list refresh** — while the GitHub sidebar is visible, check for changes every 60 seconds using ETags; refresh expanded groups only when changed. Showing it again refreshes immediately. While the PRs tab and local group are visible and expanded, local branches are re-read each minute; only a changed branch snapshot or an explicit refresh reissues their GraphQL batch.
- **Native detail tabs** — open different issues and PRs in separate tabs; selecting an already-open item reuses its tab. Contents remain session-only.
- **Discussion reader** — read Markdown descriptions, comments, and reaction counts in individual cards.
- **Automatic discussion refresh** — check the visible issue tab every 10 seconds using ETags; keep unsent comments through refreshes, stop polling hidden tabs, and refresh immediately when shown again.
- **Automatic discussion refresh** — check the visible issue or PR tab every 10 seconds using ETags; PRs also conditionally check discussion, review, inline-comment and commit-check resources rather than assuming the PR validator covers them; keep unsent comments through refreshes, stop polling hidden tabs, and refresh immediately when shown again.
- **Issue and PR links** — links to the repository's issues and PRs open the appropriate reader in the same tab, with **←** to go back across both kinds; `#123` references open as issue links. Other links open in your browser.
- **Comment, close and reopen** — post a new comment (⌘/Ctrl+Enter for issues) or close and reopen an issue or PR from its tab; mark a draft PR **Ready for Review**. The sidebar's groups and other readers update immediately after PR state changes; failed comments keep unsent text.
- **Issue and PR metadata** — view colored labels, assignees, linked Projects, and milestones. PR descriptions also show reviewers with their review states and the source and target branches.
Expand Down
75 changes: 69 additions & 6 deletions mods/github/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/github/io/pulls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ import {
import type { RemoteRepo } from "../core/remote.ts";
import { parseThreads, type ReviewThread, type ThreadNode } from "../core/review-threads.ts";
import { written } from "./changes.ts";
import { api, eachPage, GhError, graphql, mutate } from "./gh.ts";
import { api, changes, eachPage, GhError, graphql, mutate } from "./gh.ts";
import type { LocalBranches } from "./git.ts";

export const pullListChanges = (repo: string, etag: string | null, on: string | null) =>
changes(`repos/${repo}/pulls?state=all&sort=updated&per_page=1`, etag, on);

export const pullChanges = (repo: string, number: number, etag: string | null, on: string | null) =>
changes(`repos/${repo}/pulls/${number}`, etag, on);

/** One page of a group, asked with the gh on `on`, whose account is `login` (for the searches). */
export async function pullPage(
kind: PullGroupKind,
Expand Down
18 changes: 12 additions & 6 deletions src/github/views/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DetailTabs } from "../io/detail-tabs.ts";
import * as gh from "../io/gh.ts";
import { listChanges } from "../io/issues.ts";
import * as known from "../io/known.ts";
import { pullListChanges } from "../io/pulls.ts";
import type { ListHost } from "./groups.ts";
import { issueList } from "./issues.ts";
import { pullList } from "./pulls.ts";
Expand Down Expand Up @@ -90,19 +91,22 @@ export class Panel implements Role {
const current = () => run === this.latest && this.poll.current(request);
let change: Change | undefined;
try {
change = await listChanges(`${r.remote.owner}/${r.remote.repo}`, request.etag, r.on);
change = await (this.tab === "prs" ? pullListChanges : listChanges)(
`${r.remote.owner}/${r.remote.repo}`,
request.etag,
r.on,
);
if (!current()) return;
this.checkedAt = Date.now();
this.checkFailed = false;
} catch {
if (current()) this.checkFailed = true;
} finally {
if (current()) {
if (change?.changed || refresh) this.issues.load(cx, true);
// PR lists have their own change check later (#34); a refresh asks the shown tab's groups now.
// Two of them are searches (30 a minute for the whole account, ADR 0006): kept pages under a minute
// old are reused, and only ↻ asks them all again.
if (refresh && this.tab === "prs") this.pulls.load(cx, refresh === "asked");
if (this.tab === "issues" && (change?.changed || refresh)) this.issues.load(cx, true);
// Reload only the shown tab's expanded groups.
// Two groups use search: only probe changes or an explicit/show refresh re-ask them.
if ((change?.changed || refresh) && this.tab === "prs") this.pulls.load(cx, true);
// Every finished check redraws: the footer shows a failed check and its recovery.
cx.notify();
}
Expand Down Expand Up @@ -355,6 +359,8 @@ export class Panel implements Role {
.on_mouse_down("left", stop)
.on_click((_e, cx) => {
this.tab = id;
this.poll.invalidate();
this.check(cx, "shown");
// A tab that failed to open was asked from the other list.
this.openFailure = null;
if (id === "prs") this.pulls.load(cx);
Expand Down
69 changes: 64 additions & 5 deletions src/github/views/pull.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// A PR reader switches between its published discussion and a changed file's read-only unified diff.
import { h_flex, v_flex } from "gpui-base";
import { type Context, div, type Element } from "gpui-kit";
import { type AsyncContext, type Context, div, type Element } from "gpui-kit";
import { checkSummary } from "../core/checks.ts";
import { type DetailRef, detailUrl } from "../core/detail.ts";
import { type DetailRef, detailKey, detailUrl } from "../core/detail.ts";
import { type MergeMethod, selectedMergeMethod } from "../core/merge.ts";
import { ConditionalPoll } from "../core/polling.ts";
import type { Projects } from "../core/projects.ts";
import type { PullDetail } from "../core/pull-detail.ts";
import type { ReviewState } from "../core/reviewers.ts";
import { Notices } from "../io/changes.ts";
import { detailLocation } from "../io/detail-tabs.ts";
import * as gh from "../io/gh.ts";
import { deletePullBranch, mergePull, readPull, readyPull, setPullState } from "../io/pulls.ts";
import { deletePullBranch, mergePull, pullChanges, readPull, readyPull, setPullState } from "../io/pulls.ts";
import {
type DetailHost,
type DetailLayout,
Expand Down Expand Up @@ -67,8 +68,59 @@ export class Pull {
private missingFile: Extract<DiffSubject, { missing: true }> | null = null;
private expandedActivity = new Set<string>();

init(): void {
private polling = new ConditionalPoll();
private validators = new Map<string, string | null>();

init(cx: AsyncContext): void {
this.diff.init();
cx.timer.every(10_000, (cx) => {
const shown = this.syncPolling();
if (!this.writing && !this.entry?.loading) this.check(cx, shown);
});
}

private syncPolling(): boolean {
const place = detailLocation(this.host.reader);
return this.polling.sync(
this.ref && place ? `${place.on}\n${place.pane}\n${detailKey(this.ref)}` : null,
Boolean(place?.visible) && this.host.active("pr"),
);
}

private check(cx: Context, force = false): void {
this.syncPolling();
const request = this.polling.begin(force);
const ref = this.ref;
const place = detailLocation(this.host.reader);
if (!request || !ref || !place) return;
cx.spawn(async (cx) => {
let completed: import("../core/gh.ts").Change | undefined;
try {
const change = await pullChanges(ref.repo, ref.number, request.etag, place.on);
this.syncPolling();
if (!this.polling.current(request)) return;
// PR validators are not assumed to cover discussions or commit checks.
const paths = [`issues/${ref.number}`, `pulls/${ref.number}/reviews`, `pulls/${ref.number}/comments`];
const sha = this.entry?.pull?.headSha;
if (sha) paths.push(`commits/${sha}/check-runs`, `commits/${sha}/statuses`);
const replies = await Promise.all(
paths.map(async (path) => ({
path,
change: await gh.changes(`repos/${ref.repo}/${path}`, this.validators.get(path) ?? null, place.on),
})),
);
if (!detailLocation(this.host.reader)?.visible) this.syncPolling();
if (!this.polling.current(request)) return;
const changed = change.changed || replies.some((r) => r.change.changed);
if (force || changed) this.load(cx);
for (const reply of replies) if (reply.change.changed) this.validators.set(reply.path, reply.change.etag);
completed = change;
} catch {
// Keep the discussion and drafts on transient failures; retry next tick.
} finally {
this.polling.finish(request, completed);
}
});
}
private readonly host: DetailHost;
private metadata = new DetailMetadata();
Expand All @@ -86,6 +138,8 @@ export class Pull {
this.stateFailure = "";
this.metadata.expanded = false;
this.ref = ref;
this.validators.clear();
this.polling.invalidate();
this.entry = null;
this.files = null;
this.discussions = null;
Expand Down Expand Up @@ -126,7 +180,11 @@ export class Pull {
entry.on = place.on;
loadProjects(cx, ref, place.on, entry, current);
} catch (e) {
if (current()) entry.failure = readFailure(ref, e);
if (current()) {
entry.failure = readFailure(ref, e);
this.polling.invalidate();
this.validators.clear();
}
} finally {
if (current()) {
entry.loading = false;
Expand All @@ -137,6 +195,7 @@ export class Pull {
}

render(cx: Context, layout: DetailLayout): Element[] {
if (this.syncPolling()) this.check(cx, true);
const on = detailLocation(this.host.reader)?.on;
if (
this.notices
Expand Down
2 changes: 1 addition & 1 deletion src/github/views/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Reader implements Role {

init(cx: AsyncContext): void {
this.issue.init(cx);
this.pull.init();
this.pull.init(cx);
cx.spawn(async (cx) => {
for (;;) {
const ref = detailCommand(await nextCommand(), this.reader);
Expand Down
23 changes: 23 additions & 0 deletions test/io/pull-poll.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { afterEach, expect, test } from "bun:test";
import { pullChanges, pullListChanges } from "../../src/github/io/pulls.ts";
import { machine, reset } from "../fake-herdr.ts";

afterEach(reset);
for (const [name, path, read] of [
[
"list",
"pulls?state=all&sort=updated&per_page=1",
(tag: string | null) => pullListChanges("owner/repo", tag, "remote"),
],
["detail", "pulls/12", (tag: string | null) => pullChanges("owner/repo", 12, tag, "remote")],
] as const) {
test(`${name}: changed and unchanged responses use the remote validator`, async () => {
const command = `~$ gh api repos/owner/repo/${path} --include`;
machine("remote", { [command]: { stdout: 'HTTP/2.0 200 OK\r\nETag: W/"one"\r\n\r\n{}' } });
expect(await read(null)).toEqual({ changed: true, etag: 'W/"one"' });
machine("remote", {
[`${command} -H If-None-Match: W/"one"`]: { stdout: "HTTP/2.0 304 Not Modified\r\n\r\n", code: 1 },
});
expect(await read('W/"one"')).toEqual({ changed: false });
});
}
Loading