feat(watchpr): poll GitHub PRs alongside Gitea
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline failed
ci/woodpecker/pr/test Pipeline was successful

This commit is contained in:
2026-11-22 01:51:26 +11:00
parent 10d93aaa90
commit 161a33c2ed
11 changed files with 983 additions and 32 deletions
+38 -2
View File
@@ -9,14 +9,26 @@ import (
// PRRef identifies a single pull request by repository and number.
type PRRef struct {
// Forge is ForgeGitHub for a GitHub PR; empty means Gitea.
Forge string `json:",omitempty"`
Owner string
Repo string
Number int
}
// String renders the ref in canonical owner/repo#N form.
// ForgeGitHub marks a PRRef that lives on GitHub.
const ForgeGitHub = "github"
const githubPRURLPrefix = "https://github.com/"
// String renders the ref in canonical owner/repo#N form, prefixed github: for
// a GitHub PR.
func (r PRRef) String() string {
return fmt.Sprintf("%s/%s#%d", r.Owner, r.Repo, r.Number)
s := fmt.Sprintf("%s/%s#%d", r.Owner, r.Repo, r.Number)
if r.Forge != "" {
return r.Forge + ":" + s
}
return s
}
// RepoPath returns the "owner/repo" portion used in Gitea API URLs.
@@ -49,6 +61,30 @@ func ParsePRRef(s string) (PRRef, error) {
return PRRef{Owner: owner, Repo: repo, Number: n}, nil
}
// ParseWatchRef parses a Gitea ref (see ParsePRRef) or a GitHub one:
// "github:owner/repo#N", "github:owner/repo:N" or
// "https://github.com/owner/repo/pull/N".
func ParseWatchRef(s string) (PRRef, error) {
s = strings.TrimSpace(s)
if rest, ok := strings.CutPrefix(s, githubPRURLPrefix); ok {
parts := strings.Split(strings.TrimSuffix(rest, "/"), "/")
if len(parts) != 4 || parts[2] != "pull" {
return PRRef{}, fmt.Errorf("invalid GitHub PR URL %q: expected %sowner/repo/pull/N", s, githubPRURLPrefix)
}
s = "github:" + parts[0] + "/" + parts[1] + "#" + parts[3]
}
rest, ok := strings.CutPrefix(s, "github:")
if !ok {
return ParsePRRef(s)
}
ref, err := ParsePRRef(rest)
if err != nil {
return PRRef{}, err
}
ref.Forge = ForgeGitHub
return ref, nil
}
// ParseDurationFlag parses a duration flag value, accepting either a Go
// duration string ("30s", "1h30m") or a bare integer read as seconds ("15").
// flag names the flag so the error says which value was rejected.