Documentation
¶
Overview ¶
Package github is a client for the pieces of the GitHub API forge-dashboard needs: which repositories the credential can write to, their open pull requests and issues, and combined CI status per pull request. With a token, it talks to GitHub's GraphQL API — one request returns everything a REST-based Client used to need one call per repo/PR/CI-check for, and GraphQL draws from its own separate rate-limit pool rather than the REST budget every other tool on the account shares. GraphQL requires authentication for every request, so the username-only (public repos, no token) mode still uses REST — a fallback path that was never part of the authenticated budget anyway.
Index ¶
- type Client
- func (c *Client) AddLabel(ctx context.Context, owner, name string, number int, label string) error
- func (c *Client) CommentPullRequest(ctx context.Context, owner, name string, number int, body string) error
- func (c *Client) EnsureWebhook(ctx context.Context, owner, name, targetURL, secret string) error
- func (c *Client) Fetch(ctx context.Context) dashboard.Result
- func (c *Client) FetchRepo(ctx context.Context, owner, name, fullName string) ([]dashboard.PullRequest, []dashboard.Issue, error)
- func (c *Client) Forge() dashboard.Forge
- func (c *Client) HasWebhook(ctx context.Context, owner, name string) (bool, error)
- func (c *Client) MergePullRequest(ctx context.Context, owner, name string, number int) error
- func (c *Client) SetWebhookPath(path string)
- func (c *Client) UpdateBranch(ctx context.Context, owner, name string, number int) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to GitHub, either as an authenticated user (a token, GraphQL) or anonymously against one user's public repositories (a username, no token, REST — GraphQL allows no anonymous access at all). The REST fallback is driven by google/go-github rather than hand-rolled requests — same wire calls, typed responses and typed rate-limit errors instead of reparsing JSON bodies by hand.
func NewClient ¶
NewClient returns a Client. With token set, Fetch queries GraphQL for every repo the token can push to, private included. With token empty and username set, Fetch falls back to unauthenticated REST and returns only username's public repos — there's no "write access" to filter by without a credential, so this mode returns everything public GitHub already shows anyone. baseURL defaults to the real GitHub API; tests override it to point at an httptest.Server.
func (*Client) AddLabel ¶ added in v0.69.0
AddLabel implements dashboard.PullRequestLabeler: adds label to owner/name#number — Renovate's own rebase/retry trigger on GitHub. GitHub's labels-by-name endpoint needs no ID lookup, unlike Forgejo's.
func (*Client) CommentPullRequest ¶ added in v0.68.0
func (c *Client) CommentPullRequest(ctx context.Context, owner, name string, number int, body string) error
CommentPullRequest implements dashboard.PullRequestCommenter: posts body as a plain comment on owner/name#number. GitHub has no separate pull-request-comment endpoint for a top-level comment — it's the same Issues API a regular issue comment uses, since every pull request is also an issue.
func (*Client) EnsureWebhook ¶ added in v0.56.0
EnsureWebhook implements dashboard.WebhookManager: create a webhook targeting targetURL if owner/name has none yet, or bring an existing one (found by matching targetURL's own path, not c.webhookPath — this method is self-contained even if SetWebhookPath was never called) back to active with the right config rather than creating a second, duplicate hook — GitHub, unlike Forgejo, allows several hooks with the identical URL, so nothing stops a duplicate except checking first.
func (*Client) Fetch ¶ added in v0.37.0
Fetch implements dashboard.Source directly — GitHub drives its own fetch strategy (GraphQL vs. the REST fallback) rather than going through dashboard.GenericSource's one-call-per-repo model, which is exactly the round-trip count this exists to avoid.
func (*Client) FetchRepo ¶ added in v0.40.0
func (c *Client) FetchRepo(ctx context.Context, owner, name, fullName string) ([]dashboard.PullRequest, []dashboard.Issue, error)
FetchRepo implements dashboard.RepoRefresher: the single-repo counterpart to Fetch's account-wide GraphQL query, for a webhook delivery that already knows exactly which repo changed.
func (*Client) HasWebhook ¶ added in v0.54.0
HasWebhook implements dashboard.WebhookChecker: does repo owner/name already have a webhook whose target URL is this account's own webhook endpoint. REST-only — GitHub's GraphQL schema doesn't expose webhook configuration — so this is one extra REST call per repo, outside GraphQL's own separate rate-limit budget.
func (*Client) MergePullRequest ¶ added in v0.62.0
MergePullRequest implements dashboard.PullRequestMerger: merges owner/name#number, passing no PullRequestOptions so GitHub applies its own default merge method rather than this app picking one.
func (*Client) SetWebhookPath ¶ added in v0.54.0
SetWebhookPath tells Client the path (not the full URL — see dashboard.WebhookTargetsPath) this account's own GitHub webhook endpoint lives at, e.g. "/api/webhooks/github/<token>". Left unset, HasWebhook always reports false without calling GitHub at all — the same "optional, degrades quietly" shape RateLimit's nil pointer already uses elsewhere in this codebase.
func (*Client) UpdateBranch ¶ added in v0.63.0
UpdateBranch implements dashboard.BranchUpdater: merges owner/name#number's base branch into its head branch. GitHub can schedule this as a background job and answer 202 before it's actually done — go-github surfaces that as a *github.AcceptedError rather than a real failure (see its own doc comment), so that specific case is unwrapped into accepted=true instead of being treated as an error.