github

package
v0.66.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

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

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

func NewClient(token, username, baseURL string) *Client

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) EnsureWebhook added in v0.56.0

func (c *Client) EnsureWebhook(ctx context.Context, owner, name, targetURL, secret string) error

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

func (c *Client) Fetch(ctx context.Context) dashboard.Result

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) Forge added in v0.38.0

func (c *Client) Forge() dashboard.Forge

Forge implements dashboard.Source.

func (*Client) HasWebhook added in v0.54.0

func (c *Client) HasWebhook(ctx context.Context, owner, name string) (bool, error)

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

func (c *Client) MergePullRequest(ctx context.Context, owner, name string, number int) error

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

func (c *Client) SetWebhookPath(path string)

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

func (c *Client) UpdateBranch(ctx context.Context, owner, name string, number int) (bool, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL