gitprovider

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitprovider talks to Git hosting APIs (§5.8): GitHub (as a GitHub App or with a token), GitLab and Gitea/Forgejo. It lists repositories and branches, mints tokens for cloning, creates push webhooks and reports commit statuses, so connecting a repository needs no manual setup.

Index

Constants

View Source
const (
	KindGitHubApp = "github-app"
	KindGitHub    = "github"
	KindGitLab    = "gitlab"
	KindGitea     = "gitea"
)

Kinds of connection.

View Source
const (
	StatePending = "pending" // queued
	StateRunning = "running" // building or deploying
	StateSuccess = "success"
	StateFailure = "failure"
)

Commit states for SetStatus.

Variables

This section is empty.

Functions

func DefaultAPIURL

func DefaultAPIURL(kind string) string

DefaultAPIURL is the API base of a hosted service ("" when it must be given).

func GitHubAPIFor

func GitHubAPIFor(webURL string) string

GitHubAPIFor is the API URL of github.com or a GitHub Enterprise server.

func Installations

func Installations(ctx context.Context, p Provider) ([]string, error)

Installations lists the accounts a GitHub App is installed on.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports a 404 from the provider.

func ValidRepoName

func ValidRepoName(full string) bool

ValidRepoName accepts owner/name paths (GitLab may nest groups).

func WebURLFor

func WebURLFor(kind, apiURL string) string

WebURLFor is the browser URL of an API URL.

Types

type APIError

type APIError struct {
	Status  int
	Message string
}

APIError is a non-2xx answer.

func (*APIError) Error

func (e *APIError) Error() string

type Conn

type Conn struct {
	Kind    string
	APIURL  string
	AppID   int64
	Secrets Secrets
}

Conn is what New needs to build a Provider.

type ManifestConversion

type ManifestConversion struct {
	ID            int64  `json:"id"`
	Slug          string `json:"slug"`
	Name          string `json:"name"`
	HTMLURL       string `json:"html_url"`
	ClientID      string `json:"client_id"`
	ClientSecret  string `json:"client_secret"`
	WebhookSecret string `json:"webhook_secret"`
	PEM           string `json:"pem"`
	Owner         struct {
		Login string `json:"login"`
	} `json:"owner"`
}

ManifestConversion is what GitHub returns for a created app.

func ConvertManifest

func ConvertManifest(ctx context.Context, apiURL, code string) (ManifestConversion, error)

ConvertManifest exchanges the code GitHub redirects back with for the new app's credentials (POST /app-manifests/{code}/conversions).

type Provider

type Provider interface {
	// Account verifies the credentials and returns who they act as.
	Account(ctx context.Context) (string, error)
	// Repos lists repositories whose name contains query ("" = all, newest
	// activity first, capped).
	Repos(ctx context.Context, query string) ([]Repo, error)
	Repo(ctx context.Context, fullName string) (Repo, error)
	Branches(ctx context.Context, fullName string) ([]string, error)
	// Token is a password for git over HTTPS (short-lived for GitHub Apps).
	Token(ctx context.Context, fullName string) (string, error)
	// CreateHook adds a push webhook and returns its ID; "" with no error
	// means the provider delivers pushes another way (a GitHub App's own
	// webhook).
	CreateHook(ctx context.Context, fullName, hookURL, secret string) (string, error)
	DeleteHook(ctx context.Context, fullName, id string) error
	SetStatus(ctx context.Context, fullName, sha string, s Status) error
}

Provider is one connection's API.

func New

func New(c Conn) (Provider, error)

New returns the provider for a connection.

type Repo

type Repo struct {
	FullName      string `json:"fullName"` // owner/name (GitLab: group/subgroup/name)
	CloneURL      string `json:"cloneUrl"`
	WebURL        string `json:"webUrl"`
	DefaultBranch string `json:"defaultBranch"`
	Private       bool   `json:"private"`
}

Repo is a repository the connection can read.

type Secrets

type Secrets struct {
	Token         string `json:"token,omitempty"`
	PrivateKey    string `json:"privateKey,omitempty"` // GitHub App (PEM)
	ClientID      string `json:"clientId,omitempty"`
	ClientSecret  string `json:"clientSecret,omitempty"`
	WebhookSecret string `json:"webhookSecret,omitempty"`
}

Secrets are the sealed part of a connection.

type Status

type Status struct {
	State       string
	Context     string // e.g. syncloud/shop/production/web
	Description string
	TargetURL   string
}

Status is a commit status (a check next to the commit on the Git host).

Jump to

Keyboard shortcuts

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