1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//! GitHub issue discovery for `tm watch` — list + label-filter via `gh`.
//!
//! Why: `tm watch` routes work by LABEL (no bot account exists, so we do NOT
//! filter by assignee). It must enumerate a repo's issues carrying the routing
//! label and turn them into a small, backend-independent value the dispatch and
//! listen loops can act on. Hiding the `gh issue list` call behind a trait seam
//! ([`IssueLister`]) lets the loops be unit-tested with a scripted fake instead
//! of hitting GitHub over the network.
//! What: [`MatchedIssue`] is the normalised issue view; [`IssueState`] selects
//! open/all; [`IssueLister`] is the one-method seam; [`GhIssueLister`] is the
//! `gh`-backed production impl over the shared [`CommandRunner`]; [`parse_issues`]
//! turns `gh issue list --json …` output into `MatchedIssue`s and
//! [`filter_by_label`] applies the routing-label predicate defensively (gh's
//! `--label` already filters server-side, but we re-check so the predicate is
//! tested and a fake/loose backend cannot leak unmatched issues).
//! Test: `parse_issues_*`, `filter_by_label_*`, `gh_list_*` in the sibling
//! `tests.rs`.
use Deserialize;
use crateCommandRunner;
/// Which issues `tm watch` should consider.
///
/// Why: a one-shot `poll` against a busy board may want only `open` issues
/// (the common, safe case) but an operator backfilling may want `all`. Typing
/// it as a clap `ValueEnum` rejects bad values at parse time.
/// What: `Open` (default — the routable working set) or `All` (open + closed).
/// Maps to the `gh issue list --state` value via [`IssueState::as_gh`].
/// Test: `issue_state_default_is_open`, `issue_state_as_gh`.
pub
/// A normalised issue matched by the routing label.
///
/// Why: the dispatch and listen loops need a backend-independent, hashable-by-
/// number view of an issue — number (the dedup key), title/body (seed the agent
/// task), labels (for the defensive re-filter), and url (operator-facing log).
/// What: the issue number, title, body, label names, and html url.
/// Test: built from `gh` JSON in `parse_issues_basic`.
pub
/// A seam for listing a repo's issues filtered by label.
///
/// Why: decouples the watch loops from a live `gh` + GitHub so the discovery →
/// filter → dispatch flow is unit-testable with a scripted fake, mirroring the
/// `TicketSystem`/`CommandRunner` seams `tm ticket` already uses.
/// What: one `list` method taking the `owner/repo`, routing label, and state,
/// returning the matched issues.
/// Test: `GhIssueLister` via `FakeRunner`; the loops via a `FakeLister`.
pub
/// GitHub-backed [`IssueLister`] driving the `gh` CLI.
///
/// Why: GitHub is the only supported board today; wrapping `gh issue list`
/// behind a [`CommandRunner`] keeps the discovery path unit-testable and reuses
/// the exact process seam `tm ticket` uses.
/// What: `list` runs `gh issue list -R <repo> --label <l> --state <s> --json
/// number,title,body,labels,url`, parses the JSON, and applies the defensive
/// label re-filter. (Assignees are intentionally not requested: routing is by
/// LABEL, so the field was never deserialised.)
/// Test: `gh_list_parses_and_filters`, `gh_list_surfaces_gh_failure`.
pub
/// Shape of a single `gh issue list --json …` array element.
///
/// Why: decouples our [`MatchedIssue`] from gh's wire shape so a field rename
/// only touches this struct.
/// What: deserialises the subset of fields we request.
/// Test: parsed in `parse_issues_basic`.
/// A single label object in the gh issue JSON.
///
/// Why: gh returns labels as objects with a `name` field, not bare strings.
/// What: captures just the `name`.
/// Test: parsed alongside `GhIssueJson`.
/// Parse `gh issue list --json …` output into [`MatchedIssue`]s.
///
/// Why: keeping the JSON→value mapping a pure function makes every parse branch
/// (empty array, missing optional fields) deterministically unit-testable.
/// What: deserialises the gh array, flattening each label object to its name.
/// An empty input string is treated as an empty array (gh prints nothing when
/// there are no matches under some configurations).
/// Test: `parse_issues_basic`, `parse_issues_empty`.
pub
/// Keep only issues that actually carry `label` (defensive re-filter).
///
/// Why: `gh issue list --label` filters server-side, but the routing contract is
/// "only issues carrying the label are picked up". Re-applying the predicate
/// here makes that contract a tested invariant and means a fake/loose backend
/// (or a future HTTP path) can never leak an unmatched issue into execution.
/// The match is case-insensitive because GitHub label names are not.
/// What: returns the issues whose `labels` contain `label` (ASCII-case-insensitive).
/// Test: `filter_by_label_keeps_only_matching`, `filter_by_label_case_insensitive`.
pub