Documentation
¶
Overview ¶
Package vcs handles version control system stuff.
templ: version: v0.3.906
Index ¶
- Constants
- Variables
- func RepoURL(provider *Provider, repo Repo) templ.SafeURL
- type Action
- type App
- type AppKind
- type Broker
- type Callback
- type Client
- type ClientConfig
- type Commit
- type CommitAuthor
- type CreateOptions
- type CreateWebhookOptions
- type DeleteWebhookOptions
- type ErrIgnoreEvent
- type Event
- type EventHeader
- type EventPayload
- type EventType
- type GetRepoTarballOptions
- type GetWebhookOptions
- type Installation
- type Kind
- type KindID
- type ListOptions
- type ListRepositoriesOptions
- type ListTagsOptions
- type NewTokenClientOptions
- type Options
- type Provider
- type Publisher
- type Repo
- type Service
- func (a *Service) AddHandlers(r *mux.Router)
- func (a *Service) BeforeDeleteVCSProvider(hook func(context.Context, *Provider) error)
- func (a *Service) Create(ctx context.Context, opts CreateOptions) (*Provider, error)
- func (a *Service) Delete(ctx context.Context, id resource.TfeID) (*Provider, error)
- func (a *Service) Get(ctx context.Context, id resource.TfeID) (*Provider, error)
- func (db Service) GetKind(id KindID) (Kind, error)
- func (db Service) GetKindByTFEServiceProviderType(sp TFEServiceProviderType) (Kind, error)
- func (db Service) GetKinds() []Kind
- func (a *Service) List(ctx context.Context, organization organization.Name) ([]*Provider, error)
- func (a *Service) ListByInstall(ctx context.Context, installID int64) ([]*Provider, error)
- func (db Service) RegisterKind(kind Kind)
- func (a *Service) Update(ctx context.Context, id resource.TfeID, opts UpdateOptions) (*Provider, error)
- type SetStatusOptions
- type SourceIconRegistrar
- type Status
- type Subscriber
- type TFEOAuthClient
- type TFEOAuthClientCreateOptions
- type TFEOAuthToken
- type TFEServiceProviderType
- type Table
- type TokenKind
- type UpdateOptions
- type UpdateWebhookOptions
- type Webhook
Constants ¶
const ( GithubAPIURL = "https://api.github.com" GithubHTTPURL = "https://github.com" )
Variables ¶
var ErrAppNotFound = errors.New("github app not found")
var ErrInvalidRepo = errors.New("repository path is invalid")
Functions ¶
Types ¶
type App ¶ added in v0.3.24
type App interface {
// ListInstallations retrieves a list of installations.
ListInstallations(context.Context) ([]Installation, error)
// GetInstallation retrieves an installation by its ID.
GetInstallation(context.Context, int64) (Installation, error)
// InstallationLink is a link to the site where a user can create an
// installation.
InstallationLink() templ.SafeURL
}
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker is a brokerage for publishers and subscribers of VCS events.
type Client ¶
type Client interface {
// ListRepositories lists repositories accessible to the current user.
ListRepositories(ctx context.Context, opts ListRepositoriesOptions) ([]Repo, error)
GetDefaultBranch(ctx context.Context, identifier string) (string, error)
// GetRepoTarball retrieves a .tar.gz tarball of a git repository
GetRepoTarball(ctx context.Context, opts GetRepoTarballOptions) ([]byte, string, error)
// CreateWebhook creates a webhook on the cloud provider, returning the
// provider's unique ID for the webhook.
CreateWebhook(ctx context.Context, opts CreateWebhookOptions) (string, error)
UpdateWebhook(ctx context.Context, id string, opts UpdateWebhookOptions) error
GetWebhook(ctx context.Context, opts GetWebhookOptions) (Webhook, error)
DeleteWebhook(ctx context.Context, opts DeleteWebhookOptions) error
SetStatus(ctx context.Context, opts SetStatusOptions) error
// ListTags lists git tags on a repository. Each tag should be prefixed with
// 'tags/'.
ListTags(ctx context.Context, opts ListTagsOptions) ([]string, error)
// ListPullRequestFiles returns the paths of files that are modified in the pull request
ListPullRequestFiles(ctx context.Context, repo Repo, pull int) ([]string, error)
// GetCommit retrieves commit from the repo with the given git ref
GetCommit(ctx context.Context, repo Repo, ref string) (Commit, error)
}
type ClientConfig ¶ added in v0.4.0
type ClientConfig struct {
Token *string
Installation *Installation
BaseURL *internal.WebURL
}
ClientConfig is configuration for the construction of a client.
type Commit ¶
type Commit struct {
SHA string
URL string
Author CommitAuthor
}
type CommitAuthor ¶
type CreateOptions ¶ added in v0.3.24
type CreateOptions struct {
Organization organization.Name `schema:"organization_name,required"`
Name string
KindID KindID `schema:"kind,required"`
// Token and InstallID are mutually exclusive.
Token *string
InstallID *int64 `schema:"install_id"`
// Optional.
BaseURL *internal.WebURL `schema:"base_url,required"`
// contains filtered or unexported fields
}
type CreateWebhookOptions ¶
type DeleteWebhookOptions ¶
type DeleteWebhookOptions struct {
Repo Repo // Repository identifier, <owner>/<repo>
ID string // vcs' webhook ID
}
DeleteWebhookOptions are options for deleting a webhook.
type ErrIgnoreEvent ¶ added in v0.2.3
type ErrIgnoreEvent struct {
Reason string
}
ErrIgnoreEvent informs an upstream vcs provider why an event it sent is ignored.
func NewErrIgnoreEvent ¶ added in v0.2.3
func NewErrIgnoreEvent(msg string, args ...any) ErrIgnoreEvent
func (ErrIgnoreEvent) Error ¶ added in v0.2.3
func (e ErrIgnoreEvent) Error() string
type Event ¶
type Event struct {
EventHeader
EventPayload
}
Event is a VCS event received from a cloud, e.g. a commit event from github
type EventHeader ¶
type EventPayload ¶
type EventPayload struct {
Repo Repo
Type EventType
Action Action
Tag string
CommitSHA string
CommitURL string
Branch string // head branch
DefaultBranch string
PullRequestNumber int
PullRequestURL string
PullRequestTitle string
SenderUsername string
SenderAvatarURL string
SenderHTMLURL string
// Paths of files that have been added/modified/removed. Only applicable
// to Push and Tag events types.
Paths []string
// Only set if event is from a github app
GithubAppInstallID *int64
}
func (EventPayload) Validate ¶
func (e EventPayload) Validate() error
type GetRepoTarballOptions ¶
type GetWebhookOptions ¶
type GetWebhookOptions struct {
Repo Repo // Repository identifier, <owner>/<repo>
ID string // vcs' webhook ID
}
GetWebhookOptions are options for retrieving a webhook.
type Installation ¶ added in v0.3.24
type Installation struct {
ID int64
AppID int64
Username *string
Organization *string
HTMLURL string
}
func NewInstallation ¶ added in v0.3.24
func NewInstallation(ghInstall *github.Installation) (Installation, error)
func (Installation) String ¶ added in v0.3.24
func (i Installation) String() string
type Kind ¶
type Kind struct {
// ID distinguishes this kind from other kinds. NOTE: This must have first
// been inserted into the vcs_kinds table via a database migration.
ID KindID
// DefaultURL is the default base URL for the provider.
DefaultURL *internal.WebURL
// Icon renders an icon identifying the VCS host kind.
Icon templ.Component
// TokenKind provides info about the token the provider expects. Mutually
// exclusive with AppKind.
TokenKind *TokenKind
// AppKind provides info about installations for this ProviderKind.
// Mutually exclusive with TokenKind.
AppKind AppKind
// NewClient constructs a client implementation.
NewClient func(context.Context, ClientConfig) (Client, error)
// EventHandler handles incoming events from the VCS host before relaying
// them onwards for triggering actions like creating runs etc.
EventHandler func(r *http.Request, secret string) (*EventPayload, error)
// SkipRepohook if true skips the creation of a repository-level webhook.
SkipRepohook bool
// TFEServiceProviders registers the kind with the TFE API, permitting vcs
// providers of this kind to be created via the TFE API. The value specified
// here is the value that should be be provided by API clients via the
// "service-provider" attribute:
//
// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/oauth-clients#request-body
//
// Must provide at least one type. A kind can register more than one type,
// e.g. gitlab-ce and gitlab-ee, in which case if a client specifies either
// of these types then OTF creates a provider of the gitlab kind. Note that
// OTF makes no distinction between multiple types but it's merely there to
// support the TFE API and the various values that clients might provide
// according to the API documentation (though OTF may in future make a
// distinction!).
TFEServiceProviders []TFEServiceProviderType
// Source sets the source identifier for this kind, to inform users which
// kind is the source of a run configuration. By default the ID is used as
// the source identifier but Source takes precedence if it is non-nil.
Source *source.Source
}
Kind is a kind of vcs provider. Each kind represents a particular VCS hosting provider (e.g. github), and a way of interacting with the provider, including authentication, event handling. Typically there is one kind per VCS hosting provider, but providers sometimes offer more than one of interacting with it, e.g. GitHub uses both personal access tokens and a GitHub 'app' which is 'installed' via a private key.
type ListOptions ¶ added in v0.3.24
type ListOptions struct {
resource.PageOptions
Organization organization.Name `schema:"organization_name"`
}
type ListRepositoriesOptions ¶
type ListRepositoriesOptions struct {
PageSize int
}
type ListTagsOptions ¶
type ListTagsOptions struct {
Repo Repo // repo identifier, <owner>/<repo>
Prefix string // only list tags that start with this string
}
ListTagsOptions are options for listing tags on a vcs repository
type NewTokenClientOptions ¶
type NewTokenClientOptions struct {
Token string
BaseURL *internal.WebURL
SkipTLSVerification bool
}
NewTokenClientOptions are options for creating a client using a personal access token (PAT).
type Options ¶ added in v0.3.24
type Options struct {
*internal.HostnameService
*sql.DB
*tfeapi.Responder
logr.Logger
SourceIconRegistrar SourceIconRegistrar
SkipTLSVerification bool
Authorizer *authz.Authorizer
}
type Provider ¶ added in v0.3.24
type Provider struct {
ID resource.TfeID
Name string
CreatedAt time.Time
Organization organization.Name
Token *string
Installation *Installation
// The kind of provider
Kind
// Client is the actual client for interacting with the VCS host.
Client
// The base URL of the the provider.
BaseURL *internal.WebURL
// contains filtered or unexported fields
}
Provider is an identifiable client for interacting with a VCS host.
func (*Provider) String ¶ added in v0.3.24
String provides a human meaningful description of the vcs provider.
func (*Provider) Update ¶ added in v0.3.24
func (t *Provider) Update(opts UpdateOptions) error
type Repo ¶ added in v0.3.24
type Repo struct {
// contains filtered or unexported fields
}
Repo is a hosted VCS repository.
func NewMustRepo ¶ added in v0.3.25
func NewRandomModuleRepo ¶ added in v0.3.25
func NewRandomRepo ¶ added in v0.3.25
func NewRandomRepo() Repo
func NewRepoFromString ¶ added in v0.3.25
func (Repo) MarshalText ¶ added in v0.3.25
func (Repo) Name ¶ added in v0.3.24
Name is the actual name of the repo, not including the owner or namespace.
func (Repo) Owner ¶ added in v0.3.24
Owner is the owner of the repo. On some kinds, e.g. Gitlab, the owner is the 'namespace', which may include forward slashes to indicate subgroups.
func (*Repo) UnmarshalText ¶ added in v0.3.25
type Service ¶ added in v0.3.24
type Service struct {
logr.Logger
*authz.Authorizer
*internal.HostnameService
// contains filtered or unexported fields
}
func NewService ¶ added in v0.3.24
func (*Service) AddHandlers ¶ added in v0.3.24
func (*Service) BeforeDeleteVCSProvider ¶ added in v0.3.24
func (Service) GetKindByTFEServiceProviderType ¶ added in v0.3.24
func (db Service) GetKindByTFEServiceProviderType(sp TFEServiceProviderType) (Kind, error)
GetKindByTFEServiceProviderType retrieves a kind by its TFE service provider type.
func (*Service) ListByInstall ¶ added in v0.3.24
func (Service) RegisterKind ¶ added in v0.3.24
func (db Service) RegisterKind(kind Kind)
type SetStatusOptions ¶
type SetStatusOptions struct {
Workspace string // workspace name
Repo Repo // <owner>/<repo>
Ref string // git ref
Status Status
TargetURL string
Description string
}
SetStatusOptions are options for setting a status on a VCS repo
type SourceIconRegistrar ¶ added in v0.3.25
type Subscriber ¶
type Subscriber interface {
Subscribe(cb Callback)
}
type TFEOAuthClient ¶ added in v0.3.24
type TFEOAuthClient struct {
ID resource.TfeID `jsonapi:"primary,oauth-clients"`
APIURL string `jsonapi:"attribute" json:"api-url"`
CallbackURL string `jsonapi:"attribute" json:"callback-url"`
ConnectPath string `jsonapi:"attribute" json:"connect-path"`
CreatedAt time.Time `jsonapi:"attribute" json:"created-at"`
HTTPURL string `jsonapi:"attribute" json:"http-url"`
Key string `jsonapi:"attribute" json:"key"`
RSAPublicKey string `jsonapi:"attribute" json:"rsa-public-key"`
Name *string `jsonapi:"attribute" json:"name"`
Secret string `jsonapi:"attribute" json:"secret"`
ServiceProvider TFEServiceProviderType `jsonapi:"attribute" json:"service-provider"`
ServiceProviderName string `jsonapi:"attribute" json:"service-provider-display-name"`
// Relations
Organization *organization.TFEOrganization `jsonapi:"relationship" json:"organization"`
OAuthTokens []*TFEOAuthToken `jsonapi:"relationship" json:"oauth-tokens"`
}
TFEOAuthClient represents a connection between an organization and a VCS provider.
type TFEOAuthClientCreateOptions ¶ added in v0.3.24
type TFEOAuthClientCreateOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,oauth-clients"`
// A display name for the OAuth Client.
Name *string `jsonapi:"attribute" json:"name"`
// Required: The base URL of your VCS provider's API.
APIURL *internal.WebURL `jsonapi:"attribute" json:"api-url"`
// Required: The homepage of your VCS provider.
HTTPURL *internal.WebURL `jsonapi:"attribute" json:"http-url"`
// Optional: The OAuth Client key.
Key *string `jsonapi:"attribute" json:"key,omitempty"`
// Optional: The token string you were given by your VCS provider.
OAuthToken *string `jsonapi:"attribute" json:"oauth-token-string,omitempty"`
// Optional: Private key associated with this vcs provider - only available for ado_server
PrivateKey *string `jsonapi:"attribute" json:"private-key,omitempty"`
// Optional: Secret key associated with this vcs provider - only available for ado_server
Secret *string `jsonapi:"attribute" json:"secret,omitempty"`
// Optional: RSAPublicKey the text of the SSH public key associated with your BitBucket
// Server Application Link.
RSAPublicKey *string `jsonapi:"attribute" json:"rsa-public-key,omitempty"`
// Required: The VCS provider being connected with.
ServiceProvider *TFEServiceProviderType `jsonapi:"attribute" json:"service-provider"`
}
TFEOAuthClientCreateOptions represents the options for creating an OAuth client.
type TFEOAuthToken ¶ added in v0.3.24
type TFEOAuthToken struct {
ID resource.TfeID `jsonapi:"primary,oauth-tokens"`
UID resource.TfeID `jsonapi:"attribute" json:"uid"`
CreatedAt time.Time `jsonapi:"attribute" json:"created-at"`
HasSSHKey bool `jsonapi:"attribute" json:"has-ssh-key"`
ServiceProviderUser string `jsonapi:"attribute" json:"service-provider-user"`
// Relations
OAuthClient *TFEOAuthClient `jsonapi:"relationship" json:"oauth-client"`
}
TFEOAuthToken represents a VCS configuration including the associated OAuth token
type TFEServiceProviderType ¶ added in v0.3.24
type TFEServiceProviderType string
TFEServiceProviderType represents a VCS type.
const ( ServiceProviderAzureDevOpsServer TFEServiceProviderType = "ado_server" ServiceProviderAzureDevOpsServices TFEServiceProviderType = "ado_services" ServiceProviderBitbucket TFEServiceProviderType = "bitbucket_hosted" // Bitbucket Server v5.4.0 and above ServiceProviderBitbucketServer TFEServiceProviderType = "bitbucket_server" // Bitbucket Server v5.3.0 and below ServiceProviderBitbucketServerLegacy TFEServiceProviderType = "bitbucket_server_legacy" ServiceProviderForgejo TFEServiceProviderType = "forgejo" ServiceProviderGithub TFEServiceProviderType = "github" ServiceProviderGithubEE TFEServiceProviderType = "github_enterprise" ServiceProviderGithubApp TFEServiceProviderType = "github_app" ServiceProviderGitlab TFEServiceProviderType = "gitlab_hosted" ServiceProviderGitlabCE TFEServiceProviderType = "gitlab_community_edition" ServiceProviderGitlabEE TFEServiceProviderType = "gitlab_enterprise_edition" )
List of available VCS types.
type UpdateOptions ¶ added in v0.3.24
type UpdateWebhookOptions ¶
type UpdateWebhookOptions CreateWebhookOptions