Documentation
¶
Overview ¶
Package giteaapp implements OAuth2 and the small slice of Gitea's REST API this control plane needs once connected.
Methods take instanceURL explicitly rather than baking one into the Client, the same reasoning internal/gitlabapp's own doc comment gives: Gitea is almost always self-hosted, never a fixed host like api.github.com. Repos are addressed by an "owner/repo" pair, not a numeric ID: Gitea's REST API is GitHub-shaped here, unlike GitLab's own numeric project ID.
Index ¶
- Constants
- func AuthorizeURL(instanceURL, clientID, redirectURI, state string) string
- type Branch
- type Client
- func (c *Client) CreateCommitStatus(ctx context.Context, instanceURL, accessToken, fullName, sha string, ...) error
- func (c *Client) CreateIssueComment(ctx context.Context, instanceURL, accessToken, fullName string, number int, ...) error
- func (c *Client) CreateRepoWebhook(ctx context.Context, ...) error
- func (c *Client) ExchangeCode(ctx context.Context, ...) (Tokens, error)
- func (c *Client) GetRepo(ctx context.Context, instanceURL, accessToken, fullName string) (Repo, error)
- func (c *Client) ListBranches(ctx context.Context, instanceURL, accessToken, fullName string) ([]Branch, error)
- func (c *Client) ListRepos(ctx context.Context, instanceURL, accessToken string) ([]Repo, error)
- func (c *Client) RefreshToken(ctx context.Context, instanceURL, clientID, clientSecret, refreshToken string) (Tokens, error)
- type CommitStatusState
- type Repo
- type Tokens
Constants ¶
const DefaultScope = "read:repository write:repository read:user"
DefaultScope requests read and write repository access (needed to list repos/branches and to register a push webhook) plus basic user identification, Gitea's own OAuth2 scope names (docs.gitea.com/development/oauth2-provider).
Variables ¶
This section is empty.
Functions ¶
func AuthorizeURL ¶
AuthorizeURL builds Gitea's OAuth2 authorization-code flow's entry point: a real browser redirect (GET), the same "the operator's browser must navigate here itself" shape internal/gitlabapp.AuthorizeURL's own doc comment describes.
Types ¶
type Client ¶
Client is a small, purpose-built Gitea REST/OAuth client, not a general-purpose Gitea SDK.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with a bounded per-request timeout, the same reasoning internal/githubapp.NewClient's own doc comment gives.
func (*Client) CreateCommitStatus ¶
func (c *Client) CreateCommitStatus(ctx context.Context, instanceURL, accessToken, fullName, sha string, state CommitStatusState, targetURL, description, statusContext string) error
CreateCommitStatus sets a commit status on sha of fullName ("owner/repo"), authenticated the same way CreateIssueComment is.
func (*Client) CreateIssueComment ¶
func (c *Client) CreateIssueComment(ctx context.Context, instanceURL, accessToken, fullName string, number int, body string) error
CreateIssueComment posts a new comment on issue/pull request number of fullName ("owner/repo"), authenticated with an OAuth access token the same way CreateRepoWebhook is. Gitea's REST API has no distinct "pull request comment" endpoint: a PR is also an issue, the same shape GitHub's own CreateIssueComment documents.
func (*Client) CreateRepoWebhook ¶
func (c *Client) CreateRepoWebhook(ctx context.Context, instanceURL, accessToken, fullName, hookURL, secret string) error
CreateRepoWebhook registers a push and pull_request webhook on fullName ("owner/repo") pointed at hookURL, with secret set as the value Gitea signs each delivery's X-Gitea-Signature header with (HMAC-SHA256, hex digest, no prefix). Gitea also sends X-Hub-Signature-256 in GitHub's own "sha256=<hex>" format for compatibility (docs.gitea.com/usage/webhooks), which is the header verifyGitPushWebhookAuth (internal/api/git_webhook.go) actually checks, so this package needs no signature-parsing code of its own. pull_request must be requested explicitly: without it Gitea never delivers the event internal/webhook's Gitea pull-request parsing expects, so preview environments would silently never trigger for a connected repo, the same reasoning GitLab's and Bitbucket's own CreateProjectWebhook/CreateRepoWebhook already give for their own merge/pull-request event keys.
func (*Client) ExchangeCode ¶
func (c *Client) ExchangeCode(ctx context.Context, instanceURL, clientID, clientSecret, redirectURI, code string) (Tokens, error)
ExchangeCode exchanges an OAuth authorization code for an access token, Gitea's documented POST {instance}/login/oauth/access_token (docs.gitea.com/development/oauth2-provider).
func (*Client) GetRepo ¶
func (c *Client) GetRepo(ctx context.Context, instanceURL, accessToken, fullName string) (Repo, error)
GetRepo looks up a single repository by its "owner/repo" full name.
func (*Client) ListBranches ¶
func (c *Client) ListBranches(ctx context.Context, instanceURL, accessToken, fullName string) ([]Branch, error)
ListBranches lists every branch of fullName ("owner/repo"), across as many pages as Gitea returns full pages for, the same pagination shape ListRepos uses.
func (*Client) ListRepos ¶
ListRepos lists every repository the token's account owns or is a collaborator on, across as many pages as Gitea returns full pages for.
func (*Client) RefreshToken ¶
func (c *Client) RefreshToken(ctx context.Context, instanceURL, clientID, clientSecret, refreshToken string) (Tokens, error)
RefreshToken exchanges a still-valid refresh token for a new access token, Gitea's grant_type "refresh_token" on the same endpoint ExchangeCode uses.
type CommitStatusState ¶
type CommitStatusState string
CommitStatusState is Gitea's own documented "state" enum for POST .../statuses/{sha}.
const ( // CommitStatusPending marks a commit status as still in progress. CommitStatusPending CommitStatusState = "pending" // CommitStatusSuccess marks a commit status as succeeded. CommitStatusSuccess CommitStatusState = "success" // CommitStatusFailure marks a commit status as failed. CommitStatusFailure CommitStatusState = "failure" )