@andrioid/paseo-attention-span 0.4.9 → 0.4.10
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/OVERVIEW.md +3 -1
- package/client/attention-screen.tsx +33 -17
- package/client/card.tsx +31 -8
- package/client/coverage-settings.tsx +36 -1
- package/client/entity.tsx +118 -0
- package/client/feedback.tsx +2 -2
- package/client/icons.ts +5 -0
- package/client/next-up.tsx +145 -74
- package/client/sheet.tsx +91 -10
- package/client/ui.tsx +97 -6
- package/docs/architecture.md +12 -6
- package/docs/screenshots/desktop-dark-doing-acknowledge.png +0 -0
- package/docs/screenshots/desktop-dark-doing-clear.png +0 -0
- package/docs/screenshots/desktop-dark-doing-issue-sheet.png +0 -0
- package/docs/screenshots/desktop-dark-doing-reviewers.png +0 -0
- package/docs/screenshots/desktop-dark-doing-sheet.png +0 -0
- package/docs/screenshots/desktop-dark-doing.png +0 -0
- package/docs/screenshots/desktop-dark-history-reviewed.png +0 -0
- package/docs/screenshots/desktop-dark-history.png +0 -0
- package/docs/screenshots/desktop-dark-next-up.png +0 -0
- package/docs/screenshots/desktop-dark-settings.png +0 -0
- package/docs/screenshots/desktop-dark-waiting-too-long.png +0 -0
- package/docs/screenshots/desktop-dark-waiting.png +0 -0
- package/docs/screenshots/phone-dark-doing.png +0 -0
- package/docs/screenshots/phone-light-next-up-filtered.png +0 -0
- package/index.server.ts +2 -0
- package/package.json +1 -1
- package/requirements.yaml +4 -2
- package/server/classify.ts +56 -12
- package/server/details.ts +3 -2
- package/server/fixture.ts +33 -9
- package/server/gh.ts +29 -12
- package/server/github-types.ts +19 -2
- package/server/projects.ts +47 -0
- package/server/queries.ts +41 -6
- package/server/service.ts +138 -22
- package/server/store.ts +2 -0
- package/server/view.ts +2 -0
- package/shared/attention.ts +57 -0
- package/shared/opening.ts +31 -0
- package/shared/rpc.ts +5 -1
package/server/queries.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UnclaimedSource } from "../shared/attention";
|
|
1
|
+
import type { GithubColor, UnclaimedSource } from "../shared/attention";
|
|
2
2
|
import type { AttentionConfig } from "../shared/config";
|
|
3
3
|
import type { PickableNode, PullRequestNode, RequiredChecks } from "./github-types";
|
|
4
4
|
import type { IssueRef } from "./references";
|
|
@@ -56,6 +56,18 @@ const FRAGMENTS: Record<string, string> = {
|
|
|
56
56
|
issueType { name }
|
|
57
57
|
issueFieldValues(first: 20) { nodes { ... on IssueFieldSingleSelectValue { name field { ... on IssueFieldCommon { name } } } } }
|
|
58
58
|
closedByPullRequestsReferences(first: 5, includeClosedPrs: false) { nodes { number url state author { login } } }
|
|
59
|
+
}`,
|
|
60
|
+
// Needs read:project, so only asked for once the login is known to have it; without it GitHub fails the whole search [NXT-12].
|
|
61
|
+
// Archived items are off the board, so they don't count. Each board's Status options come once per board, from
|
|
62
|
+
// projectStatusesQuery, not with every issue on it [GH-01]. hasNextPage says when the list was cut short.
|
|
63
|
+
projects: `fragment projects on Issue {
|
|
64
|
+
projectItems(first: 10, includeArchived: false) {
|
|
65
|
+
pageInfo { hasNextPage }
|
|
66
|
+
nodes {
|
|
67
|
+
project { id title closed }
|
|
68
|
+
status: fieldValueByName(name: "Status") { ... on ProjectV2ItemFieldSingleSelectValue { name color } }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
59
71
|
}`,
|
|
60
72
|
pr: `fragment pr on PullRequest {
|
|
61
73
|
id number title url body isDraft createdAt updatedAt
|
|
@@ -79,10 +91,14 @@ const FRAGMENTS: Record<string, string> = {
|
|
|
79
91
|
}`,
|
|
80
92
|
};
|
|
81
93
|
|
|
94
|
+
// Next up's searches, which read the projects of what they find when they can [NXT-12].
|
|
95
|
+
const PICKABLE_SEARCHES: readonly SearchName[] = ["assigned", "unclaimed"];
|
|
96
|
+
|
|
82
97
|
// A query for some searches, as aliases named after them, with only the fragments they use; GitHub rejects unused ones.
|
|
83
98
|
// GitHub runs the searches in one request one after another, so the live ones go out as separate requests in parallel [GH-01].
|
|
84
|
-
export function searchQuery(names: readonly SearchName[], withViewer = false): string {
|
|
85
|
-
const
|
|
99
|
+
export function searchQuery(names: readonly SearchName[], withViewer = false, { projects = false } = {}): string {
|
|
100
|
+
const nodes = (name: SearchName) => `${SEARCHES[name].nodes}${projects && PICKABLE_SEARCHES.includes(name) ? " ...projects" : ""}`;
|
|
101
|
+
const fields = names.map((name) => ` ${name}: search(type: ISSUE, query: $${name}, first: ${SEARCHES[name].first}) {\n nodes { ${nodes(name)} }\n }`);
|
|
86
102
|
const used = new Set<string>();
|
|
87
103
|
const collect = (text: string) => {
|
|
88
104
|
for (const [, name] of text.matchAll(/\.\.\.(\w+)/g)) {
|
|
@@ -212,11 +228,30 @@ export function detailsQuery(prs: PullRequestNode[], orgs: string[], refs: Issue
|
|
|
212
228
|
return { query: `query Details {\n${fields.join("\n")}\n}`, compares };
|
|
213
229
|
}
|
|
214
230
|
|
|
215
|
-
// An org's single-select issue fields with their options, in the org's order [NXT-02].
|
|
231
|
+
// An org's single-select issue fields with their options, in the org's order [NXT-02], and the colors it gave them [NXT-10].
|
|
216
232
|
const orgFields = (alias: string, org: string) => `${alias}: organization(login: ${JSON.stringify(org)}) {
|
|
217
|
-
issueFields(first: 50) { nodes { ... on IssueFieldSingleSelect { name options { name } } } }
|
|
233
|
+
issueFields(first: 50) { nodes { ... on IssueFieldSingleSelect { name options { name color } } } }
|
|
218
234
|
}`;
|
|
219
|
-
export type OrgFields = { issueFields?: { nodes: { name?: string; options?: { name: string }[] }[] } } | null;
|
|
235
|
+
export type OrgFields = { issueFields?: { nodes: { name?: string; options?: { name: string; color?: GithubColor }[] }[] } } | null;
|
|
236
|
+
|
|
237
|
+
// The Status options of the boards Next up's issues are on, in each board's order, once per board [NXT-03, GH-01].
|
|
238
|
+
// Asked apart from the details request, so a board that can't be read costs only the filter's statuses.
|
|
239
|
+
export function projectStatusesQuery(ids: string[]): string {
|
|
240
|
+
const fields = ids.map(
|
|
241
|
+
(id, index) => `b${index}: node(id: ${JSON.stringify(id)}) { ... on ProjectV2 { field(name: "Status") { ... on ProjectV2SingleSelectField { options { name color } } } } }`,
|
|
242
|
+
);
|
|
243
|
+
return `query ProjectStatuses {\n${fields.join("\n")}\n}`;
|
|
244
|
+
}
|
|
245
|
+
export type ProjectStatusesResult = Record<string, { field?: { options?: { name: string; color: GithubColor }[] } | null } | null>;
|
|
246
|
+
|
|
247
|
+
// Answers only when the login may read projects; without read:project GitHub refuses it, which is how Next up tells [NXT-12].
|
|
248
|
+
// It must ask for a field read:project guards: totalCount isn't, so a token without the scope answered it. GitHub checks
|
|
249
|
+
// the scope against the query, not the data, so it's refused even for someone with no projects (seen 2026-11-11). One
|
|
250
|
+
// node keeps it small and within GitHub's documented 1–100.
|
|
251
|
+
export const PROJECTS_PROBE = "query ProjectsProbe { viewer { projectsV2(first: 1) { nodes { id } } } }";
|
|
252
|
+
|
|
253
|
+
// How GitHub says the login lacks read:project.
|
|
254
|
+
export const missingProjectScope = (error: unknown): boolean => /read:project/i.test(typeof error === "string" ? error : ((error as Error)?.message ?? ""));
|
|
220
255
|
|
|
221
256
|
// The fields settings offers for Next up, from every org it might pick from [NXT-04]. An owner that's a person fails only its own field.
|
|
222
257
|
export function issueFieldsQuery(orgs: string[]): string {
|
package/server/service.ts
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
|
-
import type { Attention, AttentionView, FeedId, FeedStatus, Item, Reviewer } from "../shared/attention";
|
|
1
|
+
import type { Attention, AttentionView, FeedId, FeedStatus, GithubColor, Item, ProjectsAccess, Reviewer } from "../shared/attention";
|
|
2
2
|
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
3
3
|
import { AttentionConfig, type FieldRole, githubRepoOf, nextUpField } from "../shared/config";
|
|
4
4
|
import type { IssueField } from "../shared/setup";
|
|
5
|
-
import { classify, classifyHistory } from "./classify";
|
|
6
|
-
import {
|
|
5
|
+
import { classify, classifyHistory, issueBoardIds } from "./classify";
|
|
6
|
+
import { probeAnswer, projectsFailure, projectsWarning, searchWithProjects } from "./projects";
|
|
7
|
+
import { FIXTURE, graphql, graphqlResult } from "./gh";
|
|
7
8
|
import { fixture, FIXTURE_AGENTS, FIXTURE_ISSUE_FIELDS } from "./fixture";
|
|
8
9
|
import type { Details, HistoryResult, LinkedIssue, LiveResult, MergeStateStatus, PullRequestNode } from "./github-types";
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
type CheckContext,
|
|
12
|
+
detailsQuery,
|
|
13
|
+
HISTORY_SEARCHES,
|
|
14
|
+
issueFieldsQuery,
|
|
15
|
+
type OrgFields,
|
|
16
|
+
MERGE_STATE_BATCH,
|
|
17
|
+
mergeStateQuery,
|
|
18
|
+
mergeUnclaimed,
|
|
19
|
+
prKey,
|
|
20
|
+
PROJECTS_PROBE,
|
|
21
|
+
projectStatusesQuery,
|
|
22
|
+
type ProjectStatusesResult,
|
|
23
|
+
requiredChecks,
|
|
24
|
+
type SearchName,
|
|
25
|
+
searchQuery,
|
|
26
|
+
searchVariables,
|
|
27
|
+
type UnclaimedSearch,
|
|
28
|
+
unclaimedSearches,
|
|
29
|
+
} from "./queries";
|
|
10
30
|
import { toLookUp } from "./references";
|
|
11
31
|
import { loadConfig, loadState, moveOldFiles, saveCodeRepo, saveCoverage, saveFollowThreads, saveNextUpFields, saveNextUpSources, saveState, State } from "./store";
|
|
12
32
|
import { applyPending, buildView, doneItem, type Effect, isPending, SETTLE_MS } from "./view";
|
|
@@ -15,6 +35,18 @@ import { applyPending, buildView, doneItem, type Effect, isPending, SETTLE_MS }
|
|
|
15
35
|
const HISTORY_MAX_AGE_SECONDS = 24 * 60 * 60;
|
|
16
36
|
// A failed refresh is retried at most this often, except on ⟳.
|
|
17
37
|
const RETRY_MS = 5 * 60_000;
|
|
38
|
+
// Whether projects can be read is asked again at most this often, unless Settings asks [NXT-12].
|
|
39
|
+
const PROJECTS_CHECK_MS = 60 * 60_000;
|
|
40
|
+
// The check waits this long at most, as the refresh waits on it.
|
|
41
|
+
const PROBE_TIMEOUT_MS = 10_000;
|
|
42
|
+
// A search with projects, or a batch of boards' statuses, waits this long at most before the refresh goes on without them.
|
|
43
|
+
const PROJECTS_SEARCH_TIMEOUT_MS = 20_000;
|
|
44
|
+
const BOARDS_PER_REQUEST = 50;
|
|
45
|
+
// Batches of boards asked at once, so many boards don't burst requests [GH-01].
|
|
46
|
+
const BOARD_BATCHES_AT_ONCE = 2;
|
|
47
|
+
|
|
48
|
+
// Where gh's token comes from: an environment variable, which gh reads before its own login, or that login [NXT-12].
|
|
49
|
+
const tokenSource = (): ProjectsAccess["token"] => (process.env.GH_TOKEN ? "GH_TOKEN" : process.env.GITHUB_TOKEN ? "GITHUB_TOKEN" : "gh");
|
|
18
50
|
|
|
19
51
|
// What a change does to the lists: an effect, Finished (merged or closed, so off the lists and maybe into History), or nothing.
|
|
20
52
|
export type Change = Effect | { kind: "finished"; notPlanned?: boolean } | null;
|
|
@@ -40,6 +72,9 @@ export class AttentionService {
|
|
|
40
72
|
private timer: ReturnType<typeof setInterval> | null = null;
|
|
41
73
|
private followUps: Partial<Record<FeedId, ReturnType<typeof setTimeout>>> = {};
|
|
42
74
|
private intervalMinutes = 0;
|
|
75
|
+
private projects: { access: ProjectsAccess; checkedAt: number } = { access: { state: "unknown", token: tokenSource() }, checkedAt: 0 };
|
|
76
|
+
private projectsProbe: Promise<ProjectsAccess> | null = null;
|
|
77
|
+
private projectsWarning: string | undefined;
|
|
43
78
|
// The app's connection to Paseo, from its last request; background refreshes have none of their own.
|
|
44
79
|
private paseo: PluginHandlerContext["paseo"] | null = null;
|
|
45
80
|
|
|
@@ -154,6 +189,11 @@ export class AttentionService {
|
|
|
154
189
|
await this.save();
|
|
155
190
|
}
|
|
156
191
|
|
|
192
|
+
async setProjectFilter(projects: string[]): Promise<void> {
|
|
193
|
+
this.state.projectFilter = projects;
|
|
194
|
+
await this.save();
|
|
195
|
+
}
|
|
196
|
+
|
|
157
197
|
// "Not now" on an update notice holds until a newer one [UPD-01].
|
|
158
198
|
get skippedUpdate(): string | null {
|
|
159
199
|
return this.state.skippedUpdate;
|
|
@@ -269,23 +309,70 @@ export class AttentionService {
|
|
|
269
309
|
return classifyHistory(await graphql<HistoryResult>(searchQuery(HISTORY_SEARCHES), this.variables(HISTORY_SEARCHES, now)));
|
|
270
310
|
}
|
|
271
311
|
|
|
312
|
+
// Whether the gh login may read projects, asked at most hourly, or now when Settings asks [NXT-12]. On only when GitHub
|
|
313
|
+
// actually returns the viewer's projects, as a partial answer with errors isn't a yes. Any attempt counts toward the
|
|
314
|
+
// hour, so an outage doesn't add a probe to every refresh, and it's given PROBE_TIMEOUT_MS, so a stuck gh can't hold up
|
|
315
|
+
// the refresh waiting on it. Settings and a refresh asking at once share one probe [GH-01].
|
|
316
|
+
// What went wrong reading projects on the last refresh, while they're on, like boards an org's SSO hides, rides along for
|
|
317
|
+
// Settings; a later probe that works doesn't clear it, only a refresh that reads them cleanly.
|
|
318
|
+
async projectsAccess(force = false): Promise<ProjectsAccess> {
|
|
319
|
+
if (FIXTURE) return { state: "on", token: "gh" };
|
|
320
|
+
const access = await this.probeProjects(force);
|
|
321
|
+
return this.projectsWarning ? { ...access, warning: this.projectsWarning } : access;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
private async probeProjects(force: boolean): Promise<ProjectsAccess> {
|
|
325
|
+
if (this.projectsProbe) return this.projectsProbe;
|
|
326
|
+
if (!force && Date.now() - this.projects.checkedAt < PROJECTS_CHECK_MS) return this.projects.access;
|
|
327
|
+
this.projectsProbe = (async () => {
|
|
328
|
+
const result = await graphqlResult<{ viewer: { projectsV2: unknown } | null }>(PROJECTS_PROBE, {}, { timeoutMs: PROBE_TIMEOUT_MS }).catch((error: Error) => error);
|
|
329
|
+
const answer = probeAnswer(result, this.projects.access.state);
|
|
330
|
+
if (answer.error) console.error("Couldn't read projects:", answer.error);
|
|
331
|
+
this.projects = { access: { ...answer, token: tokenSource() }, checkedAt: Date.now() };
|
|
332
|
+
return this.projects.access;
|
|
333
|
+
})().finally(() => (this.projectsProbe = null));
|
|
334
|
+
return this.projectsProbe;
|
|
335
|
+
}
|
|
336
|
+
|
|
272
337
|
// One request per search, in parallel. The details request starts once the searches it needs are back [GH-01].
|
|
273
338
|
private async searchLive(now: Date, unclaimed: UnclaimedSearch[]): Promise<{ data: LiveResult; details: Details }> {
|
|
274
339
|
const all = searchVariables(this.config, now);
|
|
275
|
-
|
|
340
|
+
// Next up's searches read projects too, when they can [NXT-12]. Projects are extra, so they can never cost the search:
|
|
341
|
+
// whatever goes wrong with them (the scope gone since the check, an org's SSO, no results at all), the search runs again
|
|
342
|
+
// without them and Settings says why. Boards the token can't see come back empty and are left out.
|
|
343
|
+
const projects = (await this.probeProjects(false)).state === "on";
|
|
344
|
+
// What goes wrong reading projects this refresh, for Settings.
|
|
345
|
+
const problems: string[] = [];
|
|
346
|
+
const pickable = async <K extends "assigned" | "unclaimed">(name: K, query: string): Promise<Pick<LiveResult, K>> => {
|
|
347
|
+
const plain = () => graphql<Pick<LiveResult, K>>(searchQuery([name]), { [name]: query });
|
|
348
|
+
if (!projects) return plain();
|
|
349
|
+
// Bounded, so a stuck request falls back rather than hold up the refresh.
|
|
350
|
+
const withProjects = () => graphqlResult<Pick<LiveResult, K>>(searchQuery([name], false, { projects }), { [name]: query }, { timeoutMs: PROJECTS_SEARCH_TIMEOUT_MS });
|
|
351
|
+
const { data, failure, partly } = await searchWithProjects(withProjects, plain, (result) => !!result[name]);
|
|
352
|
+
for (const problem of [partly, failure]) if (problem) (problems.push(problem), console.error(`Next up's ${name} search with projects:`, problem));
|
|
353
|
+
if (failure) this.projects = { access: { ...projectsFailure(failure), token: tokenSource() }, checkedAt: Date.now() };
|
|
354
|
+
return data;
|
|
355
|
+
};
|
|
356
|
+
const search = (name: keyof typeof all): Promise<Partial<LiveResult>> =>
|
|
357
|
+
name === "assigned" ? pickable(name, all[name]) : graphql<Partial<LiveResult>>(searchQuery([name], name === "mine"), { [name]: all[name] });
|
|
276
358
|
// One per Next up source [NXT-09].
|
|
277
359
|
const searchUnclaimed = async (): Promise<Partial<LiveResult>> => {
|
|
278
|
-
const results = await Promise.all(
|
|
279
|
-
unclaimed.map(async ({ source, query }) => ({ source, nodes: (await graphql<Pick<LiveResult, "unclaimed">>(searchQuery(["unclaimed"]), { unclaimed: query })).unclaimed.nodes })),
|
|
280
|
-
);
|
|
360
|
+
const results = await Promise.all(unclaimed.map(async ({ source, query }) => ({ source, nodes: (await pickable("unclaimed", query)).unclaimed.nodes })));
|
|
281
361
|
return { unclaimed: { nodes: mergeUnclaimed(results) } };
|
|
282
362
|
};
|
|
283
363
|
const merge = (parts: Partial<LiveResult>[]) => Object.assign({}, ...parts) as LiveResult;
|
|
284
364
|
const forDetails = Promise.all([search("mine"), search("assigned"), searchUnclaimed()]);
|
|
285
365
|
const others = Promise.all([search("reviews"), search("mentions"), search("involved"), search("asked")]);
|
|
286
|
-
const afterThem = forDetails.then((parts) => this.details(merge(parts)));
|
|
287
|
-
|
|
288
|
-
|
|
366
|
+
const afterThem = forDetails.then((parts) => this.details(merge(parts), projects, problems));
|
|
367
|
+
try {
|
|
368
|
+
const [first, rest, details] = await Promise.all([forDetails, others, afterThem]);
|
|
369
|
+
if (projects) this.projectsWarning = projectsWarning(problems);
|
|
370
|
+
return { data: merge([...first, ...rest]), details };
|
|
371
|
+
} catch (error) {
|
|
372
|
+
// Another search failing doesn't lose what went wrong with projects so far; it can't say they went well either.
|
|
373
|
+
if (projects && problems.length) this.projectsWarning = projectsWarning(problems);
|
|
374
|
+
throw error;
|
|
375
|
+
}
|
|
289
376
|
}
|
|
290
377
|
|
|
291
378
|
private variables(names: readonly Exclude<SearchName, "unclaimed">[], now: Date): Record<string, string> {
|
|
@@ -293,38 +380,66 @@ export class AttentionService {
|
|
|
293
380
|
return Object.fromEntries(names.map((name) => [name, all[name]]));
|
|
294
381
|
}
|
|
295
382
|
|
|
296
|
-
// Behind counts [UPS-07], required checks [PRS-14]
|
|
297
|
-
|
|
383
|
+
// Behind counts [UPS-07], required checks [PRS-14], issue field option order [NXT-02] and colors [NXT-10], and the Status
|
|
384
|
+
// options of the boards Next up's issues are on [NXT-03].
|
|
385
|
+
private async details(data: Pick<LiveResult, "mine" | "assigned" | "unclaimed">, projects: boolean, problems: string[]): Promise<Details> {
|
|
298
386
|
const prs = data.mine.nodes.filter((pr) => pr?.headRefName && !pr.isCrossRepository);
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
});
|
|
387
|
+
// Priority's colors tint its pill, so its options are asked for even when the config orders it.
|
|
388
|
+
const effort = nextUpField(this.config, "effort");
|
|
389
|
+
const needsOptions = !!nextUpField(this.config, "priority") || (!!effort && !effort.order);
|
|
303
390
|
const issues = [...data.unclaimed.nodes, ...data.assigned.nodes];
|
|
304
391
|
const orgs = needsOptions ? [...new Set(issues.map((issue) => issue?.repository?.nameWithOwner.split("/")[0]).filter(Boolean))] : [];
|
|
305
392
|
const refs = toLookUp(data.mine.nodes.filter((pr) => pr?.repository));
|
|
306
393
|
const mergeStates = this.mergeStates(data.mine.nodes.filter((pr) => pr?.repository));
|
|
307
|
-
const
|
|
308
|
-
|
|
394
|
+
const statuses = projects ? this.projectStatuses(issueBoardIds(issues), problems) : Promise.resolve({});
|
|
395
|
+
const details: Details = { behind: {}, fieldOptions: {}, fieldColors: {}, projectStatuses: {}, issues: {}, checks: {}, mergeState: {} };
|
|
396
|
+
if (prs.length === 0 && orgs.length === 0 && refs.length === 0) return { ...details, mergeState: await mergeStates, projectStatuses: await statuses };
|
|
309
397
|
const { query, compares } = detailsQuery(prs, orgs as string[], refs);
|
|
310
398
|
type Result = {
|
|
311
399
|
ref?: { compare: { behindBy: number } | null } | null;
|
|
312
|
-
issueFields?: { nodes: { name?: string; options?: { name: string }[] }[] };
|
|
400
|
+
issueFields?: { nodes: { name?: string; options?: { name: string; color?: GithubColor }[] }[] };
|
|
313
401
|
issueOrPullRequest?: (LinkedIssue & { state?: string }) | null;
|
|
314
402
|
pullRequest?: { commits: { nodes: { commit: { statusCheckRollup: { contexts: { nodes: CheckContext[] } } | null } }[] } } | null;
|
|
315
403
|
} | null;
|
|
316
404
|
// A reference to a repo I can't see fails only its own field.
|
|
317
405
|
const result = await graphql<Record<string, Result>>(query);
|
|
318
406
|
for (const [alias, value] of Object.entries(result)) {
|
|
407
|
+
// Org fields come back as o0, o1, … in the order the orgs were asked for.
|
|
408
|
+
const org = /^o\d+$/.test(alias) ? (orgs[Number(alias.slice(1))] as string).toLowerCase() : null;
|
|
319
409
|
const behindBy = value?.ref?.compare?.behindBy;
|
|
320
410
|
if (typeof behindBy === "number") details.behind[compares[alias]] = behindBy;
|
|
321
411
|
const contexts = value?.pullRequest?.commits.nodes[0]?.commit.statusCheckRollup?.contexts.nodes;
|
|
322
412
|
if (contexts) details.checks[compares[alias]] = requiredChecks(contexts);
|
|
323
|
-
for (const field of value?.issueFields?.nodes ?? [])
|
|
413
|
+
for (const field of value?.issueFields?.nodes ?? []) {
|
|
414
|
+
if (!org || !field.name || !field.options) continue;
|
|
415
|
+
(details.fieldOptions[org] ??= {})[field.name] = field.options.map((o) => o.name);
|
|
416
|
+
(details.fieldColors[org] ??= {})[field.name] = Object.fromEntries(field.options.flatMap((o) => (o.color ? [[o.name, o.color]] : [])));
|
|
417
|
+
}
|
|
324
418
|
const issue = value?.issueOrPullRequest; // empty for a PR
|
|
325
419
|
if (issue?.state === "OPEN") details.issues[prKey(issue)] = { number: issue.number, title: issue.title, url: issue.url, repository: issue.repository };
|
|
326
420
|
}
|
|
327
|
-
return { ...details, mergeState: await mergeStates };
|
|
421
|
+
return { ...details, mergeState: await mergeStates, projectStatuses: await statuses };
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Each board's Status options, once per board [NXT-03, GH-01]. A board that can't be read lists no statuses; the whole
|
|
425
|
+
// request failing costs only the filter's statuses, never the refresh.
|
|
426
|
+
// Bounded in time, so it can't hold up the refresh, in size, a batch of boards per request, and in how many go at once.
|
|
427
|
+
private async projectStatuses(ids: string[], problems: string[]): Promise<Details["projectStatuses"]> {
|
|
428
|
+
const batches = Array.from({ length: Math.ceil(ids.length / BOARDS_PER_REQUEST) }, (_, i) => ids.slice(i * BOARDS_PER_REQUEST, (i + 1) * BOARDS_PER_REQUEST));
|
|
429
|
+
const read = async (batch: string[]) => {
|
|
430
|
+
try {
|
|
431
|
+
const { data, errors } = await graphqlResult<ProjectStatusesResult>(projectStatusesQuery(batch), {}, { timeoutMs: PROJECTS_SEARCH_TIMEOUT_MS });
|
|
432
|
+
if (errors.length) problems.push(errors.join("; "));
|
|
433
|
+
return batch.flatMap((id, index) => (data?.[`b${index}`]?.field?.options ? [[id, data[`b${index}`]!.field!.options!] as const] : []));
|
|
434
|
+
} catch (error) {
|
|
435
|
+
problems.push((error as Error).message);
|
|
436
|
+
return [];
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
const results: Awaited<ReturnType<typeof read>>[] = [];
|
|
440
|
+
for (let at = 0; at < batches.length; at += BOARD_BATCHES_AT_ONCE) results.push(...(await Promise.all(batches.slice(at, at + BOARD_BATCHES_AT_ONCE).map(read))));
|
|
441
|
+
if (problems.length) console.error("Reading projects:", problems.join("; "));
|
|
442
|
+
return Object.fromEntries(results.flat());
|
|
328
443
|
}
|
|
329
444
|
|
|
330
445
|
// My PRs' merge state, a few per request in parallel, as GitHub only works it out for a few at a time; search's answer
|
|
@@ -396,6 +511,7 @@ export class AttentionService {
|
|
|
396
511
|
feeds: { live: status("live"), history: status("history") },
|
|
397
512
|
scopes: this.state.scopes,
|
|
398
513
|
sources: this.state.sources,
|
|
514
|
+
projectFilter: this.state.projectFilter,
|
|
399
515
|
config: this.config,
|
|
400
516
|
pending: Object.keys(pending).length,
|
|
401
517
|
...(FIXTURE ? { fixtureAgents: FIXTURE_AGENTS } : {}),
|
package/server/store.ts
CHANGED
|
@@ -25,6 +25,8 @@ export const State = z.object({
|
|
|
25
25
|
scopes: z.array(z.string()).default([]),
|
|
26
26
|
// Sources ticked in Next up's filter; none means all [NXT-09].
|
|
27
27
|
sources: z.array(z.string()).default([]),
|
|
28
|
+
// Project statuses ticked in Next up's filter; none means all [NXT-03].
|
|
29
|
+
projectFilter: z.array(z.string()).default([]),
|
|
28
30
|
// The update notice put off with Not now, by the version it offered [UPD-01].
|
|
29
31
|
skippedUpdate: z.string().nullable().default(null).catch(null),
|
|
30
32
|
// My Paseo projects' GitHub repos when last listed, for refreshes before the app has connected [NXT-08].
|
package/server/view.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface ViewMeta {
|
|
|
7
7
|
feeds: Record<FeedId, FeedStatus>;
|
|
8
8
|
scopes: string[];
|
|
9
9
|
sources: string[];
|
|
10
|
+
projectFilter: string[];
|
|
10
11
|
config: AttentionConfig;
|
|
11
12
|
pending: number;
|
|
12
13
|
}
|
|
@@ -143,6 +144,7 @@ export function buildView(attention: Attention | null, history: Item[], dismisse
|
|
|
143
144
|
assigned: attention?.assigned ?? [],
|
|
144
145
|
unclaimed: attention?.unclaimed ?? [],
|
|
145
146
|
unclaimedFrom: attention?.unclaimedFrom ?? "config",
|
|
147
|
+
projects: attention?.projects ?? [],
|
|
146
148
|
dismissedCount: items.length - visible.length,
|
|
147
149
|
};
|
|
148
150
|
}
|
package/shared/attention.ts
CHANGED
|
@@ -220,6 +220,38 @@ export interface Item {
|
|
|
220
220
|
notPlanned?: true;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
// The colors GitHub lets an org give issue field options and a project its Status options. GRAY is what nothing chosen looks
|
|
224
|
+
// like, so it's shown untinted [NXT-10].
|
|
225
|
+
export type GithubColor = "GRAY" | "BLUE" | "GREEN" | "YELLOW" | "ORANGE" | "RED" | "PINK" | "PURPLE";
|
|
226
|
+
|
|
227
|
+
// An open project an issue is on, with its place on the board's built-in Status field [NXT-12].
|
|
228
|
+
export interface IssueProject {
|
|
229
|
+
id: string;
|
|
230
|
+
title: string;
|
|
231
|
+
status?: string;
|
|
232
|
+
color?: GithubColor;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// An open project Next up's issues are on, with every option of its Status field in the board's order, for the filter [NXT-03].
|
|
236
|
+
export interface ProjectInfo {
|
|
237
|
+
id: string;
|
|
238
|
+
title: string;
|
|
239
|
+
statuses: { name: string; color: GithubColor }[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Whether Next up can read projects, and if not, why and how to fix it, for Settings [NXT-12]. Without them Next up just
|
|
243
|
+
// leaves projects out.
|
|
244
|
+
export interface ProjectsAccess {
|
|
245
|
+
// missing: the token lacks read:project; failed: GitHub refused or didn't answer for another reason; unknown: not asked yet.
|
|
246
|
+
state: "on" | "missing" | "failed" | "unknown";
|
|
247
|
+
// GitHub's own words when it failed for another reason, like an org's SSO.
|
|
248
|
+
error?: string;
|
|
249
|
+
// What went wrong reading them on the last refresh while they're on, like boards an org's SSO hides, in GitHub's words.
|
|
250
|
+
warning?: string;
|
|
251
|
+
// Where gh's token comes from: its own login, which `gh auth refresh` can widen, or an environment variable it reads first.
|
|
252
|
+
token: "gh" | "GH_TOKEN" | "GITHUB_TOKEN";
|
|
253
|
+
}
|
|
254
|
+
|
|
223
255
|
// An issue to pick up: assigned to me [NXT-06] or nobody [NXT-01].
|
|
224
256
|
export interface NextUpIssue {
|
|
225
257
|
key: string;
|
|
@@ -237,6 +269,11 @@ export interface NextUpIssue {
|
|
|
237
269
|
sources: string[];
|
|
238
270
|
// Its priority's place in the field's order, 0 first; missing when unknown [NXT-02].
|
|
239
271
|
priorityRank?: number;
|
|
272
|
+
// The color the org gave its priority option; missing when the org colored none, so the card falls back on rank [NXT-10].
|
|
273
|
+
priorityColor?: GithubColor;
|
|
274
|
+
// The open projects it's on [NXT-12]. Missing when projects can't be read, or when GitHub cut its list short with none open
|
|
275
|
+
// in what came: then which boards it's on is unknown, so it's neither on one nor on none.
|
|
276
|
+
projects?: IssueProject[];
|
|
240
277
|
// Open PRs that close it: someone may already be on it [NXT-10].
|
|
241
278
|
openPrs: { number: number; url: string; author: string | null }[];
|
|
242
279
|
}
|
|
@@ -267,6 +304,8 @@ export interface Attention {
|
|
|
267
304
|
assigned: NextUpIssue[];
|
|
268
305
|
unclaimed: NextUpIssue[];
|
|
269
306
|
unclaimedFrom?: UnclaimedSource;
|
|
307
|
+
// The projects Next up's issues are on, for its filter [NXT-03, NXT-12].
|
|
308
|
+
projects?: ProjectInfo[];
|
|
270
309
|
// Repo -> who reviewed or was asked on my PRs there, latest first, for the reviewer picker [PRS-12].
|
|
271
310
|
reviewers?: Record<string, Reviewer[]>;
|
|
272
311
|
}
|
|
@@ -340,14 +379,32 @@ export interface AttentionView {
|
|
|
340
379
|
assigned: NextUpIssue[];
|
|
341
380
|
unclaimed: NextUpIssue[];
|
|
342
381
|
unclaimedFrom: UnclaimedSource;
|
|
382
|
+
// The projects Next up's issues are on [NXT-03, NXT-12].
|
|
383
|
+
projects: ProjectInfo[];
|
|
343
384
|
dismissedCount: number;
|
|
344
385
|
// Scopes ticked in Next up's filter; none means all [NXT-03].
|
|
345
386
|
scopes: string[];
|
|
346
387
|
// Sources ticked in Next up's filter; none means all [NXT-09].
|
|
347
388
|
sources: string[];
|
|
389
|
+
// Project statuses ticked in Next up's filter, as projectFilterId makes them; none means all [NXT-03].
|
|
390
|
+
projectFilter: string[];
|
|
348
391
|
config: AttentionConfig;
|
|
349
392
|
// Changes I just made that GitHub's search hasn't caught up with; the app checks back sooner while there are any [FRESH-02].
|
|
350
393
|
pending: number;
|
|
351
394
|
// Fixture mode only: made-up sessions, since the preview daemon has no agents.
|
|
352
395
|
fixtureAgents?: AgentSummary[];
|
|
353
396
|
}
|
|
397
|
+
|
|
398
|
+
// What a tick in Next up's project filter stands for: one status of one project, a project's issues without a status, or
|
|
399
|
+
// issues on no project [NXT-03].
|
|
400
|
+
export function projectFilterId(project: { id: string } | null, status?: string | null): string {
|
|
401
|
+
if (!project) return "noproject";
|
|
402
|
+
return status ? `status:${project.id}:${status}` : `nostatus:${project.id}`;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// The ticks an issue answers to: one per project it's on, or "noproject". None when its projects are unknown, so a project
|
|
406
|
+
// filter hides it rather than call it on no project.
|
|
407
|
+
export function projectFilterIds(issue: Pick<NextUpIssue, "projects">): string[] {
|
|
408
|
+
if (!issue.projects) return [];
|
|
409
|
+
return issue.projects.length ? issue.projects.map((project) => projectFilterId(project, project.status)) : [projectFilterId(null)];
|
|
410
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Only the newest of several pending opens may go through: tapping another card while one waits for its details supersedes
|
|
2
|
+
// it, so two sheets never open on top of each other whichever request finishes first [ATT-06].
|
|
3
|
+
export class LatestOnly {
|
|
4
|
+
private current: { id: number; cancel: () => void } | null = null;
|
|
5
|
+
private next = 0;
|
|
6
|
+
|
|
7
|
+
// Something else took over, like an action that opens its own sheet: whatever was waiting to open won't.
|
|
8
|
+
cancel(): void {
|
|
9
|
+
this.current?.cancel();
|
|
10
|
+
this.current = null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// A new pending open; the one before it, if still waiting, is cancelled.
|
|
14
|
+
start(cancel: () => void): PendingOpen {
|
|
15
|
+
this.current?.cancel();
|
|
16
|
+
const id = ++this.next;
|
|
17
|
+
this.current = { id, cancel };
|
|
18
|
+
return {
|
|
19
|
+
isCurrent: () => this.current?.id === id,
|
|
20
|
+
// It opened, or its card went away: nothing is pending any more.
|
|
21
|
+
done: () => {
|
|
22
|
+
if (this.current?.id === id) this.current = null;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface PendingOpen {
|
|
29
|
+
isCurrent: () => boolean;
|
|
30
|
+
done: () => void;
|
|
31
|
+
}
|
package/shared/rpc.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineRpc } from "@getpaseo/plugin";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import type { AttentionView, ItemDetails, ReviewerChoices, Target } from "./attention";
|
|
3
|
+
import type { AttentionView, ItemDetails, ProjectsAccess, ReviewerChoices, Target } from "./attention";
|
|
4
4
|
import { SessionKind } from "./config";
|
|
5
5
|
import type { ConfigStatus, CoverageCheck, IssueField, SetupStatus } from "./setup";
|
|
6
6
|
import type { FeedbackInfo } from "./feedback";
|
|
@@ -39,6 +39,10 @@ export const myOrgs = defineRpc({ name: "config.my-orgs", input: z.object({}), o
|
|
|
39
39
|
// Remember the scopes and sources ticked in Next up's filter [NXT-03, NXT-09].
|
|
40
40
|
export const setScopes = defineRpc({ name: "next-up.scopes", input: z.object({ scopes: z.array(z.string()) }), output: done });
|
|
41
41
|
export const setSources = defineRpc({ name: "next-up.sources", input: z.object({ sources: z.array(z.string()) }), output: done });
|
|
42
|
+
// And the project statuses [NXT-03].
|
|
43
|
+
export const setProjectFilter = defineRpc({ name: "next-up.projects", input: z.object({ projects: z.array(z.string()) }), output: done });
|
|
44
|
+
// Whether the gh login may read projects, asked again now, for Settings [NXT-12].
|
|
45
|
+
export const projectsAccess = defineRpc({ name: "config.projects-access", input: z.object({}), output: z.custom<ProjectsAccess>() });
|
|
42
46
|
|
|
43
47
|
// GitHub changes, each from an explicit tap [SAFE-01], answered with the list after it.
|
|
44
48
|
// `key` is the card it was done from, which shows the change until GitHub's search does [FRESH-02].
|