@andrioid/paseo-attention-span 0.3.1 → 0.3.2
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/docs/architecture.md +2 -2
- package/package.json +1 -1
- package/server/classify.ts +14 -8
- package/server/fixture.ts +11 -3
- package/server/github-types.ts +7 -2
- package/server/queries.ts +17 -6
- package/server/references.ts +70 -0
- package/server/service.ts +15 -6
package/docs/architecture.md
CHANGED
|
@@ -80,7 +80,7 @@ Top to bottom. Each item appears once, under its most urgent reason [ATT-02]. `s
|
|
|
80
80
|
|
|
81
81
|
## Rules
|
|
82
82
|
|
|
83
|
-
- **One item per issue** [ATT-03]: PRs are grouped under the
|
|
83
|
+
- **One item per issue** [ATT-03]: PRs are grouped under the issue they work on, across repos. GitHub links (`closingIssuesReferences`) only PRs into the default branch, so a stack's upper PRs are read too. For a stack, strongest evidence first: what GitHub links on any of its PRs, bottom first; then a closing keyword ("Closes #N") in any PR's description; then the one issue the bottom PR's description mentions ("First of three for #N"), and none when it mentions several. Code, quotes and template comments don't count. References from descriptions are looked up in the details request, and only open issues count, so a reference to a PR doesn't group. A PR without an issue is its own item. History does the same per merged PR, against the closed issues it lists.
|
|
84
84
|
- **One item per stack** [ATT-04]: a stack is followed through base/head branch names. Its section is decided by the bottom PR; the PRs above it are listed beneath.
|
|
85
85
|
- **Answers** [ATT-16]: on an issue a PR of mine closes, an answer leads the item like a mention does. From the issue itself only what's on me counts; its PRs say how the work is going.
|
|
86
86
|
- **Mentions** [MEN-01..06]: a thread counts when a person @-mentioned me after my last comment, review or reaction there. Team mentions are ignored. A bot counts only when it opened a thread I need to resolve, and is marked with 🤖. The quote on a card is cut around the mention, so it's shown as plain text: links keep their text, Markdown marks and quoted replies go.
|
|
@@ -165,7 +165,7 @@ One GraphQL request per search, sent in parallel. GitHub runs the searches in on
|
|
|
165
165
|
- `is:issue is:open author:@me commenter:@me sort:updated-desc`, 50 at most, no date limit, the same fields (questions on my own issues nobody answered, however old) [ATT-11]
|
|
166
166
|
- `is:issue is:open no:assignee` (Next up, with issue type and field values; one request per source [NXT-09], skipped when there's nowhere to look [NXT-08]). "My repos" needs my login, taken from the last fetch or asked once with `viewer { login }`
|
|
167
167
|
|
|
168
|
-
Once my PRs and both issue searches are back, one batched **details** request asks for `Ref.compare` behind counts for my PRs, and the option order of org issue fields when Next up needs it. The other searches carry on meanwhile.
|
|
168
|
+
Once my PRs and both issue searches are back, one batched **details** request asks for `Ref.compare` behind counts for my PRs, the open issues their descriptions refer to (at most 100), and the option order of org issue fields when Next up needs it. The other searches carry on meanwhile.
|
|
169
169
|
|
|
170
170
|
A live refresh is 8 requests and about 85 points, of the 5,000 GitHub allows per hour. Points depend on how much a query asks for, not how many requests carry it; my PRs (34) and review requests (20) cost the most.
|
|
171
171
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrioid/paseo-attention-span",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "For when your attention is spread thin: the GitHub issues and pull requests waiting on you, grouped by why, with one-tap Paseo sessions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/server/classify.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type Attention, type Chip, type Item, type NextUpIssue, type Person, type Reviewer, SECTION_ORDER, SECTIONS, type SectionId, type SubRow, type Target } from "../shared/attention";
|
|
2
2
|
import type { AttentionConfig, MergeMethod } from "../shared/config";
|
|
3
3
|
import { ago, daysSince } from "../shared/format";
|
|
4
|
-
import type { Actor, Comment, Details, HistoryResult, IssueNode, LiveResult, MentionNode, PickableNode, PullRequestNode, RequestedReviewer } from "./github-types";
|
|
4
|
+
import type { Actor, Comment, Details, HistoryResult, IssueNode, LinkedIssue, LiveResult, MentionNode, PickableNode, PullRequestNode, RequestedReviewer } from "./github-types";
|
|
5
5
|
import { excerpt, plainText } from "./markdown";
|
|
6
6
|
import { prKey } from "./queries";
|
|
7
|
+
import { issueFor } from "./references";
|
|
7
8
|
import { ISSUE_RULES, type IssueState, pick, PR_RULES, type PrState, replyActions } from "./rules";
|
|
8
9
|
|
|
9
10
|
// Turns one refresh worth of GitHub data into what needs me. Pure, so every rule is testable.
|
|
@@ -216,12 +217,15 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
216
217
|
stack: stack.map((p) => ({ number: p.number, head: p.headRefName, base: p.baseRefName })),
|
|
217
218
|
});
|
|
218
219
|
|
|
219
|
-
// One item per issue: PRs grouped under the issue they
|
|
220
|
-
const
|
|
220
|
+
// One item per issue: PRs grouped under the issue they work on [ATT-03]. Otherwise one per unit.
|
|
221
|
+
const issues = new Map(Object.entries(details.issues));
|
|
222
|
+
for (const pr of mine) for (const issue of pr.closingIssuesReferences.nodes) issues.set(prKey(issue), issue);
|
|
223
|
+
const groups = new Map<string, { lead?: LinkedIssue; units: Unit[] }>();
|
|
221
224
|
for (const unit of units) {
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
+
const prs = unit.stack.map((pr) => ({ repo: pr.repository.nameWithOwner, body: pr.body, linked: pr.closingIssuesReferences.nodes.map(prKey) }));
|
|
226
|
+
const issue = issueFor(prs, (key) => issues.has(key));
|
|
227
|
+
const key = issue ?? prKey(unit.stack[0]);
|
|
228
|
+
groups.set(key, { lead: issue ? issues.get(issue) : undefined, units: [...(groups.get(key)?.units ?? []), unit] });
|
|
225
229
|
}
|
|
226
230
|
for (const [key, { lead, units: grouped }] of groups) {
|
|
227
231
|
for (const unit of grouped) for (const pr of unit.stack) listed.add(prKey(pr));
|
|
@@ -335,7 +339,7 @@ export function classify({ data, details, config, now }: ClassifyInput): Attenti
|
|
|
335
339
|
};
|
|
336
340
|
}
|
|
337
341
|
|
|
338
|
-
// My merged PRs under the issues they
|
|
342
|
+
// My merged PRs under the closed issues they worked on, closed issues, and reviews [HIS-01, HIS-02, ATT-03].
|
|
339
343
|
export function classifyHistory(data: HistoryResult): Item[] {
|
|
340
344
|
const items: Item[] = [];
|
|
341
345
|
const closed = new Map<string, Item>();
|
|
@@ -346,7 +350,9 @@ export function classifyHistory(data: HistoryResult): Item[] {
|
|
|
346
350
|
items.push(item);
|
|
347
351
|
}
|
|
348
352
|
for (const pr of compact(data.merged.nodes)) {
|
|
349
|
-
|
|
353
|
+
// Each merged PR on its own: its branches are gone, so it can't be put back in its stack [ATT-03].
|
|
354
|
+
const linked = { repo: pr.repository.nameWithOwner, body: pr.body, linked: pr.closingIssuesReferences.nodes.map(prKey) };
|
|
355
|
+
const issue = closed.get(issueFor([linked], (key) => closed.has(key)) ?? "");
|
|
350
356
|
if (issue) issue.children.push({ key: prKey(pr), number: pr.number, title: pr.title, url: pr.url, draft: false, chips: [], attention: false });
|
|
351
357
|
else items.push({ ...plain(pr, "pr", "done"), closedAt: pr.mergedAt });
|
|
352
358
|
}
|
package/server/fixture.ts
CHANGED
|
@@ -140,9 +140,10 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
140
140
|
pr(102, { title: "Retry webhook deliveries with backoff", reviewThreads: { nodes: [thread(alice, 1), thread(bot, 2)] } }),
|
|
141
141
|
pr(103, { title: "Fetch supplier price files nightly", reviewDecision: "APPROVED", closingIssuesReferences: closes(90, "Supplier prices are a week out of date") }),
|
|
142
142
|
pr(104, { title: "Move price-file login into a service", isDraft: true, baseRefName: "branch-103", headRefName: "branch-104" }),
|
|
143
|
-
|
|
143
|
+
// A stack GitHub links to no issue: its descriptions say which [ATT-03].
|
|
144
|
+
pr(105, { title: "Dialog focus returns to the trigger", body: "First of three stacked PRs for #132.", reviewDecision: "APPROVED", headRefName: "a11y-1" }),
|
|
144
145
|
pr(106, { title: "Keyboard navigation for calendar cards", isDraft: true, baseRefName: "a11y-1", headRefName: "a11y-2", reviewDecision: "APPROVED" }),
|
|
145
|
-
pr(107, { title: "Calendar: jump between weeks with keys", isDraft: true, baseRefName: "a11y-2", headRefName: "a11y-3" }, "FAILURE"),
|
|
146
|
+
pr(107, { title: "Calendar: jump between weeks with keys", body: "Closes #132", isDraft: true, baseRefName: "a11y-2", headRefName: "a11y-3" }, "FAILURE"),
|
|
146
147
|
pr(108, { title: "Company-scoped database layer", mergeable: "CONFLICTING" }),
|
|
147
148
|
// Asked a team, and nobody has looked for 6 days [ATT-11, PRS-12].
|
|
148
149
|
pr(109, { title: "Store uploads locally in development", reviewRequests: { nodes: [{ requestedReviewer: frontend }] }, commits: commit("SUCCESS", 6) }),
|
|
@@ -224,7 +225,14 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
224
225
|
],
|
|
225
226
|
closed: [closed(171, "Backups are never verified", 1), closed(174, "Order list takes 8 seconds", 9), closed(176, "Dark mode for the admin", 10, "NOT_PLANNED")],
|
|
226
227
|
});
|
|
227
|
-
return {
|
|
228
|
+
return {
|
|
229
|
+
data,
|
|
230
|
+
details: {
|
|
231
|
+
behind: { [key(103)]: 1, [key(106)]: 12, [key(108)]: 139, [key(110)]: 2307, [key(114)]: 3, [key(115)]: 40 },
|
|
232
|
+
fieldOptions: { Priority: ["🌋 P0 Urgent", "🏔 P1 High", "🏕P2 Medium", "🏝 P3 Low"] },
|
|
233
|
+
issues: { [key(132)]: { number: 132, title: "The calendar can't be used with a keyboard", url: `https://github.com/${REPO}/issues/132`, repository } },
|
|
234
|
+
},
|
|
235
|
+
};
|
|
228
236
|
}
|
|
229
237
|
|
|
230
238
|
// Sessions the preview shows as started from items: working, needs me, failed, idle.
|
package/server/github-types.ts
CHANGED
|
@@ -36,6 +36,7 @@ export interface PullRequestNode {
|
|
|
36
36
|
number: number;
|
|
37
37
|
title: string;
|
|
38
38
|
url: string;
|
|
39
|
+
body?: string;
|
|
39
40
|
isDraft: boolean;
|
|
40
41
|
createdAt: string;
|
|
41
42
|
updatedAt: string;
|
|
@@ -49,7 +50,7 @@ export interface PullRequestNode {
|
|
|
49
50
|
reviewDecision: "APPROVED" | "CHANGES_REQUESTED" | "REVIEW_REQUIRED" | null;
|
|
50
51
|
autoMergeRequest?: { enabledAt: string } | null;
|
|
51
52
|
assignees: Nodes<{ login: string }>;
|
|
52
|
-
closingIssuesReferences: Nodes<
|
|
53
|
+
closingIssuesReferences: Nodes<LinkedIssue>;
|
|
53
54
|
commits: Nodes<{ commit: { committedDate: string; statusCheckRollup: { state: string } | null } }>;
|
|
54
55
|
// A person, or a team by its "org/slug"; null when it can't be seen.
|
|
55
56
|
reviewRequests: Nodes<{ requestedReviewer: RequestedReviewer | null }>;
|
|
@@ -115,7 +116,7 @@ export interface LiveResult {
|
|
|
115
116
|
|
|
116
117
|
// One request for all three [HIS-01, HIS-02].
|
|
117
118
|
export interface HistoryResult {
|
|
118
|
-
merged: Nodes<{ number: number; title: string; url: string; mergedAt: string; repository: Repo; closingIssuesReferences: Nodes<{ number: number; repository: Repo }> }>;
|
|
119
|
+
merged: Nodes<{ number: number; title: string; url: string; body?: string; mergedAt: string; repository: Repo; closingIssuesReferences: Nodes<{ number: number; repository: Repo }> }>;
|
|
119
120
|
reviewed: Nodes<{ number: number; title: string; url: string; mergedAt: string; repository: Repo; author: Actor | null }>;
|
|
120
121
|
closed: Nodes<{ number: number; title: string; url: string; closedAt: string; stateReason: string | null; repository: Repo }>;
|
|
121
122
|
}
|
|
@@ -128,4 +129,8 @@ export interface Details {
|
|
|
128
129
|
behind: Record<string, number>;
|
|
129
130
|
// Issue field name -> its options in order.
|
|
130
131
|
fieldOptions: Record<string, string[]>;
|
|
132
|
+
// "owner/name#number" -> the open issue my PRs' descriptions refer to; PRs and closed issues are left out [ATT-03].
|
|
133
|
+
issues: Record<string, LinkedIssue>;
|
|
131
134
|
}
|
|
135
|
+
|
|
136
|
+
export type LinkedIssue = { number: number; title: string; url: string; repository: Repo };
|
package/server/queries.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { UnclaimedSource } from "../shared/attention";
|
|
2
2
|
import type { AttentionConfig } from "../shared/config";
|
|
3
3
|
import type { PickableNode, PullRequestNode } from "./github-types";
|
|
4
|
+
import type { IssueRef } from "./references";
|
|
4
5
|
|
|
5
6
|
// An issue or PR with its last conversation comments [ATT-16].
|
|
6
7
|
const THREAD = `__typename
|
|
@@ -29,7 +30,7 @@ const SEARCHES = {
|
|
|
29
30
|
unclaimed: { first: 100, nodes: "...pickable" },
|
|
30
31
|
merged: {
|
|
31
32
|
first: 100,
|
|
32
|
-
nodes: "... on PullRequest { number title url mergedAt repository { nameWithOwner } closingIssuesReferences(first: 3) { nodes { number repository { nameWithOwner } } } }",
|
|
33
|
+
nodes: "... on PullRequest { number title url body mergedAt repository { nameWithOwner } closingIssuesReferences(first: 3) { nodes { number repository { nameWithOwner } } } }",
|
|
33
34
|
},
|
|
34
35
|
reviewed: { first: 100, nodes: "... on PullRequest { number title url mergedAt repository { nameWithOwner } author { ...author } }" },
|
|
35
36
|
closed: { first: 100, nodes: "... on Issue { number title url closedAt stateReason repository { nameWithOwner } }" },
|
|
@@ -56,7 +57,7 @@ const FRAGMENTS: Record<string, string> = {
|
|
|
56
57
|
closedByPullRequestsReferences(first: 5, includeClosedPrs: false) { nodes { number url state author { login } } }
|
|
57
58
|
}`,
|
|
58
59
|
pr: `fragment pr on PullRequest {
|
|
59
|
-
id number title url isDraft createdAt updatedAt
|
|
60
|
+
id number title url body isDraft createdAt updatedAt
|
|
60
61
|
author { ...author }
|
|
61
62
|
repository { nameWithOwner squashMergeAllowed mergeCommitAllowed autoMergeAllowed defaultBranchRef { name } }
|
|
62
63
|
baseRefName headRefName headRefOid isCrossRepository mergeable reviewDecision
|
|
@@ -175,16 +176,26 @@ export function prKey(node: { repository: { nameWithOwner: string }; number: num
|
|
|
175
176
|
return `${node.repository.nameWithOwner}#${node.number}`;
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
const repository = (repo: string) => {
|
|
180
|
+
const [owner, name] = repo.split("/");
|
|
181
|
+
return `repository(owner: ${JSON.stringify(owner)}, name: ${JSON.stringify(name)})`;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// After my PRs and Next up's issues: how far my PRs are behind their bases, the option order of org issue fields, and
|
|
185
|
+
// what the issues my PRs' descriptions refer to are [GH-01, ATT-03].
|
|
186
|
+
export function detailsQuery(prs: PullRequestNode[], orgs: string[], refs: IssueRef[] = []): { query: string; compares: Record<string, string> } {
|
|
180
187
|
const compares: Record<string, string> = {};
|
|
181
188
|
const fields = prs.map((pr, index) => {
|
|
182
189
|
compares[`c${index}`] = prKey(pr);
|
|
183
|
-
|
|
184
|
-
return `c${index}: repository(owner: ${JSON.stringify(owner)}, name: ${JSON.stringify(name)}) {
|
|
190
|
+
return `c${index}: ${repository(pr.repository.nameWithOwner)} {
|
|
185
191
|
ref(qualifiedName: ${JSON.stringify(`refs/heads/${pr.baseRefName}`)}) { compare(headRef: ${JSON.stringify(pr.headRefName)}) { behindBy } }
|
|
186
192
|
}`;
|
|
187
193
|
});
|
|
194
|
+
refs.forEach((ref, index) =>
|
|
195
|
+
fields.push(`i${index}: ${repository(ref.repo)} {
|
|
196
|
+
issueOrPullRequest(number: ${ref.number}) { ... on Issue { number title url state repository { nameWithOwner } } }
|
|
197
|
+
}`),
|
|
198
|
+
);
|
|
188
199
|
orgs.forEach((org, index) =>
|
|
189
200
|
fields.push(`o${index}: organization(login: ${JSON.stringify(org)}) {
|
|
190
201
|
issueFields(first: 50) { nodes { ... on IssueFieldSingleSelect { name options { name } } } }
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Which issue a PR or stack works on, from what GitHub links and what its descriptions say [ATT-03, HIS-01].
|
|
2
|
+
|
|
3
|
+
export interface IssueRef {
|
|
4
|
+
repo: string;
|
|
5
|
+
number: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// "#12", "acme/shop#12" or a link to an issue; links to PRs are left out.
|
|
9
|
+
const REF = String.raw`(?:https://github\.com/([\w.-]+/[\w.-]+)/issues/(\d+)|(?<![\w/#&])(?:([\w.-]+/[\w.-]+))?#(\d+))(?![\w-])`;
|
|
10
|
+
// GitHub's closing keywords [docs: linking a pull request to an issue].
|
|
11
|
+
const CLOSING = new RegExp(String.raw`\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\b:?\s+${REF}`, "gi");
|
|
12
|
+
const ANY = new RegExp(REF, "gi");
|
|
13
|
+
|
|
14
|
+
// What counts as said: not code, quoted replies or template comments.
|
|
15
|
+
function prose(body: string): string {
|
|
16
|
+
return body
|
|
17
|
+
.replace(/\r/g, "")
|
|
18
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
19
|
+
.replace(/^\s*(```|~~~)[\s\S]*?^\s*\1.*$/gm, "")
|
|
20
|
+
.replace(/`[^`\n]*`/g, "")
|
|
21
|
+
.replace(/^\s*>.*$/gm, "");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function refs(body: string | undefined, repo: string, pattern: RegExp): IssueRef[] {
|
|
25
|
+
const found = new Map<string, IssueRef>();
|
|
26
|
+
for (const match of prose(body ?? "").matchAll(pattern)) {
|
|
27
|
+
const ref = { repo: match[1] ?? match[3] ?? repo, number: Number(match[2] ?? match[4]) };
|
|
28
|
+
found.set(refKey(ref), ref);
|
|
29
|
+
}
|
|
30
|
+
return [...found.values()];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const refKey = (ref: IssueRef) => `${ref.repo}#${ref.number}`;
|
|
34
|
+
export const closingRefs = (body: string | undefined, repo: string) => refs(body, repo, CLOSING);
|
|
35
|
+
export const mentionedRefs = (body: string | undefined, repo: string) => refs(body, repo, ANY);
|
|
36
|
+
|
|
37
|
+
export interface LinkedPr {
|
|
38
|
+
repo: string;
|
|
39
|
+
body?: string;
|
|
40
|
+
// Issues GitHub links it to with a closing keyword, as "owner/name#number".
|
|
41
|
+
linked: string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The issue for PRs listed bottom first, strongest evidence first: what GitHub links, then a closing keyword in a
|
|
45
|
+
// description, then the one issue the bottom PR's description mentions. GitHub links only PRs into the default branch,
|
|
46
|
+
// so a stack's upper PRs need their descriptions read. `isIssue` says whether a reference is an issue that counts, which
|
|
47
|
+
// rules out PRs and closed issues; several mentioned issues are too ambiguous to pick from.
|
|
48
|
+
export function issueFor(prs: LinkedPr[], isIssue: (key: string) => boolean): string | undefined {
|
|
49
|
+
for (const pr of prs) {
|
|
50
|
+
const linked = pr.linked.find(isIssue);
|
|
51
|
+
if (linked) return linked;
|
|
52
|
+
}
|
|
53
|
+
for (const pr of prs) {
|
|
54
|
+
const closing = closingRefs(pr.body, pr.repo).map(refKey).find(isIssue);
|
|
55
|
+
if (closing) return closing;
|
|
56
|
+
}
|
|
57
|
+
const mentioned = prs[0] ? mentionedRefs(prs[0].body, prs[0].repo).map(refKey).filter(isIssue) : [];
|
|
58
|
+
return mentioned.length === 1 ? mentioned[0] : undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The references in my PRs' descriptions to look up, at most `max`: my PRs themselves and what GitHub links are known.
|
|
62
|
+
type Node = { number: number; repository: { nameWithOwner: string } };
|
|
63
|
+
const nodeKey = (node: Node) => `${node.repository.nameWithOwner}#${node.number}`;
|
|
64
|
+
|
|
65
|
+
export function toLookUp(prs: (Node & { body?: string; closingIssuesReferences: { nodes: Node[] } })[], max = 100): IssueRef[] {
|
|
66
|
+
const known = new Set(prs.flatMap((pr) => [pr, ...pr.closingIssuesReferences.nodes].map(nodeKey)));
|
|
67
|
+
const wanted = new Map<string, IssueRef>();
|
|
68
|
+
for (const pr of prs) for (const ref of mentionedRefs(pr.body, pr.repository.nameWithOwner)) if (!known.has(refKey(ref))) wanted.set(refKey(ref), ref);
|
|
69
|
+
return [...wanted.values()].slice(0, max);
|
|
70
|
+
}
|
package/server/service.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { AttentionConfig, githubRepoOf } from "../shared/config";
|
|
|
4
4
|
import { classify, classifyHistory } from "./classify";
|
|
5
5
|
import { FIXTURE, graphql } from "./gh";
|
|
6
6
|
import { fixture, FIXTURE_AGENTS } from "./fixture";
|
|
7
|
-
import type { Details, HistoryResult, LiveResult } from "./github-types";
|
|
8
|
-
import { detailsQuery, HISTORY_SEARCHES, mergeUnclaimed, type SearchName, searchQuery, searchVariables, type UnclaimedSearch, unclaimedSearches } from "./queries";
|
|
7
|
+
import type { Details, HistoryResult, LinkedIssue, LiveResult } from "./github-types";
|
|
8
|
+
import { detailsQuery, HISTORY_SEARCHES, mergeUnclaimed, prKey, type SearchName, searchQuery, searchVariables, type UnclaimedSearch, unclaimedSearches } from "./queries";
|
|
9
|
+
import { toLookUp } from "./references";
|
|
9
10
|
import { loadConfig, loadState, moveOldFiles, saveCodeRepo, saveCoverage, saveFollowThreads, saveNextUpSources, saveState, State } from "./store";
|
|
10
11
|
import { applyPending, buildView, doneItem, type Effect, isPending, SETTLE_MS } from "./view";
|
|
11
12
|
|
|
@@ -258,15 +259,23 @@ export class AttentionService {
|
|
|
258
259
|
const needsOptions = [priority, effort].some((field) => field && !field.order);
|
|
259
260
|
const issues = [...data.unclaimed.nodes, ...data.assigned.nodes];
|
|
260
261
|
const orgs = needsOptions ? [...new Set(issues.map((issue) => issue?.repository?.nameWithOwner.split("/")[0]).filter(Boolean))] : [];
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
const refs = toLookUp(data.mine.nodes.filter((pr) => pr?.repository));
|
|
263
|
+
const details: Details = { behind: {}, fieldOptions: {}, issues: {} };
|
|
264
|
+
if (prs.length === 0 && orgs.length === 0 && refs.length === 0) return details;
|
|
265
|
+
const { query, compares } = detailsQuery(prs, orgs as string[], refs);
|
|
266
|
+
type Result = {
|
|
267
|
+
ref?: { compare: { behindBy: number } | null } | null;
|
|
268
|
+
issueFields?: { nodes: { name?: string; options?: { name: string }[] }[] };
|
|
269
|
+
issueOrPullRequest?: (LinkedIssue & { state?: string }) | null;
|
|
270
|
+
} | null;
|
|
271
|
+
// A reference to a repo I can't see fails only its own field.
|
|
265
272
|
const result = await graphql<Record<string, Result>>(query);
|
|
266
273
|
for (const [alias, value] of Object.entries(result)) {
|
|
267
274
|
const behindBy = value?.ref?.compare?.behindBy;
|
|
268
275
|
if (typeof behindBy === "number") details.behind[compares[alias]] = behindBy;
|
|
269
276
|
for (const field of value?.issueFields?.nodes ?? []) if (field.name && field.options) details.fieldOptions[field.name] ??= field.options.map((o) => o.name);
|
|
277
|
+
const issue = value?.issueOrPullRequest; // empty for a PR
|
|
278
|
+
if (issue?.state === "OPEN") details.issues[prKey(issue)] = { number: issue.number, title: issue.title, url: issue.url, repository: issue.repository };
|
|
270
279
|
}
|
|
271
280
|
return details;
|
|
272
281
|
}
|