@andrioid/paseo-attention-span 0.1.2 โ 0.1.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/OVERVIEW.md +3 -3
- package/client/attention-screen.tsx +79 -74
- package/client/card.tsx +129 -0
- package/client/coverage-settings.tsx +73 -20
- package/client/icons.ts +1 -0
- package/client/next-up.tsx +217 -47
- 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 +7 -2
- package/package.json +1 -1
- package/server/actions.ts +15 -1
- package/server/classify.ts +21 -13
- package/server/fixture.ts +15 -7
- package/server/github-types.ts +5 -1
- package/server/queries.ts +44 -13
- package/server/service.ts +35 -10
- package/server/setup.ts +12 -5
- package/server/store.ts +15 -2
- package/server/view.ts +1 -0
- package/shared/attention.ts +12 -1
- package/shared/config.ts +20 -3
- package/shared/format.ts +10 -0
- package/shared/rpc.ts +8 -1
- package/shared/setup.ts +2 -0
package/client/next-up.tsx
CHANGED
|
@@ -2,12 +2,15 @@ import { openExternalUrl } from "@getpaseo/plugin/client";
|
|
|
2
2
|
import { useQuery } from "@tanstack/react-query";
|
|
3
3
|
import { useMemo, useState } from "react";
|
|
4
4
|
import { Pressable, Text, View } from "react-native";
|
|
5
|
-
import { ago } from "../shared/format";
|
|
6
|
-
import type { AgentSummary, NextUpIssue, UnclaimedSource } from "../shared/attention";
|
|
5
|
+
import { ago, shortValue } from "../shared/format";
|
|
6
|
+
import type { AgentSummary, Chip, IssueCloseReason, NextUpIssue, UnclaimedSource } from "../shared/attention";
|
|
7
|
+
import type { NextUpSource } from "../shared/config";
|
|
7
8
|
import type { IconName } from "./icons";
|
|
8
9
|
import type { FetchDetails } from "./attention-screen";
|
|
10
|
+
import { CardList, CardRow, type Tone } from "./card";
|
|
9
11
|
import { ActionSheet, DetailLines, type SheetEntry } from "./sheet";
|
|
10
|
-
import {
|
|
12
|
+
import { Modal } from "@getpaseo/plugin/client/ui";
|
|
13
|
+
import { Button, KeepStyles, Meta, SectionHeader, TablerIcon, useHover, useStyles } from "./ui";
|
|
11
14
|
|
|
12
15
|
const TYPE_ICONS: Record<string, IconName> = { bug: "bug", feature: "feature", debt: "debt", task: "task", epic: "epic" };
|
|
13
16
|
|
|
@@ -15,28 +18,46 @@ interface Props {
|
|
|
15
18
|
assigned: NextUpIssue[];
|
|
16
19
|
unclaimed: NextUpIssue[];
|
|
17
20
|
unclaimedFrom: UnclaimedSource;
|
|
18
|
-
//
|
|
21
|
+
// Scopes I ticked in the filter; none means all [NXT-03].
|
|
19
22
|
selected: string[];
|
|
20
23
|
onSelect: (scopes: string[]) => void;
|
|
24
|
+
// Where Next up looks, and the sources I ticked; none means all [NXT-09].
|
|
25
|
+
sources: NextUpSource[];
|
|
26
|
+
selectedSources: string[];
|
|
27
|
+
onSelectSources: (sources: string[]) => void;
|
|
21
28
|
agents: Record<string, AgentSummary>;
|
|
22
29
|
busy: string | null;
|
|
23
30
|
fetchDetails: FetchDetails;
|
|
24
31
|
onStart: (issue: NextUpIssue, claim: boolean) => void;
|
|
25
32
|
// Claim without starting, or give an assigned issue back [NXT-07].
|
|
26
33
|
onClaim: (issue: NextUpIssue, on: boolean) => void;
|
|
34
|
+
// Close it, once I've confirmed the reason [NXT-11].
|
|
35
|
+
onCloseIssue: (issue: NextUpIssue, reason: IssueCloseReason, comment: string) => void;
|
|
27
36
|
onOpenAgent: (agentId: string) => void;
|
|
28
37
|
}
|
|
29
38
|
|
|
30
|
-
type RowProps = Omit<Props, "assigned" | "unclaimed" | "unclaimedFrom" | "selected" | "onSelect">;
|
|
39
|
+
type RowProps = Omit<Props, "assigned" | "unclaimed" | "unclaimedFrom" | "selected" | "onSelect" | "sources" | "selectedSources" | "onSelectSources">;
|
|
31
40
|
|
|
32
41
|
// Assigned issues first [NXT-06], then unclaimed ones [NXT-01]; both already ranked by the server [NXT-02].
|
|
33
|
-
export function NextUpList({ assigned, unclaimed, unclaimedFrom, selected, onSelect, ...rowProps }: Props) {
|
|
42
|
+
export function NextUpList({ assigned, unclaimed, unclaimedFrom, selected, onSelect, sources, selectedSources, onSelectSources, ...rowProps }: Props) {
|
|
34
43
|
const styles = useStyles();
|
|
35
44
|
const scopes = useMemo(() => [...new Set(unclaimed.map((issue) => issue.scope).filter((scope): scope is string => !!scope))].sort(), [unclaimed]);
|
|
36
45
|
// Filter by the scopes I picked last time [NXT-03]; a picked scope with no issues left is ignored.
|
|
37
46
|
const active = selected.filter((scope) => scopes.includes(scope));
|
|
38
|
-
|
|
47
|
+
// And by source, when there's more than one [NXT-09]; a picked source no longer in settings is ignored.
|
|
48
|
+
const activeSources = sources.length > 1 ? selectedSources.filter((id) => sources.some((source) => source.id === id)) : [];
|
|
49
|
+
const shown = unclaimed.filter(
|
|
50
|
+
(issue) => (active.length === 0 || (issue.scope && active.includes(issue.scope))) && (activeSources.length === 0 || issue.sources.some((id) => activeSources.includes(id))),
|
|
51
|
+
);
|
|
39
52
|
const toggle = (scope: string) => onSelect(active.includes(scope) ? active.filter((s) => s !== scope) : [...active, scope]);
|
|
53
|
+
const toggleSource = (id: string) => onSelectSources(activeSources.includes(id) ? activeSources.filter((s) => s !== id) : [...activeSources, id]);
|
|
54
|
+
const narrowedBy = [activeSources.length ? "sources" : null, active.length ? "scopes" : null].filter(Boolean).join(" and ");
|
|
55
|
+
const [filtering, setFiltering] = useState(false);
|
|
56
|
+
const picked = active.length + activeSources.length;
|
|
57
|
+
const groups: FilterGroup[] = [
|
|
58
|
+
...(sources.length > 1 ? [{ title: "Source", options: sources, active: activeSources, onToggle: toggleSource }] : []),
|
|
59
|
+
...(scopes.length > 0 ? [{ title: "Scope", options: scopes.map((scope) => ({ id: scope, label: scope })), active, onToggle: toggle }] : []),
|
|
60
|
+
];
|
|
40
61
|
|
|
41
62
|
return (
|
|
42
63
|
<View style={{ gap: 24 }}>
|
|
@@ -47,19 +68,36 @@ export function NextUpList({ assigned, unclaimed, unclaimedFrom, selected, onSel
|
|
|
47
68
|
</View>
|
|
48
69
|
) : null}
|
|
49
70
|
<View>
|
|
50
|
-
<SectionHeader
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
71
|
+
<SectionHeader
|
|
72
|
+
icon="nextUp"
|
|
73
|
+
title="Unclaimed"
|
|
74
|
+
count={shown.length}
|
|
75
|
+
action={
|
|
76
|
+
groups.length > 0 ? (
|
|
77
|
+
<Button
|
|
78
|
+
label={picked ? `Filter ยท ${picked}` : "Filter"}
|
|
79
|
+
accessibilityLabel={picked ? `Filter, ${picked} on` : "Filter"}
|
|
80
|
+
icon="filter"
|
|
81
|
+
variant={picked ? "calm" : "ghost"}
|
|
82
|
+
onPress={() => setFiltering(true)}
|
|
83
|
+
/>
|
|
84
|
+
) : null
|
|
85
|
+
}
|
|
86
|
+
/>
|
|
87
|
+
{filtering ? (
|
|
88
|
+
<FilterSheet
|
|
89
|
+
groups={groups}
|
|
90
|
+
onClear={() => {
|
|
91
|
+
onSelect([]);
|
|
92
|
+
onSelectSources([]);
|
|
93
|
+
}}
|
|
94
|
+
onClose={() => setFiltering(false)}
|
|
95
|
+
/>
|
|
58
96
|
) : null}
|
|
59
97
|
{unclaimedFrom === "none" ? (
|
|
60
|
-
<Text style={styles.text}>No repos to look in. Register a project in Paseo, or
|
|
98
|
+
<Text style={styles.text}>No repos to look in. Register a project in Paseo, or choose where Next up looks in Settings.</Text>
|
|
61
99
|
) : shown.length === 0 ? (
|
|
62
|
-
<Text style={styles.text}>No unclaimed issues{
|
|
100
|
+
<Text style={styles.text}>No unclaimed issues{narrowedBy ? ` in these ${narrowedBy}` : ""}.</Text>
|
|
63
101
|
) : (
|
|
64
102
|
<IssueList issues={shown} claim {...rowProps} />
|
|
65
103
|
)}
|
|
@@ -68,49 +106,179 @@ export function NextUpList({ assigned, unclaimed, unclaimedFrom, selected, onSel
|
|
|
68
106
|
);
|
|
69
107
|
}
|
|
70
108
|
|
|
71
|
-
|
|
109
|
+
// Source and scope filters behind one button, so they take no room above the list [NXT-03, NXT-09].
|
|
110
|
+
// Ticks apply right away; a bottom sheet on phones, a dialog on desktop.
|
|
111
|
+
function FilterSheet({ groups, onClear, onClose }: { groups: FilterGroup[]; onClear: () => void; onClose: () => void }) {
|
|
112
|
+
const styles = useStyles();
|
|
113
|
+
const any = groups.some((group) => group.active.length > 0);
|
|
114
|
+
return (
|
|
115
|
+
<Modal title="Filter" open onOpenChange={(open) => (open ? null : onClose())}>
|
|
116
|
+
<Modal.Content>
|
|
117
|
+
<KeepStyles styles={styles}>
|
|
118
|
+
{groups.map((group) => (
|
|
119
|
+
<View key={group.title} style={{ gap: 6 }}>
|
|
120
|
+
<Text style={styles.muted}>{group.title}</Text>
|
|
121
|
+
<View style={[styles.card, { backgroundColor: styles.c.surface2 }]}>
|
|
122
|
+
{group.options.map((option, index) => (
|
|
123
|
+
<FilterOption key={option.id} label={option.label} checked={group.active.includes(option.id)} first={index === 0} onPress={() => group.onToggle(option.id)} />
|
|
124
|
+
))}
|
|
125
|
+
</View>
|
|
126
|
+
</View>
|
|
127
|
+
))}
|
|
128
|
+
<View style={[styles.row, { justifyContent: "flex-end" }]}>
|
|
129
|
+
<Button label="Clear" variant="ghost" disabled={!any} onPress={onClear} />
|
|
130
|
+
<Button label="Done" variant="solid" onPress={onClose} />
|
|
131
|
+
</View>
|
|
132
|
+
</KeepStyles>
|
|
133
|
+
</Modal.Content>
|
|
134
|
+
</Modal>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface FilterGroup {
|
|
139
|
+
title: string;
|
|
140
|
+
options: { id: string; label: string }[];
|
|
141
|
+
active: string[];
|
|
142
|
+
onToggle: (id: string) => void;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function FilterOption({ label, checked, first, onPress }: { label: string; checked: boolean; first: boolean; onPress: () => void }) {
|
|
72
146
|
const styles = useStyles();
|
|
147
|
+
const { hovered, hover } = useHover();
|
|
148
|
+
return (
|
|
149
|
+
<Pressable
|
|
150
|
+
accessibilityRole="checkbox"
|
|
151
|
+
accessibilityState={{ checked }}
|
|
152
|
+
accessibilityLabel={label}
|
|
153
|
+
onPress={onPress}
|
|
154
|
+
{...hover}
|
|
155
|
+
style={({ pressed }) => [
|
|
156
|
+
styles.row,
|
|
157
|
+
{ paddingVertical: 10, paddingHorizontal: 12, backgroundColor: pressed || hovered ? styles.c.border : "transparent" },
|
|
158
|
+
first ? null : { borderTopWidth: 1, borderTopColor: styles.c.surface1 },
|
|
159
|
+
]}
|
|
160
|
+
>
|
|
161
|
+
<TablerIcon name={checked ? "squareCheck" : "square"} size={18} color={checked ? styles.action : styles.c.foregroundMuted} />
|
|
162
|
+
<Text style={styles.text}>{label}</Text>
|
|
163
|
+
</Pressable>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function IssueList({ issues, claim, ...rowProps }: RowProps & { issues: NextUpIssue[]; claim: boolean }) {
|
|
73
168
|
return (
|
|
74
|
-
<
|
|
169
|
+
<CardList>
|
|
75
170
|
{issues.map((issue, index) => (
|
|
76
171
|
<IssueRow key={issue.key} issue={issue} claim={claim} first={index === 0} {...rowProps} />
|
|
77
172
|
))}
|
|
173
|
+
</CardList>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// What tells me whether to pick it up: where it lives and how old it is, then priority, effort and scope as tags [NXT-10].
|
|
178
|
+
// The type is the mark. The sheet has the full values.
|
|
179
|
+
const fullFacts = (issue: NextUpIssue) => [
|
|
180
|
+
`${issue.repo}#${issue.number}`,
|
|
181
|
+
`${ago(issue.createdAt)} old`,
|
|
182
|
+
...[issue.type, issue.priority, issue.effort, issue.scope].filter((v): v is string => !!v),
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
// An open PR that closes it means someone may already be on it [NXT-10].
|
|
186
|
+
function prSignal(issue: NextUpIssue): Chip[] {
|
|
187
|
+
const [first, ...more] = issue.openPrs;
|
|
188
|
+
if (!first) return [];
|
|
189
|
+
return [{ text: `PR by ${first.author ?? "someone"}${more.length ? ` +${more.length}` : ""}`, tone: "warn" }];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// The top priority is warm, the next accent, the rest quiet; unknown order stays quiet.
|
|
193
|
+
function Tags({ issue }: { issue: NextUpIssue }) {
|
|
194
|
+
const styles = useStyles();
|
|
195
|
+
const priorityColor = issue.priorityRank === 0 ? styles.c.statusWarning : issue.priorityRank === 1 ? styles.action : undefined;
|
|
196
|
+
const tags = [
|
|
197
|
+
issue.priority ? { key: "priority", text: shortValue(issue.priority), color: priorityColor } : null,
|
|
198
|
+
issue.effort ? { key: "effort", text: shortValue(issue.effort) } : null,
|
|
199
|
+
issue.scope ? { key: "scope", text: shortValue(issue.scope) } : null,
|
|
200
|
+
].filter((tag): tag is { key: string; text: string; color?: string } => !!tag);
|
|
201
|
+
if (tags.length === 0) return null;
|
|
202
|
+
return (
|
|
203
|
+
<View style={[styles.wrap, { gap: 4, marginTop: 2 }]}>
|
|
204
|
+
{tags.map((tag) => (
|
|
205
|
+
<Text
|
|
206
|
+
key={tag.key}
|
|
207
|
+
style={{
|
|
208
|
+
fontSize: 11,
|
|
209
|
+
color: tag.color ?? styles.c.foregroundMuted,
|
|
210
|
+
borderWidth: 1,
|
|
211
|
+
borderColor: tag.color ?? styles.c.border,
|
|
212
|
+
borderRadius: 4,
|
|
213
|
+
paddingHorizontal: 5,
|
|
214
|
+
paddingVertical: 1,
|
|
215
|
+
}}
|
|
216
|
+
>
|
|
217
|
+
{tag.text}
|
|
218
|
+
</Text>
|
|
219
|
+
))}
|
|
78
220
|
</View>
|
|
79
221
|
);
|
|
80
222
|
}
|
|
81
223
|
|
|
82
|
-
|
|
224
|
+
// The type as the card's mark: red bugs, green features and epics, amber debt, the rest quiet.
|
|
225
|
+
const TYPE_TONES: Record<string, Tone> = { bug: "bad", feature: "good", epic: "good", debt: "warn" };
|
|
83
226
|
|
|
84
227
|
// Its main action and โฏ; tapping it opens the sheet with the description, Claim or Unclaim [ATT-06, NXT-07].
|
|
85
|
-
function IssueRow({ issue, claim, first, agents, busy, fetchDetails, onStart, onClaim, onOpenAgent }: RowProps & { issue: NextUpIssue; claim: boolean; first: boolean }) {
|
|
86
|
-
const styles = useStyles();
|
|
228
|
+
function IssueRow({ issue, claim, first, agents, busy, fetchDetails, onStart, onClaim, onCloseIssue, onOpenAgent }: RowProps & { issue: NextUpIssue; claim: boolean; first: boolean }) {
|
|
87
229
|
const [open, setOpen] = useState(false);
|
|
230
|
+
// Closing asks first, with the reason and an optional comment [NXT-11, SAFE-01].
|
|
231
|
+
const [closing, setClosing] = useState(false);
|
|
88
232
|
const agent = agents[issue.key];
|
|
89
233
|
const startLabel = claim ? "Claim & start" : "Start";
|
|
234
|
+
const type = issue.type?.toLowerCase() ?? "";
|
|
235
|
+
const close = (reason: IssueCloseReason) => (comment: string) => (setClosing(false), onCloseIssue(issue, reason, comment));
|
|
90
236
|
return (
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
237
|
+
<CardRow
|
|
238
|
+
first={first}
|
|
239
|
+
mark={{ icon: TYPE_ICONS[type] ?? "issue", tone: TYPE_TONES[type] ?? "neutral" }}
|
|
240
|
+
title={issue.title}
|
|
241
|
+
accessibilityLabel={`${issue.type ? `${issue.type}: ` : ""}${issue.title}, more`}
|
|
242
|
+
meta={{ place: `${issue.repo.split("/")[1]} #${issue.number}`, when: `${ago(issue.createdAt)} old`, signals: prSignal(issue) }}
|
|
243
|
+
extra={<Tags issue={issue} />}
|
|
244
|
+
onOpen={() => setOpen(true)}
|
|
245
|
+
busy={busy === issue.key}
|
|
246
|
+
primary={
|
|
247
|
+
agent
|
|
248
|
+
? { label: "Continue", icon: "agent", onPress: () => onOpenAgent(agent.id) }
|
|
249
|
+
: // Claim first so teammates see it's taken [NXT-05].
|
|
250
|
+
{ label: startLabel, accessibilityLabel: `${startLabel} ${issue.title}`, icon: "agent", onPress: () => onStart(issue, claim) }
|
|
251
|
+
}
|
|
252
|
+
secondary={[{ label: "More actions", icon: "dots", onPress: () => setOpen(true) }]}
|
|
253
|
+
confirm={
|
|
254
|
+
closing
|
|
255
|
+
? {
|
|
256
|
+
text: `Close #${issue.number}? A comment is only posted if you write one.`,
|
|
257
|
+
comment: true,
|
|
258
|
+
choices: [
|
|
259
|
+
{ label: "Completed", icon: "issueClosed", solid: true, onConfirm: close("completed") },
|
|
260
|
+
{ label: "Not planned", icon: "close", onConfirm: close("not_planned") },
|
|
261
|
+
],
|
|
262
|
+
onCancel: () => setClosing(false),
|
|
263
|
+
}
|
|
264
|
+
: null
|
|
265
|
+
}
|
|
266
|
+
overlay={
|
|
267
|
+
open ? (
|
|
268
|
+
<IssueSheet
|
|
269
|
+
issue={issue}
|
|
270
|
+
claim={claim}
|
|
271
|
+
agent={agent}
|
|
272
|
+
fetchDetails={fetchDetails}
|
|
273
|
+
onStart={onStart}
|
|
274
|
+
onClaim={onClaim}
|
|
275
|
+
onOpenAgent={onOpenAgent}
|
|
276
|
+
onCloseIssue={() => setClosing(true)}
|
|
277
|
+
onClose={() => setOpen(false)}
|
|
278
|
+
/>
|
|
279
|
+
) : null
|
|
280
|
+
}
|
|
281
|
+
/>
|
|
114
282
|
);
|
|
115
283
|
}
|
|
116
284
|
|
|
@@ -122,8 +290,9 @@ function IssueSheet({
|
|
|
122
290
|
onStart,
|
|
123
291
|
onClaim,
|
|
124
292
|
onOpenAgent,
|
|
293
|
+
onCloseIssue,
|
|
125
294
|
onClose,
|
|
126
|
-
}: Pick<Props, "fetchDetails" | "onStart" | "onClaim" | "onOpenAgent"> & { issue: NextUpIssue; claim: boolean; agent?: AgentSummary; onClose: () => void }) {
|
|
295
|
+
}: Pick<Props, "fetchDetails" | "onStart" | "onClaim" | "onOpenAgent"> & { issue: NextUpIssue; claim: boolean; agent?: AgentSummary; onCloseIssue: () => void; onClose: () => void }) {
|
|
127
296
|
const details = useQuery({
|
|
128
297
|
queryKey: ["attention-span", "details", issue.key, false],
|
|
129
298
|
queryFn: () => fetchDetails({ subject: { kind: "issue", repo: issue.repo, number: issue.number }, checks: false }),
|
|
@@ -144,6 +313,7 @@ function IssueSheet({
|
|
|
144
313
|
? { key: "claim", icon: "claim", label: "Claim", detail: "Assigns you, without starting a session", onPress: close(() => onClaim(issue, true)) }
|
|
145
314
|
: { key: "unclaim", icon: "unclaim", label: "Unclaim", detail: "Removes you as assignee, so it goes back to Unclaimed", onPress: close(() => onClaim(issue, false)) },
|
|
146
315
|
{ key: "github", icon: "github", label: "Open issue on GitHub", detail: `${issue.repo}#${issue.number}`, onPress: close(() => void openExternalUrl(issue.url)) },
|
|
316
|
+
{ key: "close", icon: "issueClosed", label: "Close issue", detail: "Asks first: as completed or not planned, with an optional comment", onPress: close(onCloseIssue) },
|
|
147
317
|
];
|
|
148
318
|
return (
|
|
149
319
|
<ActionSheet
|
|
@@ -151,7 +321,7 @@ function IssueSheet({
|
|
|
151
321
|
onClose={onClose}
|
|
152
322
|
top={
|
|
153
323
|
<>
|
|
154
|
-
<Meta facts={
|
|
324
|
+
<Meta facts={fullFacts(issue)} chips={prSignal(issue)} />
|
|
155
325
|
</>
|
|
156
326
|
}
|
|
157
327
|
entries={entries}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.server.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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";
|
|
7
|
+
import { checkCoverage, configStatus, myOrgs, setupStatus } from "./server/setup";
|
|
8
8
|
import { AttentionService } from "./server/service";
|
|
9
9
|
import type { FeedId } from "./shared/attention";
|
|
10
10
|
import * as rpc from "./shared/rpc";
|
|
@@ -31,12 +31,17 @@ export default function contribute(server: PluginServerContext) {
|
|
|
31
31
|
server.handle(rpc.getCoverage, () => configStatus());
|
|
32
32
|
server.handle(rpc.checkCoverage, ({ kind, name }) => checkCoverage(kind, name));
|
|
33
33
|
server.handle(rpc.setCoverage, ({ orgs, repos }) => ready(() => attention.setCoverage(orgs, repos)).then(() => ({ ok: true as const })));
|
|
34
|
+
server.handle(rpc.setNextUpSources, (sources) => ready(() => attention.setNextUpSources(sources)).then(() => ({ ok: true as const })));
|
|
35
|
+
server.handle(rpc.myOrgs, async () => ({ orgs: await myOrgs() }));
|
|
34
36
|
server.handle(rpc.setScopes, ({ scopes }) => ready(() => attention.setScopes(scopes)).then(() => ({ ok: true as const })));
|
|
37
|
+
server.handle(rpc.setSources, ({ sources }) => ready(() => attention.setSources(sources)).then(() => ({ ok: true as const })));
|
|
35
38
|
server.handle(rpc.updateBranch, ({ target }) => thenRefresh(updateBranch(target)));
|
|
36
39
|
server.handle(rpc.mergePullRequest, ({ target }) => thenRefresh(mergePullRequest(target), ["live", "history"]));
|
|
37
40
|
server.handle(rpc.closePullRequest, ({ target, comment }) => thenRefresh(closePullRequest(target, comment)));
|
|
38
41
|
server.handle(rpc.claimIssue, ({ target }) => thenRefresh(claimIssue(target)));
|
|
39
42
|
server.handle(rpc.unclaimIssue, ({ target }) => thenRefresh(unclaimIssue(target)));
|
|
43
|
+
server.handle(rpc.closeIssue, ({ target, reason, comment }) => thenRefresh(closeIssue(target, reason, comment)));
|
|
44
|
+
server.handle(rpc.reopenIssue, ({ target }) => thenRefresh(reopenIssue(target)));
|
|
40
45
|
server.handle(rpc.setReady, ({ target, ready }) => thenRefresh(setReady(target, ready)));
|
|
41
46
|
server.handle(rpc.setAutoMerge, ({ target, on }) => thenRefresh(setAutoMerge(target, on)));
|
|
42
47
|
server.handle(rpc.react, ({ subjectIds, on }) => thenRefresh(react(subjectIds, on)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrioid/paseo-attention-span",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.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/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: [
|
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}`,
|