forgejo

package
v0.147.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

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

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

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

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

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

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

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.

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. 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

func (c *Client) ListRepos(ctx context.Context) ([]dashboard.RepoRef, error)

ListRepos returns the repositories this Client is configured to track — see NewClient for the two modes.

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 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) PullRequestBody added in v0.139.0

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

PullRequestBody implements dashboard.PullRequestBodyEditor: the description of owner/name#number.

func (*Client) ReadPullRequestState added in v0.111.1

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

ReadPullRequestState implements dashboard.PullRequestStateReader via Forgejo's "Get a pull request". It reports merged, state and a single mergeable verdict, with no mergeable_state to say why a PR isn't mergeable. Gitea computes that flag from the merge check alone: false for a conflict, but also while the check is still running or has errored, and it ignores branch protection altogether. So an open, non-draft PR with a false flag is reported as ConflictUnconfirmed, and one with an empty diff (which Gitea also marks unmergeable) as Blocked. A missing review or check isn't visible here: the merge refusal's own text names it.

func (*Client) RerunFailedChecks added in v0.135.0

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

RerunFailedChecks implements dashboard.ChecksRerunner: it finds the Actions runs on the pull request's head commit, and asks Forgejo to rerun the failed jobs of each run that failed, once per run. A commit status doesn't say which run it came from, so the runs are looked up by commit instead. A status with no run behind it (an external CI) isn't there to find and is skipped.

The rerun is a raw request, not the SDK's RerunRepoActionRunFailedJobs: the SDK drops the body of a refusal, and Forgejo's own reason (a token without the Actions scope, an instance without the route) is what a person needs.

func (*Client) SetPullRequestBody added in v0.139.0

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

SetPullRequestBody implements dashboard.PullRequestBodyEditor: replaces the description of owner/name#number and nothing else about it.

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 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

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, bringing it up to date. Forgejo's SDK call is synchronous — accepted is always false here — unlike GitHub's async equivalent.

Jump to

Keyboard shortcuts

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