@andrioid/paseo-attention-span 0.3.1 → 0.3.3
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/client/coverage-settings.tsx +3 -16
- package/docs/architecture.md +3 -3
- package/index.client.tsx +5 -15
- package/package.json +1 -1
- package/requirements.yaml +0 -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/client/host.ts +0 -8
|
@@ -5,8 +5,7 @@ import { useState } from "react";
|
|
|
5
5
|
import { Text, View } from "react-native";
|
|
6
6
|
import * as rpc from "../shared/rpc";
|
|
7
7
|
import type { ConfigStatus, CoverageKind } from "../shared/setup";
|
|
8
|
-
import {
|
|
9
|
-
import { useHostLabel } from "./host";
|
|
8
|
+
import { VIEW_QUERY_KEY } from "./data";
|
|
10
9
|
import { Button, StylesProvider, useStyles } from "./ui";
|
|
11
10
|
|
|
12
11
|
const COVERAGE_QUERY_KEY = ["attention-span", "coverage"] as const;
|
|
@@ -16,26 +15,14 @@ const CAPTION = { marginTop: -24, marginBottom: 16 };
|
|
|
16
15
|
|
|
17
16
|
// Settings → Plugins → Attention Span: which orgs and repos the lists cover, and where Next up looks,
|
|
18
17
|
// saved to config.json [SRC-02, NXT-04].
|
|
19
|
-
export function CoverageSettings({ theme, layout
|
|
18
|
+
export function CoverageSettings({ theme, layout }: PluginSurfaceProps) {
|
|
20
19
|
return (
|
|
21
20
|
<StylesProvider theme={theme} compact={layout.compact}>
|
|
22
|
-
<
|
|
23
|
-
<HostLine host={host} />
|
|
24
|
-
<Coverage />
|
|
25
|
-
</View>
|
|
21
|
+
<Coverage />
|
|
26
22
|
</StylesProvider>
|
|
27
23
|
);
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
// Which host's config.json this edits, and its GitHub account, when there are several hosts [REACH-02].
|
|
31
|
-
function HostLine({ host }: Pick<PluginSurfaceProps, "host">) {
|
|
32
|
-
const styles = useStyles();
|
|
33
|
-
const label = useHostLabel(host);
|
|
34
|
-
const login = useAttention().data?.login;
|
|
35
|
-
if (!label) return null;
|
|
36
|
-
return <Text style={styles.muted}>{login ? `These settings are for ${label}, signed in to GitHub as @${login}.` : `These settings are for ${label}.`}</Text>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
26
|
function Coverage() {
|
|
40
27
|
const styles = useStyles();
|
|
41
28
|
const queryClient = useQueryClient();
|
package/docs/architecture.md
CHANGED
|
@@ -25,8 +25,8 @@ flowchart LR
|
|
|
25
25
|
|
|
26
26
|
- **Paseo plugin**, installed per daemon.
|
|
27
27
|
- Client: one screen and a sidebar header item. React Native primitives only, so it works on phone and desktop [REACH-01].
|
|
28
|
-
- With more than one host in the app, each host runs its own copy, with its own `gh` login, `config.json` and `state.json`. The sidebar row shows the host's name beside the count, and settings say which host they're for and its GitHub login. The app doesn't say which other hosts have the plugin, so any second host counts [REACH-02].
|
|
29
28
|
- Server: RPC handlers for fetching and for GitHub actions.
|
|
29
|
+
- With several hosts, each runs its own copy, with its own `gh` login, `config.json` and `state.json`. Paseo shows one sidebar row for all of them and switches hosts with the picker in the screen's header; the row follows the host in view, else the one picked last.
|
|
30
30
|
- **GitHub access** goes through the host's existing `gh` login. The plugin stores no token [SEC-01].
|
|
31
31
|
- **Setup checklist** [SET-01]: when a refresh fails, the screen asks the server what setup needs (`gh api user` for whether `gh` is there and who it's signed in as, and whether `config.json` parses). If `gh` is missing or signed out, or the file is broken, a checklist takes the tabs' place. Each line says how to fix it, and Check again refreshes. It also lists what's covered, the Paseo projects with a GitHub remote, and which profile sessions will use. Other failures, like a network error, stay a red line above the tabs.
|
|
32
32
|
- **Settings screen** [SRC-02], under Settings → Plugins → Attention Span and the gear next to ⟳: orgs and repos, one per row. Each is checked with `gh api users/<org>` (it must be an organization, since searches use `org:`) or `gh api repos/<owner>/<name>` before it's saved, and GitHub's exact name is kept. Saving rewrites only `orgs` and `repos` in `config.json`, refuses a file that doesn't parse, and refreshes the lists. A Replies section has one switch, Follow threads I've commented on, which writes only `followThreads` [ATT-17].
|
|
@@ -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/index.client.tsx
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import type { PluginClientContext, PluginScreenProps, PluginSidebarItemProps } from "@getpaseo/plugin/client";
|
|
2
2
|
import { SidebarRow } from "@getpaseo/plugin/client/ui";
|
|
3
|
-
import { Text
|
|
3
|
+
import { Text } from "react-native";
|
|
4
4
|
import { AttentionScreen } from "./client/attention-screen";
|
|
5
5
|
import { CoverageSettings } from "./client/coverage-settings";
|
|
6
6
|
import { useAttention } from "./client/data";
|
|
7
7
|
import { returnFromFeedback } from "./client/feedback";
|
|
8
|
-
import { useHostLabel } from "./client/host";
|
|
9
8
|
import { ICONS } from "./client/icons";
|
|
10
9
|
|
|
11
|
-
// The count, visible from anywhere in Paseo [ATT-09]
|
|
12
|
-
function SidebarItem({ theme,
|
|
10
|
+
// The count, visible from anywhere in Paseo [ATT-09].
|
|
11
|
+
function SidebarItem({ theme, currentScreen, openScreen }: PluginSidebarItemProps) {
|
|
13
12
|
const { data } = useAttention();
|
|
14
|
-
const hostLabel = useHostLabel(host);
|
|
15
13
|
const count = data?.count ?? 0;
|
|
16
|
-
const muted = { color: theme.colors.foregroundMuted, fontSize: 12 };
|
|
17
14
|
return (
|
|
18
15
|
<SidebarRow
|
|
19
16
|
icon={ICONS.logo}
|
|
@@ -21,15 +18,8 @@ function SidebarItem({ theme, host, currentScreen, openScreen }: PluginSidebarIt
|
|
|
21
18
|
active={currentScreen?.screenId === "attention"}
|
|
22
19
|
onPress={() => openScreen({ screenId: "attention" })}
|
|
23
20
|
trailing={
|
|
24
|
-
|
|
25
|
-
<
|
|
26
|
-
{hostLabel ? (
|
|
27
|
-
<Text style={[muted, { maxWidth: 120 }]} numberOfLines={1}>
|
|
28
|
-
{hostLabel}
|
|
29
|
-
</Text>
|
|
30
|
-
) : null}
|
|
31
|
-
{count > 0 ? <Text style={[muted, data?.feeds.live.error ? { color: theme.colors.statusDanger } : null]}>{count}</Text> : null}
|
|
32
|
-
</View>
|
|
21
|
+
count > 0 ? (
|
|
22
|
+
<Text style={{ color: data?.feeds.live.error ? theme.colors.statusDanger : theme.colors.foregroundMuted, fontSize: 12 }}>{count}</Text>
|
|
33
23
|
) : undefined
|
|
34
24
|
}
|
|
35
25
|
/>
|
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.3",
|
|
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/requirements.yaml
CHANGED
|
@@ -114,7 +114,6 @@ non_functional:
|
|
|
114
114
|
PRIV-01: may keep a local copy of the GitHub data it shows; so that Attention Span shows instantly after a restart.
|
|
115
115
|
reach:
|
|
116
116
|
REACH-01: works in Paseo on both phone and desktop; so that I can triage from anywhere.
|
|
117
|
-
REACH-02: names its host in the sidebar and in settings when Paseo knows more than one host; so that I can tell which host's list and config.json I'm looking at.
|
|
118
117
|
freshness:
|
|
119
118
|
FRESH-01: stays current without me refreshing it; so that its count can be trusted.
|
|
120
119
|
FRESH-02: shows what I just did on GitHub right away, and keeps showing it until GitHub's search catches up; so that I never refresh to see it.
|
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
|
}
|
package/client/host.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type PluginHostProps, useHosts } from "@getpaseo/plugin/client";
|
|
2
|
-
|
|
3
|
-
// This host's name, once the app knows more than one host, so two copies of Attention Span can be told apart [REACH-02].
|
|
4
|
-
// Hosts without the plugin count too: the app can't say which hosts have it.
|
|
5
|
-
export function useHostLabel(host: PluginHostProps["host"]): string | null {
|
|
6
|
-
const hosts = useHosts();
|
|
7
|
-
return hosts.length > 1 ? host.label : null;
|
|
8
|
-
}
|