watchpr: fix watch mode never detecting changes #5
Reference in New Issue
Block a user
Delete Branch "benvin/watchpr-watchloop-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
watchpr watch mode establishes its baseline and then never detects changes or exits: it ran 37+ minutes and silently missed two PRs merging, while
--oncereports state correctly. The poll loop was not the culprit -- the fetch it depends on was.Root cause:
FetchStatecallsGetPR(which returnsmerged=truefor the merged PR) and thenCommitStatus(pr.Head.Sha). When a PR is squash/rebase-merged and its branch is auto-deleted (default_delete_branch_after_mergeis on for these repos), the original head commit becomes unreachable and the status endpoint returns HTTP 404.FetchStatetreated that 404 as fatal and returned an error, discarding themerged=truesignal it had just fetched. The watch loop then saw only a transient poll error, logged a warning, and kept polling forever -- the observed hang. Regular merges keep the head commit reachable as a merge parent, which is why the earlier fix (PR #3) looked correct and--onceon open PRs worked.Changes:
APIErrorcarrying the HTTP status code so callers can detect a 404 viaerrors.Asinstead of parsing error strings.FetchStatetolerates a 404 fromCommitStatus(a gone commit has no CI status) and returns the authoritative merged/closed PR state; non-404 status errors still fail.FetchStatesurvives a 404 status endpoint, and the full watch loop -- driven through a real*GiteaClientagainst an httptest Gitea server -- detects a merge whose head commit is gone. Both fail/hang against the pre-fix code. A guard test keeps non-404 status errors fatal.Validation:
gofmt -l .clean,go vet ./...clean,go test -race ./...passes,make buildsucceeds,golangci-lint run ./...(CI image) reports 0 issues.