Documentation
¶
Overview ¶
Package forgejo is a client for the pieces of the Forgejo API (Gitea-compatible) forge-dashboard needs — the same shape as internal/github, against a different API under a self-hosted host. Driven by code.gitea.io/sdk/gitea, the official Gitea Go client and the one Forgejo's own API compatibility targets, rather than hand-rolled requests.
Index ¶
- type Client
- func (c *Client) AddLabel(ctx context.Context, owner, name string, number int, label string) error
- func (c *Client) ClosePullRequest(ctx context.Context, owner, name string, number int) error
- func (c *Client) EnsureWebhook(ctx context.Context, owner, name, targetURL, secret string) error
- func (c *Client) HasWebhook(ctx context.Context, owner, name string) (bool, error)
- func (c *Client) ListChecks(ctx context.Context, owner, name string, number int) ([]dashboard.Check, error)
- func (c *Client) ListOpenIssues(ctx context.Context, owner, name, repo string) ([]dashboard.Issue, error)
- func (c *Client) ListOpenPullRequests(ctx context.Context, owner, name, repo string) ([]dashboard.PullRequest, error)
- func (c *Client) ListRepos(ctx context.Context) ([]dashboard.RepoRef, 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 a Forgejo instance's API, either as an authenticated user (a token) or anonymously against one user's public repositories on that instance (a username, no token at all).
func NewClient ¶
func NewClient(instanceURL, token, username string, recorder ...requestlog.Recorder) *Client
NewClient returns a Client against instanceURL (e.g. "https://git.higherlearning.eu"). With token set, it authenticates as that user and ListRepos returns every repo the token can push to, private included. With token empty and username set, every request goes out unauthenticated and ListRepos returns only username's public repos on that instance. recorder is variadic, not a plain trailing parameter, purely so every existing call site (tests included) keeps compiling unchanged (#482) — pass one to have every outbound request persisted, or omit it (or pass nil) to get requestlog.NoopRecorder{}, the same as before this parameter existed.
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 this forge. Forgejo's AddIssueLabels takes label IDs, not names (unlike GitHub's equivalent), so this looks the repo's own labels up first to resolve label to its ID. A repo with no label by that name fails informatively rather than silently doing nothing — Renovate doesn't create the label itself, the repo owner (or Renovate's own onboarding) does.
func (*Client) ClosePullRequest ¶ added in v0.88.0
ClosePullRequest implements dashboard.PullRequestCloser: closes owner/name#number without merging it. EditPullRequest goes through the SDK's own getParsedResponse, not the getStatusCode MergePullRequest and UpdateBranch are stuck with (see forgejoError's own callers above for why that matters) — Forgejo's real rejection reason, if any, reaches the caller here without needing rawRequest.
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.
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. Forgejo's hooks API has no separate read-only scope — listing needs the same write:repository scope creating one does (see #234's research, cited on settings.html's token instructions).
func (*Client) ListChecks ¶ added in v0.79.0
func (c *Client) ListChecks(ctx context.Context, owner, name string, number int) ([]dashboard.Check, error)
ListChecks implements dashboard.PullRequestChecker: lists every individual job across every Actions run against owner/name#number's head commit, falling back to the legacy combined-status API's own per-check Statuses when this instance reports no Actions runs for that commit at all (Actions disabled, or an instance old enough to lack the /actions/runs route family — ListRepoActionRuns hits the wire for real rather than failing fast on a version check, since this client disables the SDK's version gates; see NewClient's own SetGiteaVersion("") comment). A real fetch error (permission, rate limit) still propagates instead of being swallowed into that same fallback.
func (*Client) ListOpenIssues ¶
func (c *Client) ListOpenIssues(ctx context.Context, owner, name, repo string) ([]dashboard.Issue, error)
ListOpenIssues returns every open issue against repo. Forgejo's issues endpoint takes type=issues to exclude pull requests server-side, unlike GitHub's equivalent — no client-side filtering needed here.
func (*Client) ListOpenPullRequests ¶
func (c *Client) ListOpenPullRequests(ctx context.Context, owner, name, repo string) ([]dashboard.PullRequest, error)
ListOpenPullRequests returns every open pull request against repo, with CI already resolved. repo is owner-qualified ("alrayyes/tempus-fugit").
func (*Client) ListRepos ¶
ListRepos returns the repositories this Client is configured to track — see NewClient for the two modes.
func (*Client) MergePullRequest ¶ added in v0.62.0
MergePullRequest implements dashboard.PullRequestMerger: merges owner/name#number using the repo's own configured default merge style. Unlike GitHub, Forgejo's merge API has no "use the repo default" sentinel — MergePullRequestOption.Style is a required field on the wire — so this looks the repo's DefaultMergeStyle up first rather than hardcoding one style for every repo regardless of its own settings.
func (*Client) SetWebhookPath ¶ added in v0.54.0
SetWebhookPath tells Client the path (not the full URL — see dashboard.WebhookTargetsPath) this account's own Forgejo webhook endpoint lives at, e.g. "/api/webhooks/forgejo/<token>". Left unset, HasWebhook always reports false without calling the forge 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, bringing it up to date. Forgejo's SDK call is synchronous — accepted is always false here — unlike GitHub's async equivalent.