Documentation
¶
Overview ¶
Package github is a small REST client for the GitHub API used by the PR-AF review pipeline: fetch a PR (metadata + changed files + commits + unified diff), and post a review with inline comments.
It is a faithful port of src/pr_af/github/client.py. Behavioural contract (byte-exact with Python):
- ParsePRURL: regexp ^https?://github\.com/([^/]+)/([^/]+)/pull/(\d+).
- FetchPR: 4 attempts, sleep 2.0*(attempt+1)s between them, retry on transport errors + 5xx + 403/429, fail fast on any other 4xx.
- Per-request timeouts: 30s (fetch), 60s (post).
- Redirects followed (Go's default http.Client) — matches httpx follow_redirects=True on the fetch client (see divergence notes below).
- Pagination of /files and /commits at per_page=100.
- Diff via Accept: application/vnd.github.v3.diff.
- Auth: the token the constructor is handed, or none. (pr-af's served node also signed in as a GitHub App; codeaf carries no App key.)
- PostReview surfaces HTTP failures (incl. 422 "own pull request") as a typed *APIError carrying StatusCode + Body so the orchestrator can detect the 422 and downgrade the event to COMMENT.
Divergences from Python (intentional, behaviourally inert in production):
- Go's http.Client follows redirects for every request; Python leaves follow_redirects at its default (off) for the post-review call and only enables it for fetch. That endpoint never redirects on api.github.com, so this is inert.
- Debug print() lines from the Python client are dropped (they are stdout diagnostics, not behaviour).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
func NewClient(token string) *client
NewClient builds a GitHub client on token, which may be empty for a public repository. The caller resolves it (internal/praf's githubToken: GH_TOKEN, GITHUB_TOKEN, then `gh auth token`); pr-af's served node also signed in as a GitHub App, which codeaf does not carry.
Types ¶
type APIError ¶
APIError is returned for any GitHub response with status >= 400. It carries the status code and raw response body so callers can classify failures — in particular the orchestrator inspects StatusCode==422 with Body containing "own pull request" to downgrade the review event to COMMENT and retry.
type Client ¶
type Client interface {
ParsePRURL(url string) (owner, repo string, number int, err error)
FetchPR(ctx context.Context, owner, repo string, number int) (schemas.GitHubPRData, error)
PostReview(ctx context.Context, owner, repo string, number int, review schemas.GitHubReview, commitID string) (map[string]any, error)
}
Client is the GitHub surface the review pipeline depends on.