Skip to content

Commit 26284f0

Browse files
voidstackloopclaude
andcommitted
Add GitHub Issues auto-tracking for regressions
Another large-scale improvement, same shape as --webhook-url: turn a regression into something a team actually has to act on, rather than a notification that scrolls off a Slack channel. --github-issues-repo opens a tracking issue when a check goes to Fail, and closes it (with a recovery comment) when the same check comes back to Pass. Warn never opens, comments, or closes anything - it isn't a confirmed regression either way, matching the existing Status semantics used everywhere else in the codebase. Deliberately built on history::diff, the same primitive notify.rs already uses for regressions, rather than inventing a second notion of "what changed" (src/issues.rs::events_from_history keeps every transition, not just ->Fail, since Pass needs to close issues too). Dedup uses a stable marker embedded in the issue body (<!-- formwatch-issue-key: {url} | {check} -->, invisible in GitHub's rendered view) as a search key, rather than hashing it - the raw text is more debuggable and there's no need to obscure it. Token resolution follows the same never-fail-the-run philosophy as the LLM/webhook integrations: github_issues.token, then GITHUB_TOKEN (set automatically in Actions), then GH_TOKEN (gh CLI's convention), then a logged warning and skip. Verified against the real voidstackloop/formwatch repo, not just unit tests, which is what actually caught a genuine bug: GitHub's issue search index is eventually consistent, so calling reconcile() twice in quick succession (simulating two close monitor runs) created a second issue instead of finding the first. Confirmed the race directly via `gh api search/issues`, then fixed it with a bounded retry ([2s, 4s] backoff) before falling back to create - re-verified live with a fresh URL and got the correct Created -> AlreadyTracked -> Closed sequence, independently double-checked via `gh issue view`. cargo fmt/clippy -D warnings clean, full suite green (152 tests). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent beb86cb commit 26284f0

6 files changed

Lines changed: 733 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ project doesn't have a release yet, so everything below is grouped under
2424

2525
### Added
2626

27+
- **GitHub Issues auto-tracking** (`--github-issues-repo owner/repo`,
28+
`github_issues.*` config, `FORMWATCH_GITHUB_ISSUES_REPO`/
29+
`FORMWATCH_GITHUB_ISSUES_TOKEN`): a check going to Fail opens a
30+
tracking issue, a check recovering to Pass comments and closes it, and
31+
Warn never touches issue lifecycle either way. Reuses the same
32+
`history::diff` primitive as `--webhook-url` regression notifications
33+
rather than a second notion of "what changed." A stable HTML-comment
34+
marker (form URL + check name) embedded in the issue body is used to
35+
find the same issue again, so repeated `monitor` runs never duplicate
36+
it. The token falls back through `github_issues.token` →
37+
`GITHUB_TOKEN` (set automatically in GitHub Actions) → `GH_TOKEN` (the
38+
`gh` CLI's convention) → a skip-with-warning if none is found, and the
39+
integration is never fatal to the run itself. Live testing against a
40+
real repository surfaced a genuine bug unit tests couldn't have caught:
41+
GitHub's issue-search index is eventually consistent, so a lookup
42+
moments after creating an issue can miss it and create a duplicate;
43+
fixed with a bounded retry-with-backoff before falling back to create.
2744
- A reusable **GitHub Action** (`action.yml`): any repository can add
2845
`uses: voidstackloop/formwatch@vX` to its own CI and run `test` or
2946
`monitor` with no Rust toolchain — it downloads the matching prebuilt

‎README.md‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ Every command also accepts these global flags:
184184
`--fail-on fail|warn` (default `fail`; use `warn` to also fail CI on
185185
warnings).
186186
- `test`/`monitor` additionally accept `--webhook-url URL` to push a
187-
regression notification (Slack or generic JSON) after the run.
187+
regression notification (Slack or generic JSON) after the run, and
188+
`--github-issues-repo owner/repo` to auto-track regressions as GitHub
189+
Issues (see [GitHub Issues auto-tracking](#github-issues-auto-tracking)).
188190

189191
Every run is stored under `.formwatch/history/` in the current directory so
190192
`monitor` and `report` can diff against history. Override that location
@@ -263,6 +265,10 @@ accept_terms: true # record acknowledgement of the legal notice
263265
notify:
264266
webhook_url: https://hooks.slack.com/services/...
265267
on: regression # or: always
268+
github_issues:
269+
repo: voidstackloop/formwatch
270+
# token: ghp_... # falls back to GITHUB_TOKEN / GH_TOKEN
271+
labels: [formwatch]
266272
llm:
267273
enabled: true
268274
provider: openai # openai | anthropic | mock
@@ -285,6 +291,7 @@ in CI and containers: `FORMWATCH_HISTORY_DIR`, `FORMWATCH_CHECKS_DIR`,
285291
`FORMWATCH_SERVE_ADDR`, `FORMWATCH_ACCEPT_TERMS`,
286292
`FORMWATCH_KEEP_LAST`, `FORMWATCH_KEEP_DAYS`,
287293
`FORMWATCH_FAIL_ON`, `FORMWATCH_WEBHOOK_URL`, `FORMWATCH_WEBHOOK_ON`,
294+
`FORMWATCH_GITHUB_ISSUES_REPO`, `FORMWATCH_GITHUB_ISSUES_TOKEN`,
288295
`FORMWATCH_LLM`, `FORMWATCH_LLM_PROVIDER`, `FORMWATCH_LLM_MODEL`,
289296
`FORMWATCH_LLM_API_KEY`, `FORMWATCH_LLM_BASE_URL`,
290297
`FORMWATCH_LLM_TIMEOUT_SECS`, `FORMWATCH_LLM_MAX_RETRIES`,
@@ -371,6 +378,32 @@ a CI job directly. For richer integration:
371378
- `--proxy` and `--insecure` route Chrome through a corporate proxy (or a
372379
trusted test host with a self-signed certificate).
373380

381+
### GitHub Issues auto-tracking
382+
383+
`--github-issues-repo owner/repo` (or `github_issues.repo` /
384+
`FORMWATCH_GITHUB_ISSUES_REPO`) turns regressions into tracked GitHub
385+
Issues instead of (or alongside) a webhook ping:
386+
387+
- A check that goes to **Fail** opens an issue, unless one is already
388+
open for that exact form URL + check — a stable HTML-comment marker in
389+
the issue body is used to find it again, so re-running `monitor` never
390+
creates duplicates.
391+
- A check that recovers to **Pass** comments on and closes its open
392+
issue. **Warn** never opens, comments, or closes anything — it isn't a
393+
confirmed regression either way.
394+
- The token comes from `github_issues.token` /
395+
`FORMWATCH_GITHUB_ISSUES_TOKEN` first, then the `GITHUB_TOKEN` env var
396+
GitHub Actions sets automatically, then `GH_TOKEN` (the `gh` CLI's
397+
own convention). No token found just logs a warning and skips tracking
398+
for that run — it never fails the run itself.
399+
- `labels` (`github_issues.labels`) applies extra labels to created
400+
issues.
401+
- Because GitHub's issue-search index is eventually consistent, a lookup
402+
for an issue created moments earlier can briefly miss it; tracking
403+
retries the search with a short backoff before falling back to
404+
creating a new issue, rather than risk a duplicate on every fast
405+
`monitor` interval.
406+
374407
## LLM semantic checks (optional)
375408

376409
The built-in checks are heuristic — they can prove a validations error

‎src/config.rs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,34 @@ pub struct NotifyConfig {
6060
pub on: Option<NotifyOn>,
6161
}
6262

63+
/// GitHub Issues auto-tracking settings (`github_issues:` in config).
64+
#[derive(Clone, Default, Deserialize, Serialize)]
65+
#[serde(default)]
66+
pub struct GithubIssuesConfig {
67+
/// `"owner/repo"` to create/comment-on/close tracking issues in.
68+
pub repo: Option<String>,
69+
/// GitHub token. Prefer `GITHUB_TOKEN` (set automatically in GitHub
70+
/// Actions) or `GH_TOKEN` (the `gh` CLI's own convention) — both are
71+
/// consulted at call time if this is unset — over writing a token
72+
/// into a config file.
73+
pub token: Option<String>,
74+
/// Labels applied to a newly created tracking issue. Defaults to
75+
/// `["formwatch"]` if unset.
76+
pub labels: Option<Vec<String>>,
77+
}
78+
79+
/// Hand-written so a token accidentally left in a config file is never
80+
/// printed by a `{:?}` (a debug log line, an error context).
81+
impl std::fmt::Debug for GithubIssuesConfig {
82+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83+
f.debug_struct("GithubIssuesConfig")
84+
.field("repo", &self.repo)
85+
.field("token", &self.token.as_ref().map(|_| "<redacted>"))
86+
.field("labels", &self.labels)
87+
.finish()
88+
}
89+
}
90+
6391
/// Optional LLM semantic-check settings (`llm:` in the config file).
6492
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
6593
#[serde(default)]
@@ -144,6 +172,8 @@ pub struct Config {
144172
pub notify: Option<NotifyConfig>,
145173
/// Optional LLM semantic-check settings.
146174
pub llm: Option<LlmConfig>,
175+
/// Optional GitHub Issues auto-tracking settings.
176+
pub github_issues: Option<GithubIssuesConfig>,
147177
}
148178

149179
/// Reads a boolean-ish environment value.
@@ -242,6 +272,17 @@ impl Config {
242272
self.notify.get_or_insert_with(NotifyConfig::default).on = Some(parsed);
243273
}
244274

275+
if let Some(repo) = env_string(&get, "FORMWATCH_GITHUB_ISSUES_REPO") {
276+
self.github_issues
277+
.get_or_insert_with(GithubIssuesConfig::default)
278+
.repo = Some(repo);
279+
}
280+
if let Some(token) = env_string(&get, "FORMWATCH_GITHUB_ISSUES_TOKEN") {
281+
self.github_issues
282+
.get_or_insert_with(GithubIssuesConfig::default)
283+
.token = Some(token);
284+
}
285+
245286
macro_rules! llm_set {
246287
($field:ident, $key:literal, $parser:ident) => {
247288
if let Some(v) = $parser(&get, $key)? {

0 commit comments

Comments
 (0)