fix(health): gitea_project_health reports "Open PRs: unknown (API error)" when the only error says "unprotected" #19

Closed
opened 2026-10-24 00:58:34 +00:00 by dsh · 1 comment
Owner

Symptom

gitea_project_health prints Open PRs: unknown (API error) even when the pulls API is healthy, because the security warning contains the substring pr.

Repro

gitea_project_health {owner: "dsh-plugins", repo: "dsh-gitea"}

Verbatim output:

Repository Health Report
Open Issues: 0 (0 stale), Open PRs: unknown (API error)
Errors: security: default branch "master" is unprotected

gitea_pr_list {state:"open"} on the same repo returned No pull requests., so the pulls fetch was fine.

Observed vs expected

  • Observed: the open-PR count is replaced by unknown (API error) whenever the only error is about an unprotected branch.
  • Expected: Open PRs: 0; the unknown fallback only for a real pulls/PR API failure.

Root cause

lib/handlers/formatters.js decides:

const hasPullErr = Array.isArray(data.errors) && data.errors.some((e) => /pull|pr/i.test(e))

"default branch ... is unprotected" contains pr, so hasPullErr is true. The same substring approach is used for issues (/issue/).

Proposed fix

Match structured error prefixes/codes (pulls: / issues:) or have the health handler report per-section error flags instead of parsing prose. Add a regression test with {openPRs: 0, errors: ["security: ... unprotected"]} asserting Open PRs: 0.

Acceptance: health output keeps the numeric PR count when only the security check failed; unknown (API error) appears only for a genuine pulls failure.

Duplicate check

gitea_issue_search {q:"formatter",state:"all"} and {q:"security"} → only the known #2–#18 tool issues; none mentions project_health.

Layer

dsh-gitea plugin/tool (formatter).

## Symptom `gitea_project_health` prints `Open PRs: unknown (API error)` even when the pulls API is healthy, because the security warning contains the substring `pr`. ## Repro `gitea_project_health {owner: "dsh-plugins", repo: "dsh-gitea"}` Verbatim output: ``` Repository Health Report Open Issues: 0 (0 stale), Open PRs: unknown (API error) Errors: security: default branch "master" is unprotected ``` `gitea_pr_list {state:"open"}` on the same repo returned `No pull requests.`, so the pulls fetch was fine. ## Observed vs expected - Observed: the open-PR count is replaced by `unknown (API error)` whenever the only error is about an unprotected branch. - Expected: `Open PRs: 0`; the `unknown` fallback only for a real pulls/PR API failure. ## Root cause `lib/handlers/formatters.js` decides: ```js const hasPullErr = Array.isArray(data.errors) && data.errors.some((e) => /pull|pr/i.test(e)) ``` `"default branch ... is unprotected"` contains `pr`, so `hasPullErr` is true. The same substring approach is used for issues (`/issue/`). ## Proposed fix Match structured error prefixes/codes (`pulls:` / `issues:`) or have the health handler report per-section error flags instead of parsing prose. Add a regression test with `{openPRs: 0, errors: ["security: ... unprotected"]}` asserting `Open PRs: 0`. Acceptance: health output keeps the numeric PR count when only the security check failed; `unknown (API error)` appears only for a genuine pulls failure. ## Duplicate check `gitea_issue_search {q:"formatter",state:"all"}` and `{q:"security"}` → only the known #2–#18 tool issues; none mentions `project_health`. ## Layer dsh-gitea plugin/tool (formatter).
dsh closed this issue 2026-10-24 01:16:14 +00:00
Author
Owner

Fixed in 281eade (PR #40).

gitea_project_health now matches source-prefixed errors (issues:, pulls:) instead of /pull|pr/i, so security: … is unprotected no longer hides the PR count. Live: Open Issues: 16 … Open PRs: 0 with the security warning still shown.

Tests: test/qa-defaults.test.mjs.

Fixed in `281eade` (PR #40). `gitea_project_health` now matches source-prefixed errors (`issues:`, `pulls:`) instead of `/pull|pr/i`, so `security: … is unprotected` no longer hides the PR count. Live: `Open Issues: 16 … Open PRs: 0` with the security warning still shown. Tests: `test/qa-defaults.test.mjs`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
dsh-plugins/dsh-gitea#19
No description provided.