Documentation
¶
Overview ¶
Package vcs handles version control system stuff.
templ: version: v0.3.865
Index ¶
- Constants
- Variables
- func NewTestModuleRepo(provider, name string) string
- func NewTestRepo() string
- func RepoURL(provider *Provider, repo string) templ.SafeURL
- type Action
- type App
- type AppKind
- type Broker
- type Callback
- type Client
- type Commit
- type CommitAuthor
- type Config
- 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 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")
Functions ¶
func NewTestModuleRepo ¶
func NewTestRepo ¶
func NewTestRepo() string
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) ([]string, 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 string, pull int) ([]string, error)
// GetCommit retrieves commit from the repo with the given git ref
GetCommit(ctx context.Context, repo, ref string) (Commit, error)
}
type Commit ¶
type Commit struct {
SHA string
URL string
Author CommitAuthor
}
type CommitAuthor ¶
type Config ¶ added in v0.3.24
type Config struct {
Token *string
Installation *Installation
}
type CreateOptions ¶ added in v0.3.24
type CreateWebhookOptions ¶
type DeleteWebhookOptions ¶
type DeleteWebhookOptions struct {
Repo string // 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 EventHeader struct {
// ID of vcs provider that generated this event.
// event.
VCSProviderID resource.TfeID
// Source of vcs provider kind that generated this event.
Source configversion.Source
}
type EventPayload ¶
type EventPayload struct {
RepoPath string
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 string // 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
// Hostname is the hostname of the VCS host, not including scheme or path.
Hostname string
// 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, Config) (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
// TFEServiceProvider optionally 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
TFEServiceProvider 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 *configversion.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.
func (Kind) GetSource ¶ added in v0.3.24
func (k Kind) GetSource() configversion.Source
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 string // 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 ¶
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
ConfigVersionService *configversion.Service
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
// The kind of provider
Kind
// Config for constructing a client
Config
// Client is the actual client for interacting with the VCS host.
Client
}
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 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)
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 string // <owner>/<repo>
Ref string // git ref
Status Status
TargetURL string
Description string
}
SetStatusOptions are options for setting a status on a VCS repo
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 *string `jsonapi:"attribute" json:"api-url"`
// Required: The homepage of your VCS provider.
HTTPURL *string `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" 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