@andrioid/paseo-attention-span 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OVERVIEW.md +116 -42
- package/README.md +12 -12
- package/client/attention-screen.tsx +232 -175
- package/client/card.tsx +141 -0
- package/client/coverage-settings.tsx +73 -20
- package/client/data.ts +2 -1
- package/client/icons.ts +3 -0
- package/client/next-up.tsx +266 -62
- package/client/session-menu.ts +45 -0
- package/client/sessions.ts +10 -8
- package/client/sheet.tsx +75 -3
- package/client/ui.tsx +91 -9
- package/docs/screenshots/desktop-dark-doing.png +0 -0
- package/docs/screenshots/desktop-dark-next-up.png +0 -0
- package/docs/screenshots/phone-dark-doing.png +0 -0
- package/index.server.ts +21 -19
- package/package.json +1 -1
- package/paseo-plugin.json +4 -2
- package/server/actions.ts +15 -1
- package/server/classify.ts +21 -13
- package/server/fixture.ts +34 -14
- package/server/github-types.ts +5 -1
- package/server/queries.ts +44 -13
- package/server/service.ts +90 -16
- package/server/setup.ts +12 -5
- package/server/store.ts +18 -2
- package/server/view.ts +72 -1
- package/shared/attention.ts +34 -2
- package/shared/config.ts +20 -3
- package/shared/format.ts +16 -0
- package/shared/rpc.ts +19 -11
- package/shared/setup.ts +2 -0
package/client/ui.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PluginScreenProps } from "@getpaseo/plugin/client";
|
|
2
2
|
import { copyText, Icon, useToast } from "@getpaseo/plugin/client/ui";
|
|
3
|
-
import { createContext, type ReactNode, useContext, useMemo, useState } from "react";
|
|
4
|
-
import { Image, Pressable, Text, View } from "react-native";
|
|
3
|
+
import { createContext, type ReactNode, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { ActivityIndicator, Animated, Easing, Image, Platform, Pressable, Text, View } from "react-native";
|
|
5
5
|
import type { Chip } from "../shared/attention";
|
|
6
6
|
import { ICONS, type IconName } from "./icons";
|
|
7
7
|
|
|
@@ -54,17 +54,45 @@ export function TablerIcon({ name, size = 16, color }: { name: IconName; size?:
|
|
|
54
54
|
return <Icon icon={ICONS[name]} size={size} color={color ?? c.foregroundMuted} />;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// An icon that turns while something runs, like ⟳ while its feed is fetched.
|
|
58
|
+
export function SpinningIcon({ name, size = 16, color, spinning }: { name: IconName; size?: number; color?: string; spinning: boolean }) {
|
|
59
|
+
const turn = useRef(new Animated.Value(0)).current;
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!spinning) return;
|
|
62
|
+
const loop = Animated.loop(Animated.timing(turn, { toValue: 1, duration: 1000, easing: Easing.linear, useNativeDriver: Platform.OS !== "web" }));
|
|
63
|
+
loop.start();
|
|
64
|
+
return () => (loop.stop(), turn.setValue(0));
|
|
65
|
+
}, [spinning, turn]);
|
|
66
|
+
const rotate = turn.interpolate({ inputRange: [0, 1], outputRange: ["0deg", "360deg"] });
|
|
67
|
+
return (
|
|
68
|
+
<Animated.View style={{ transform: [{ rotate }] }}>
|
|
69
|
+
<TablerIcon name={name} size={size} color={color} />
|
|
70
|
+
</Animated.View>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// What's loading, with a spinner so it doesn't read as stuck.
|
|
75
|
+
export function Loading({ text }: { text: string }) {
|
|
76
|
+
const styles = useStyles();
|
|
77
|
+
return (
|
|
78
|
+
<View style={styles.row}>
|
|
79
|
+
<ActivityIndicator size="small" color={styles.c.foregroundMuted} />
|
|
80
|
+
<Text style={styles.muted}>{text}</Text>
|
|
81
|
+
</View>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
57
85
|
export function toneColor(styles: Styles, tone: Chip["tone"]): string {
|
|
58
86
|
return { good: styles.c.statusSuccess, bad: styles.c.statusDanger, warn: styles.c.statusWarning, neutral: styles.c.foregroundMuted }[tone];
|
|
59
87
|
}
|
|
60
88
|
|
|
61
|
-
// A state that matters, as a colored dot and text.
|
|
62
|
-
export function Signal({ text, tone }: Chip) {
|
|
89
|
+
// A state that matters, as a colored dot (or its icon) and text.
|
|
90
|
+
export function Signal({ text, tone, icon }: Chip) {
|
|
63
91
|
const styles = useStyles();
|
|
64
92
|
const color = toneColor(styles, tone);
|
|
65
93
|
return (
|
|
66
94
|
<View style={[styles.row, { gap: 5 }]}>
|
|
67
|
-
<View style={{ width: 7, height: 7, borderRadius: 4, backgroundColor: color }} />
|
|
95
|
+
{icon ? <TablerIcon name={icon} size={13} color={color} /> : <View style={{ width: 7, height: 7, borderRadius: 4, backgroundColor: color }} />}
|
|
68
96
|
<Text style={{ color, fontSize: 12, fontWeight: "500" }}>{text}</Text>
|
|
69
97
|
</View>
|
|
70
98
|
);
|
|
@@ -73,8 +101,9 @@ export function Signal({ text, tone }: Chip) {
|
|
|
73
101
|
// The line under a title: facts as quiet text joined by "·", then signals [ATT-05].
|
|
74
102
|
export function Meta({ facts, chips }: { facts: string[]; chips: Chip[] }) {
|
|
75
103
|
const styles = useStyles();
|
|
76
|
-
const
|
|
77
|
-
const
|
|
104
|
+
const quiet = (chip: Chip) => chip.tone === "neutral" && !chip.icon;
|
|
105
|
+
const text = [...facts, ...chips.filter(quiet).map((chip) => chip.text)];
|
|
106
|
+
const signals = chips.filter((chip) => !quiet(chip));
|
|
78
107
|
return (
|
|
79
108
|
<View style={[styles.wrap, { columnGap: 10, rowGap: 4 }]}>
|
|
80
109
|
{text.length ? <Text style={styles.muted}>{text.join(" · ")}</Text> : null}
|
|
@@ -100,20 +129,26 @@ export function useHover() {
|
|
|
100
129
|
}
|
|
101
130
|
|
|
102
131
|
// Calm by default: accent text on a subtle surface. Solid accent is for confirmations.
|
|
132
|
+
// Busy: a spinner in place of the icon, and no second press while it runs.
|
|
103
133
|
export function Button({
|
|
104
134
|
label,
|
|
105
135
|
icon,
|
|
106
136
|
onPress,
|
|
107
137
|
variant = "plain",
|
|
108
138
|
disabled,
|
|
139
|
+
busy,
|
|
109
140
|
accessibilityLabel,
|
|
141
|
+
joined,
|
|
110
142
|
}: {
|
|
111
143
|
label?: string;
|
|
112
144
|
icon?: IconName;
|
|
113
145
|
onPress: () => void;
|
|
114
146
|
variant?: Variant;
|
|
115
147
|
disabled?: boolean;
|
|
148
|
+
busy?: boolean;
|
|
116
149
|
accessibilityLabel?: string;
|
|
150
|
+
// One half of a split button: square on the side it joins.
|
|
151
|
+
joined?: "start" | "end";
|
|
117
152
|
}) {
|
|
118
153
|
const styles = useStyles();
|
|
119
154
|
const { hovered, hover } = useHover();
|
|
@@ -123,7 +158,8 @@ export function Button({
|
|
|
123
158
|
<Pressable
|
|
124
159
|
accessibilityRole="button"
|
|
125
160
|
accessibilityLabel={accessibilityLabel ?? label ?? icon}
|
|
126
|
-
|
|
161
|
+
accessibilityState={{ disabled: disabled || busy, busy }}
|
|
162
|
+
disabled={disabled || busy}
|
|
127
163
|
onPress={onPress}
|
|
128
164
|
{...hover}
|
|
129
165
|
style={({ pressed }) => ({
|
|
@@ -133,16 +169,62 @@ export function Button({
|
|
|
133
169
|
height: 30,
|
|
134
170
|
paddingHorizontal: label ? 11 : 8,
|
|
135
171
|
borderRadius: 8,
|
|
172
|
+
...(joined === "start" ? { borderTopRightRadius: 0, borderBottomRightRadius: 0 } : joined === "end" ? { borderTopLeftRadius: 0, borderBottomLeftRadius: 0, paddingHorizontal: 6 } : null),
|
|
136
173
|
backgroundColor: variant === "solid" ? c.accent : hovered || (pressed && variant === "ghost") ? c.border : variant === "ghost" ? "transparent" : c.surface2,
|
|
137
174
|
opacity: disabled ? 0.5 : pressed ? 0.8 : 1,
|
|
138
175
|
})}
|
|
139
176
|
>
|
|
140
|
-
{icon ? <TablerIcon name={icon} size={15} color={color} /> : null}
|
|
177
|
+
{busy ? <ActivityIndicator size="small" color={color} style={{ width: 15, height: 15 }} /> : icon ? <TablerIcon name={icon} size={15} color={color} /> : null}
|
|
141
178
|
{label ? <Text style={{ color, fontSize: 13, fontWeight: "600" }}>{label}</Text> : null}
|
|
142
179
|
</Pressable>
|
|
143
180
|
);
|
|
144
181
|
}
|
|
145
182
|
|
|
183
|
+
// Where a menu opens from, in window coordinates.
|
|
184
|
+
export interface Anchor {
|
|
185
|
+
x: number;
|
|
186
|
+
y: number;
|
|
187
|
+
width: number;
|
|
188
|
+
height: number;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Measures a view, for a menu that opens under it.
|
|
192
|
+
export function useAnchor() {
|
|
193
|
+
const ref = useRef<View>(null);
|
|
194
|
+
const measure = (then: (anchor: Anchor | undefined) => void) => {
|
|
195
|
+
if (!ref.current) return then(undefined);
|
|
196
|
+
ref.current.measureInWindow((x, y, width, height) => then(width || height ? { x, y, width, height } : undefined));
|
|
197
|
+
};
|
|
198
|
+
return { ref, measure };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// The action, and ▾ for the choices around it [SES-03].
|
|
202
|
+
export function SplitButton({
|
|
203
|
+
label,
|
|
204
|
+
icon,
|
|
205
|
+
onPress,
|
|
206
|
+
onMenu,
|
|
207
|
+
menuLabel,
|
|
208
|
+
busy,
|
|
209
|
+
accessibilityLabel,
|
|
210
|
+
}: {
|
|
211
|
+
label: string;
|
|
212
|
+
icon?: IconName;
|
|
213
|
+
onPress: () => void;
|
|
214
|
+
onMenu: (anchor: Anchor | undefined) => void;
|
|
215
|
+
menuLabel: string;
|
|
216
|
+
busy?: boolean;
|
|
217
|
+
accessibilityLabel?: string;
|
|
218
|
+
}) {
|
|
219
|
+
const { ref, measure } = useAnchor();
|
|
220
|
+
return (
|
|
221
|
+
<View ref={ref} collapsable={false} style={{ flexDirection: "row", gap: 1 }}>
|
|
222
|
+
<Button label={label} icon={icon} variant="calm" busy={busy} accessibilityLabel={accessibilityLabel} onPress={onPress} joined="start" />
|
|
223
|
+
<Button icon="chevronDown" variant="calm" disabled={busy} accessibilityLabel={menuLabel} onPress={() => measure(onMenu)} joined="end" />
|
|
224
|
+
</View>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
146
228
|
// Sentence case, with the count as quiet text.
|
|
147
229
|
export function SectionHeader({ icon, title, count, action }: { icon: IconName; title: string; count: number; action?: ReactNode }) {
|
|
148
230
|
const styles = useStyles();
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.server.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
2
|
-
import { claimIssue, closePullRequest, mergePullRequest, react, rerunFailed, setAutoMerge, setReady, unclaimIssue, updateBranch } from "./server/actions";
|
|
2
|
+
import { claimIssue, closeIssue, closePullRequest, mergePullRequest, react, reopenIssue, rerunFailed, setAutoMerge, setReady, unclaimIssue, updateBranch } from "./server/actions";
|
|
3
3
|
import { defaultBranch, sessionContext } from "./server/context";
|
|
4
4
|
import { itemDetails } from "./server/details";
|
|
5
5
|
import { FIXTURE_CONTEXT, fixtureDetails } from "./server/fixture";
|
|
6
6
|
import { FIXTURE } from "./server/gh";
|
|
7
|
-
import { checkCoverage, configStatus, setupStatus } from "./server/setup";
|
|
8
|
-
import { AttentionService } from "./server/service";
|
|
9
|
-
import type {
|
|
7
|
+
import { checkCoverage, configStatus, myOrgs, setupStatus } from "./server/setup";
|
|
8
|
+
import { AttentionService, type Change } from "./server/service";
|
|
9
|
+
import type { Chip } from "./shared/attention";
|
|
10
10
|
import * as rpc from "./shared/rpc";
|
|
11
11
|
|
|
12
12
|
export default function contribute(server: PluginServerContext) {
|
|
@@ -14,12 +14,9 @@ export default function contribute(server: PluginServerContext) {
|
|
|
14
14
|
const started = attention.start().catch((error) => console.error("Attention Span failed to start:", error));
|
|
15
15
|
const ready = <T>(work: () => Promise<T>) => started.then(work);
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
for (const feed of feeds) void attention.refresh(feed).catch(() => {});
|
|
21
|
-
return { ok: true as const };
|
|
22
|
-
};
|
|
17
|
+
// A change on GitHub, answered with the list after it; what it does to the card shows right away [FRESH-02].
|
|
18
|
+
const act = (key: string, work: () => Promise<void>, change: Change) => ready(() => attention.act(key, work, change));
|
|
19
|
+
const chip = (text: string, tone: Chip["tone"] = "neutral", icon?: Chip["icon"]): Change => ({ kind: "chip", chip: { text, tone, ...(icon ? { icon } : {}) } });
|
|
23
20
|
|
|
24
21
|
// The app asks for the list on load and every few minutes; its Paseo connection lets refreshes see my projects [NXT-08].
|
|
25
22
|
server.handle(rpc.getAttention, ({ refresh }, { paseo }) => ready(() => (attention.connect(paseo), attention.get(refresh))));
|
|
@@ -31,16 +28,21 @@ export default function contribute(server: PluginServerContext) {
|
|
|
31
28
|
server.handle(rpc.getCoverage, () => configStatus());
|
|
32
29
|
server.handle(rpc.checkCoverage, ({ kind, name }) => checkCoverage(kind, name));
|
|
33
30
|
server.handle(rpc.setCoverage, ({ orgs, repos }) => ready(() => attention.setCoverage(orgs, repos)).then(() => ({ ok: true as const })));
|
|
31
|
+
server.handle(rpc.setNextUpSources, (sources) => ready(() => attention.setNextUpSources(sources)).then(() => ({ ok: true as const })));
|
|
32
|
+
server.handle(rpc.myOrgs, async () => ({ orgs: await myOrgs() }));
|
|
34
33
|
server.handle(rpc.setScopes, ({ scopes }) => ready(() => attention.setScopes(scopes)).then(() => ({ ok: true as const })));
|
|
35
|
-
server.handle(rpc.
|
|
36
|
-
server.handle(rpc.
|
|
37
|
-
server.handle(rpc.
|
|
38
|
-
server.handle(rpc.
|
|
39
|
-
server.handle(rpc.
|
|
40
|
-
server.handle(rpc.
|
|
41
|
-
server.handle(rpc.
|
|
42
|
-
server.handle(rpc.
|
|
43
|
-
server.handle(rpc.
|
|
34
|
+
server.handle(rpc.setSources, ({ sources }) => ready(() => attention.setSources(sources)).then(() => ({ ok: true as const })));
|
|
35
|
+
server.handle(rpc.updateBranch, ({ key, target }) => act(key, () => updateBranch(target), chip("updating")));
|
|
36
|
+
server.handle(rpc.mergePullRequest, ({ key, target }) => act(key, () => mergePullRequest(target), { kind: "finished" }));
|
|
37
|
+
server.handle(rpc.closePullRequest, ({ key, target, comment }) => act(key, () => closePullRequest(target, comment), { kind: "gone" }));
|
|
38
|
+
server.handle(rpc.claimIssue, ({ key, target }) => act(key, () => claimIssue(target), { kind: "claimed" }));
|
|
39
|
+
server.handle(rpc.unclaimIssue, ({ key, target }) => act(key, () => unclaimIssue(target), { kind: "unclaimed" }));
|
|
40
|
+
server.handle(rpc.closeIssue, ({ key, target, reason, comment }) => act(key, () => closeIssue(target, reason, comment), { kind: "finished", notPlanned: reason === "not_planned" }));
|
|
41
|
+
server.handle(rpc.reopenIssue, ({ key, target }) => act(key, () => reopenIssue(target), null));
|
|
42
|
+
server.handle(rpc.setReady, ({ key, target, ready }) => act(key, () => setReady(target, ready), ready ? chip("ready for review", "good") : null));
|
|
43
|
+
server.handle(rpc.setAutoMerge, ({ key, target, on }) => act(key, () => setAutoMerge(target, on), on ? chip("auto-merge on", "good") : null));
|
|
44
|
+
server.handle(rpc.react, ({ key, subjectIds, on }) => act(key, () => react(subjectIds, on), on ? chip("acknowledged", "neutral", "thumbUp") : null));
|
|
45
|
+
server.handle(rpc.rerunFailed, ({ key, repo, runIds }) => act(key, () => rerunFailed(repo, runIds), chip("rerunning")));
|
|
44
46
|
server.handle(rpc.itemDetails, ({ subject, target, checks }) => (FIXTURE ? Promise.resolve(fixtureDetails(subject, target, checks)) : itemDetails(subject, target, checks)));
|
|
45
47
|
server.handle(rpc.defaultBranch, async ({ repo }) => ({ name: FIXTURE ? "main" : await defaultBranch(repo) }));
|
|
46
48
|
server.handle(rpc.sessionContext, async ({ kind, target }) => ({ context: FIXTURE ? FIXTURE_CONTEXT : await sessionContext(kind, target) }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrioid/paseo-attention-span",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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/paseo-plugin.json
CHANGED
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
"icon": "assets/icon.png",
|
|
6
6
|
"media": [
|
|
7
7
|
"docs/screenshots/desktop-dark-doing.png",
|
|
8
|
-
"docs/screenshots/
|
|
9
|
-
"docs/screenshots/desktop-dark-next-up.png"
|
|
8
|
+
"docs/screenshots/desktop-dark-waiting.png",
|
|
9
|
+
"docs/screenshots/desktop-dark-next-up.png",
|
|
10
|
+
"docs/screenshots/desktop-dark-history.png",
|
|
11
|
+
"docs/screenshots/phone-dark-doing.png"
|
|
10
12
|
],
|
|
11
13
|
"requirements": {
|
|
12
14
|
"paseo": ">=0.13.0"
|
package/server/actions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Target } from "../shared/attention";
|
|
1
|
+
import type { IssueCloseReason, Target } from "../shared/attention";
|
|
2
2
|
import { graphql, runGh } from "./gh";
|
|
3
3
|
|
|
4
4
|
// Each action runs only from an explicit tap in Attention Span [SAFE-01].
|
|
@@ -46,6 +46,20 @@ export async function claimIssue(target: Target): Promise<void> {
|
|
|
46
46
|
if (code !== 0) throw new Error(stderr.trim() || "Claiming the issue failed");
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// Close an issue I won't pick up, as completed or not planned; comment only when I wrote one [NXT-11].
|
|
50
|
+
export async function closeIssue(target: Target, reason: IssueCloseReason, comment?: string): Promise<void> {
|
|
51
|
+
const args = ["issue", "close", String(target.number), "--repo", target.repo, "--reason", reason === "not_planned" ? "not planned" : "completed"];
|
|
52
|
+
if (comment?.trim()) args.push("--comment", comment.trim());
|
|
53
|
+
const { code, stderr } = await runGh(args);
|
|
54
|
+
if (code !== 0) throw new Error(stderr.trim() || "Closing the issue failed");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Undo of Close [NXT-11]. A comment already posted stays.
|
|
58
|
+
export async function reopenIssue(target: Target): Promise<void> {
|
|
59
|
+
const { code, stderr } = await runGh(["issue", "reopen", String(target.number), "--repo", target.repo]);
|
|
60
|
+
if (code !== 0) throw new Error(stderr.trim() || "Reopening the issue failed");
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
// Hand an assigned issue back; also undoes a claim [NXT-07].
|
|
50
64
|
export async function unclaimIssue(target: Target): Promise<void> {
|
|
51
65
|
const { code, stderr } = await runGh(["issue", "edit", String(target.number), "--repo", target.repo, "--remove-assignee", "@me"]);
|
package/server/classify.ts
CHANGED
|
@@ -362,19 +362,27 @@ function rankIssues(nodes: PickableNode[], details: Details, config: AttentionCo
|
|
|
362
362
|
return index < 0 ? Infinity : index;
|
|
363
363
|
};
|
|
364
364
|
return nodes
|
|
365
|
-
.map((node) =>
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
365
|
+
.map((node) => {
|
|
366
|
+
const rank = position(valueOf(node, priority?.field), priority);
|
|
367
|
+
return {
|
|
368
|
+
key: prKey(node),
|
|
369
|
+
repo: node.repository.nameWithOwner,
|
|
370
|
+
number: node.number,
|
|
371
|
+
title: node.title,
|
|
372
|
+
url: node.url,
|
|
373
|
+
createdAt: node.createdAt,
|
|
374
|
+
type: node.issueType?.name,
|
|
375
|
+
priority: valueOf(node, priority?.field),
|
|
376
|
+
effort: valueOf(node, effort?.field),
|
|
377
|
+
scope: valueOf(node, scope?.field),
|
|
378
|
+
defaultBranch: node.repository.defaultBranchRef?.name,
|
|
379
|
+
sources: node.sources ?? [],
|
|
380
|
+
priorityRank: Number.isFinite(rank) ? rank : undefined,
|
|
381
|
+
openPrs: (node.closedByPullRequestsReferences?.nodes ?? [])
|
|
382
|
+
.filter((pr) => pr?.state === "OPEN")
|
|
383
|
+
.map((pr) => ({ number: pr.number, url: pr.url, author: pr.author?.login ?? null })),
|
|
384
|
+
};
|
|
385
|
+
})
|
|
378
386
|
.sort(
|
|
379
387
|
(a, b) =>
|
|
380
388
|
position(a.priority, priority) - position(b.priority, priority) ||
|
package/server/fixture.ts
CHANGED
|
@@ -8,7 +8,9 @@ export const REPO = "acme/shop";
|
|
|
8
8
|
export const ISSUES_REPO = "acme/issues";
|
|
9
9
|
// What the settings screen can add in previews [SRC-02]; anything else isn't found.
|
|
10
10
|
export const FIXTURE_ORGS = ["acme"];
|
|
11
|
-
export const FIXTURE_REPOS = [REPO, ISSUES_REPO, "acme/web"];
|
|
11
|
+
export const FIXTURE_REPOS = [REPO, ISSUES_REPO, "acme/web", "me/tool"];
|
|
12
|
+
// The orgs Next up's org picker offers in previews [NXT-04].
|
|
13
|
+
export const FIXTURE_MY_ORGS = ["acme", "globex"];
|
|
12
14
|
const repository = { nameWithOwner: REPO, squashMergeAllowed: true, defaultBranchRef: { name: "main" } };
|
|
13
15
|
const avatar = (id: number) => `https://avatars.githubusercontent.com/u/${id}?v=4`;
|
|
14
16
|
|
|
@@ -179,13 +181,19 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
179
181
|
pickable(150, fields("🏔 P1 High", "🐇 Small (0.5-2d)", "🔙 Backend"), 20, "Bug", "Orders export times out for big shops"),
|
|
180
182
|
pickable(151, fields("🏕P2 Medium", "🐟 Tiny (< 4h)", "🔙 Backend"), 5, "Bug", "Price list import skips quoted rows", ISSUES_REPO),
|
|
181
183
|
],
|
|
184
|
+
// Found by the preview config's Next up sources [NXT-09].
|
|
182
185
|
unclaimed: [
|
|
183
|
-
pickable(160, fields("
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
{ ...pickable(160, fields("🌋 P0 Urgent", "🐂 Medium (2-5d)", "🕵 Full-stack"), 40, "Feature", "Follow-up emails for unanswered offers"), sources: ["org:acme"] },
|
|
187
|
+
// Nobody's assigned, but alice has a PR open for it [NXT-10].
|
|
188
|
+
{
|
|
189
|
+
...pickable(161, fields("🏝 P3 Low", "🐟 Tiny (< 4h)", "🔙 Backend"), 15, "Bug", "Deleted employee still shows in the calendar"),
|
|
190
|
+
closedByPullRequestsReferences: { nodes: [{ number: 190, url: `https://github.com/${REPO}/pull/190`, state: "OPEN", author: { login: "alice" } }] },
|
|
191
|
+
sources: ["org:acme"],
|
|
192
|
+
},
|
|
193
|
+
{ ...pickable(162, fields("🏝 P3 Low", "🐇 Small (0.5-2d)", "🔙 Backend"), 30, "Debt", "Merge the two import commands"), sources: ["org:acme"] },
|
|
194
|
+
{ ...pickable(163, fields("🏝 P3 Low", "🐇 Small (0.5-2d)", "🖌 Frontend"), 8, "Bug", "Moving a task in the calendar loses its colour"), sources: ["org:acme"] },
|
|
195
|
+
{ ...pickable(164, fields("🏝 P3 Low", "🦑 Large (1-2w)", "📱 Mobile app"), 60, "Feature", "Offline mode for time tracking"), sources: ["org:acme"] },
|
|
196
|
+
{ ...pickable(165, {}, 3, "Task", "Devcontainers for pull requests", "me/tool"), sources: ["mine"] },
|
|
189
197
|
],
|
|
190
198
|
merged: [merged(170, "Nightly backup check", 1, 171), merged(172, "Fix VAT on credit notes", 3), merged(173, "Speed up the order list", 9, 174), merged(175, "Remove the old importer", 16)],
|
|
191
199
|
reviewed: [
|
|
@@ -199,13 +207,25 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
199
207
|
}
|
|
200
208
|
|
|
201
209
|
// Sessions the preview shows as started from items: working, needs me, failed, idle.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
210
|
+
// Issue 90 has two, one on the issue and one on its PR, so the card shows the pick. #113 waits on CI while its agent works.
|
|
211
|
+
const agent = (id: string, itemKey: string, status: string, minutesAgo: number, requiresAttention = false): AgentSummary => ({
|
|
212
|
+
id,
|
|
213
|
+
itemKey,
|
|
214
|
+
status,
|
|
215
|
+
requiresAttention,
|
|
216
|
+
title: `Fixture session ${id}`,
|
|
217
|
+
workspaceId: null,
|
|
218
|
+
lastActivityAt: new Date(Date.now() - minutesAgo * 60_000).toISOString(),
|
|
219
|
+
});
|
|
220
|
+
export const FIXTURE_AGENTS: AgentSummary[] = [
|
|
221
|
+
agent("agent-101", `${REPO}#101`, "running", 4),
|
|
222
|
+
agent("agent-102", `${REPO}#102`, "idle", 30, true),
|
|
223
|
+
agent("agent-108", `${REPO}#108`, "error", 90),
|
|
224
|
+
agent("agent-150", `${REPO}#150`, "idle", 300),
|
|
225
|
+
agent("agent-90", `${REPO}#90`, "idle", 120, true),
|
|
226
|
+
agent("agent-103", `${REPO}#103`, "running", 6),
|
|
227
|
+
agent("agent-113", `${REPO}#113`, "running", 2),
|
|
228
|
+
];
|
|
209
229
|
|
|
210
230
|
export const FIXTURE_CONTEXT = "Context from GitHub would go here (fixture mode).";
|
|
211
231
|
|
package/server/github-types.ts
CHANGED
|
@@ -80,9 +80,13 @@ export interface PickableNode {
|
|
|
80
80
|
title: string;
|
|
81
81
|
url: string;
|
|
82
82
|
createdAt: string;
|
|
83
|
-
repository: Repo;
|
|
83
|
+
repository: Repo & { isFork?: boolean };
|
|
84
84
|
issueType: { name: string } | null;
|
|
85
85
|
issueFieldValues: Nodes<{ name?: string; field?: { name: string } }>;
|
|
86
|
+
// Open PRs that close it, so a card can say someone is on it [NXT-10].
|
|
87
|
+
closedByPullRequestsReferences?: Nodes<{ number: number; url: string; state: string; author: { login: string } | null }>;
|
|
88
|
+
// Added after the search: the Next up sources that found it [NXT-09].
|
|
89
|
+
sources?: string[];
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
// One request per search, merged [GH-01].
|
package/server/queries.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UnclaimedSource } from "../shared/attention";
|
|
2
2
|
import type { AttentionConfig } from "../shared/config";
|
|
3
|
-
import type { PullRequestNode } from "./github-types";
|
|
3
|
+
import type { PickableNode, PullRequestNode } from "./github-types";
|
|
4
4
|
|
|
5
5
|
// Each search with how many results it asks for and what it reads of each.
|
|
6
6
|
const SEARCHES = {
|
|
@@ -42,9 +42,10 @@ const FRAGMENTS: Record<string, string> = {
|
|
|
42
42
|
}`,
|
|
43
43
|
pickable: `fragment pickable on Issue {
|
|
44
44
|
number title url createdAt
|
|
45
|
-
repository { nameWithOwner defaultBranchRef { name } }
|
|
45
|
+
repository { nameWithOwner isFork defaultBranchRef { name } }
|
|
46
46
|
issueType { name }
|
|
47
47
|
issueFieldValues(first: 20) { nodes { ... on IssueFieldSingleSelectValue { name field { ... on IssueFieldCommon { name } } } } }
|
|
48
|
+
closedByPullRequestsReferences(first: 5, includeClosedPrs: false) { nodes { number url state author { login } } }
|
|
48
49
|
}`,
|
|
49
50
|
pr: `fragment pr on PullRequest {
|
|
50
51
|
id number title url isDraft createdAt updatedAt
|
|
@@ -98,18 +99,50 @@ function startOfWeek(now: Date): Date {
|
|
|
98
99
|
return monday;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
// Where Next up looks for unclaimed issues
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
// Where Next up looks for unclaimed issues [NXT-04, NXT-08]: one search per chosen source, so each issue says which
|
|
103
|
+
// sources found it and no query outgrows GitHub's limit [NXT-09]. Without sources, the configured orgs and repos,
|
|
104
|
+
// else my Paseo projects' repos. Never all of GitHub: unlike the other searches, this one isn't about me.
|
|
105
|
+
export function unclaimedSearches(config: AttentionConfig, projectRepos: string[], login: string | null): { from: UnclaimedSource; searches: UnclaimedSearch[] } {
|
|
106
|
+
const search = (source: string | null, scope: string) => ({ source, query: `is:issue is:open no:assignee ${scope}` });
|
|
107
|
+
const { mine, orgs, repos } = config.nextUp;
|
|
108
|
+
if (mine || orgs.length || repos.length) {
|
|
109
|
+
if (mine && !login) throw new Error("Couldn't tell which GitHub account is yours, for My repos");
|
|
110
|
+
return {
|
|
111
|
+
from: "config",
|
|
112
|
+
searches: [
|
|
113
|
+
...(mine ? [search("mine", `user:${login} archived:false`)] : []),
|
|
114
|
+
...orgs.map((org) => search(`org:${org}`, where([org], []))),
|
|
115
|
+
...repos.map((repo) => search(`repo:${repo}`, where([], [repo]))),
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (config.orgs.length || config.repos.length) return { from: "config", searches: [search(null, where(config.orgs, config.repos))] };
|
|
120
|
+
return projectRepos.length ? { from: "projects", searches: [search(null, where([], projectRepos))] } : { from: "none", searches: [] };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// One search's query, and the source it stands for; null when Next up has no sources of its own.
|
|
124
|
+
export interface UnclaimedSearch {
|
|
125
|
+
source: string | null;
|
|
126
|
+
query: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// An issue found by several sources is listed once, under each of them [NXT-09]. Forks don't count as my repos.
|
|
130
|
+
export function mergeUnclaimed(results: { source: string | null; nodes: (PickableNode | null)[] }[]): PickableNode[] {
|
|
131
|
+
const byKey = new Map<string, PickableNode>();
|
|
132
|
+
for (const { source, nodes } of results) {
|
|
133
|
+
for (const node of nodes) {
|
|
134
|
+
if (!node?.repository || (source === "mine" && node.repository.isFork)) continue;
|
|
135
|
+
const seen = byKey.get(prKey(node)) ?? { ...node, sources: [] };
|
|
136
|
+
if (source && !seen.sources!.includes(source)) seen.sources!.push(source);
|
|
137
|
+
byKey.set(prKey(node), seen);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return [...byKey.values()];
|
|
107
141
|
}
|
|
108
142
|
|
|
109
|
-
//
|
|
110
|
-
export function searchVariables(config: AttentionConfig, now: Date
|
|
143
|
+
// The searches about me. Next up's unclaimed issues have their own [NXT-04].
|
|
144
|
+
export function searchVariables(config: AttentionConfig, now: Date): Record<Exclude<SearchName, "unclaimed">, string> {
|
|
111
145
|
const scope = where(config.orgs, config.repos);
|
|
112
|
-
const unclaimed = unclaimedScope(config, projectRepos).scope;
|
|
113
146
|
const since = isoDate(new Date(now.getTime() - config.mentionDays * 86_400_000));
|
|
114
147
|
// Whole weeks, from a Monday, so the oldest week isn't cut short.
|
|
115
148
|
const history = isoDate(new Date(startOfWeek(now).getTime() - (config.historyWeeks - 1) * 7 * 86_400_000));
|
|
@@ -120,8 +153,6 @@ export function searchVariables(config: AttentionConfig, now: Date, projectRepos
|
|
|
120
153
|
mentions: `is:open mentions:@me updated:>=${since} ${scope}`,
|
|
121
154
|
assigned: `is:issue is:open assignee:@me ${scope}`,
|
|
122
155
|
commented: `is:issue is:open commenter:@me updated:>=${since} ${scope}`,
|
|
123
|
-
// [NXT-01, NXT-04, NXT-08]
|
|
124
|
-
unclaimed: unclaimed && `is:issue is:open no:assignee ${unclaimed}`,
|
|
125
156
|
// History [HIS-01, HIS-02]
|
|
126
157
|
merged: `is:pr is:merged author:@me merged:>=${history} ${scope}`,
|
|
127
158
|
reviewed: `is:pr is:merged reviewed-by:@me -author:@me merged:>=${history} ${scope}`,
|