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
- func DefaultAPIURL(kind string) string
- func GitHubAPIFor(webURL string) string
- func Installations(ctx context.Context, p Provider) ([]string, error)
- func IsNotFound(err error) bool
- func ValidRepoName(full string) bool
- func WebURLFor(kind, apiURL string) string
- type APIError
- type Conn
- type ManifestConversion
- type Provider
- type Repo
- type Secrets
- type Status
Constants ¶
const ( KindGitHubApp = "github-app" KindGitHub = "github" KindGitLab = "gitlab" KindGitea = "gitea" )
Kinds of connection.
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 ¶
DefaultAPIURL is the API base of a hosted service ("" when it must be given).
func GitHubAPIFor ¶
GitHubAPIFor is the API URL of github.com or a GitHub Enterprise server.
func Installations ¶
Installations lists the accounts a GitHub App is installed on.
func ValidRepoName ¶
ValidRepoName accepts owner/name paths (GitLab may nest groups).
Types ¶
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.
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.