gitlabapp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gitlabapp implements OAuth2 and the small slice of GitLab's REST API this control plane needs once connected.

Methods take instanceURL explicitly rather than baking one into the Client, since GitLab is commonly self-hosted and not fixed like api.github.com.

Index

Constants

View Source
const DefaultScope = "api"

DefaultScope requests read access for project listing and write access for registering a project webhook: GitLab's own docs (docs.gitlab.com/ee/api/oauth2.html) document "api" as required for the webhook-creation endpoint, "read_api" alone is not enough.

Variables

This section is empty.

Functions

func AuthorizeURL

func AuthorizeURL(instanceURL, clientID, redirectURI, state string) string

AuthorizeURL builds the GitLab OAuth2 authorization-code flow's entry point: a real browser redirect (GET), not a fetch call, the same "the operator's browser must navigate here itself" shape internal/githubapp's manifest flow requires for the equivalent reason.

Types

type Branch

type Branch struct {
	Name      string
	CommitSHA string
}

Branch is one branch of one project.

type Client

type Client struct {
	HTTP *http.Client
}

Client is a small, purpose-built GitLab REST/OAuth client, not a general-purpose GitLab 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) CreateProjectWebhook

func (c *Client) CreateProjectWebhook(ctx context.Context, instanceURL, accessToken string, projectID int64, hookURL, secretToken string) error

CreateProjectWebhook registers a push- and merge-request-events webhook on projectID pointed at hookURL, authenticated by GitLab's own X-Gitlab-Token scheme (secretToken echoed back on every delivery, not an HMAC signature the way GitHub's webhooks work). merge_requests_events must be requested explicitly: without it GitLab never sends the "Merge Request Hook" delivery internal/webhook's GitLab pull-request parsing expects, so preview environments would silently never trigger for a connected project.

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, GitLab's documented POST {instance}/oauth/token grant_type "authorization_code" (docs.gitlab.com/ee/api/oauth2.html).

func (*Client) GetProject

func (c *Client) GetProject(ctx context.Context, instanceURL, accessToken string, projectID int64) (Project, error)

GetProject looks up a single project by ID.

func (*Client) ListBranches

func (c *Client) ListBranches(ctx context.Context, instanceURL, accessToken string, projectID int64) ([]Branch, error)

ListBranches lists every branch of projectID, across as many pages as GitLab returns full pages for, the same pagination shape ListProjects uses.

func (*Client) ListProjects

func (c *Client) ListProjects(ctx context.Context, instanceURL, accessToken string) ([]Project, error)

ListProjects lists every project the token's account is at least a member of, across as many pages as GitLab 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, GitLab's grant_type "refresh_token" on the same endpoint ExchangeCode uses.

type Project

type Project struct {
	ID                int64
	Name              string
	PathWithNamespace string
	HTTPURLToRepo     string
	DefaultBranch     string
	Visibility        string
	WebURL            string
}

Project is one GitLab project accessible to the connected account, the subset of GitLab's Project object this control plane's project picker and "use as source" action need.

type Tokens

type Tokens struct {
	AccessToken  string
	RefreshToken string
	ExpiresAt    time.Time
}

Tokens is ExchangeCode's and RefreshToken's shared result.

Jump to

Keyboard shortcuts

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