Documentation
¶
Overview ¶
Package github provides the ability for Vela to integrate with GitHub or GitHub Enterprise as a scm provider.
Usage:
import "github.com/go-vela/server/scm/github"
Index ¶
- Constants
- func ApplyInstallationPermissions(resource, perm string, perms *github.InstallationPermissions) (*github.InstallationPermissions, error)
- func GetInstallationPermission(resource string, appPermissions *github.InstallationPermissions) (string, error)
- func GetReadWriter(i interface{}) (io.ReadWriter, error)
- func InstallationHasPermission(resource, requiredPerm, actualPerm string) error
- type AppsTransport
- type AppsTransportOption
- type Client
- func (c *Client) Authenticate(ctx context.Context, _ http.ResponseWriter, r *http.Request, oAuthState string) (*api.User, error)
- func (c *Client) AuthenticateToken(ctx context.Context, r *http.Request) (*api.User, error)
- func (c *Client) Authorize(ctx context.Context, token string) (string, error)
- func (c *Client) Changeset(ctx context.Context, r *api.Repo, sha string) ([]string, error)
- func (c *Client) ChangesetPR(ctx context.Context, r *api.Repo, number int) ([]string, error)
- func (c *Client) Config(ctx context.Context, u *api.User, r *api.Repo, ref string) ([]byte, error)
- func (c *Client) ConfigBackoff(ctx context.Context, u *api.User, r *api.Repo, ref string) (data []byte, err error)
- func (c *Client) CreateDeployment(ctx context.Context, u *api.User, r *api.Repo, d *api.Deployment) error
- func (c *Client) CreateWebhook(ctx context.Context, u *api.User, r *api.Repo, h *api.Hook) (*api.Hook, string, error)
- func (c *Client) DestroyWebhook(ctx context.Context, u *api.User, org, name string) error
- func (c *Client) Disable(ctx context.Context, u *api.User, org, name string) error
- func (c *Client) Driver() string
- func (c *Client) Enable(ctx context.Context, u *api.User, r *api.Repo, h *api.Hook) (*api.Hook, string, error)
- func (c *Client) FinishInstallation(ctx context.Context, _ *http.Request, installID int64) (string, error)
- func (c *Client) GetBranch(ctx context.Context, r *api.Repo, branch string) (string, string, error)
- func (c *Client) GetDeployment(ctx context.Context, u *api.User, r *api.Repo, id int64) (*api.Deployment, error)
- func (c *Client) GetDeploymentCount(ctx context.Context, u *api.User, r *api.Repo) (int64, error)
- func (c *Client) GetDeploymentList(ctx context.Context, u *api.User, r *api.Repo, page, perPage int) ([]*api.Deployment, error)
- func (c *Client) GetHTMLURL(ctx context.Context, u *api.User, org, repo, name, ref string) (string, error)
- func (c *Client) GetNetrcPassword(ctx context.Context, db database.Interface, r *api.Repo, u *api.User, ...) (string, error)
- func (c *Client) GetOrgAndRepoName(ctx context.Context, u *api.User, o string, r string) (string, string, error)
- func (c *Client) GetOrgName(ctx context.Context, u *api.User, o string) (string, error)
- func (c *Client) GetPullRequest(ctx context.Context, r *api.Repo, number int) (string, string, string, string, error)
- func (c *Client) GetRepo(ctx context.Context, u *api.User, r *api.Repo) (*api.Repo, int, error)
- func (c *Client) GetSettings() settings.SCM
- func (c *Client) GetUserID(ctx context.Context, name string, token string) (string, error)
- func (c *Client) ListUserRepos(ctx context.Context, u *api.User) ([]string, error)
- func (c *Client) ListUsersTeamsForOrg(ctx context.Context, u *api.User, org string) ([]string, error)
- func (c *Client) Login(_ context.Context, w http.ResponseWriter, r *http.Request) (string, error)
- func (c *Client) OrgAccess(ctx context.Context, u *api.User, org string) (string, error)
- func (c *Client) ProcessInstallation(ctx context.Context, _ *http.Request, webhook *internal.Webhook, ...) error
- func (c *Client) ProcessWebhook(ctx context.Context, request *http.Request) (*internal.Webhook, error)
- func (c *Client) RedeliverWebhook(ctx context.Context, u *api.User, h *api.Hook) error
- func (c *Client) RepoAccess(ctx context.Context, name, token, org, repo string) (string, error)
- func (c *Client) RepoContributor(ctx context.Context, owner *api.User, sender, org, repo string) (bool, error)
- func (c *Client) SetSettings(s *settings.Platform)
- func (c *Client) Status(ctx context.Context, b *api.Build, org, name, token string) error
- func (c *Client) StepStatus(ctx context.Context, b *api.Build, s *api.Step, org, name, token string) error
- func (c *Client) SyncRepoWithInstallation(ctx context.Context, r *api.Repo) (*api.Repo, error)
- func (c *Client) TeamAccess(ctx context.Context, u *api.User, org, team string) (string, error)
- func (c *Client) Update(ctx context.Context, u *api.User, r *api.Repo, hookID int64) (bool, error)
- func (c *Client) ValidateGitHubApp(ctx context.Context) error
- func (c *Client) ValidateOAuthToken(ctx context.Context, token string) (bool, error)
- func (c *Client) VerifyWebhook(_ context.Context, request *http.Request, secret []byte) error
- type ClientOpt
- func WithAddress(address string) ClientOpt
- func WithClientID(id string) ClientOpt
- func WithClientSecret(secret string) ClientOpt
- func WithGitHubAppPermissions(permissions []string) ClientOpt
- func WithGithubAppID(id int64) ClientOpt
- func WithGithubPrivateKey(key string) ClientOpt
- func WithGithubPrivateKeyPath(path string) ClientOpt
- func WithOAuthScopes(scopes []string) ClientOpt
- func WithOrgRoleMap(mapping map[string]string) ClientOpt
- func WithRepoRoleMap(mapping map[string]string) ClientOpt
- func WithServerAddress(address string) ClientOpt
- func WithServerWebhookAddress(address string) ClientOpt
- func WithStatusContext(context string) ClientOpt
- func WithTeamRoleMap(mapping map[string]string) ClientOpt
- func WithTracing(tracing *tracing.Client) ClientOpt
- func WithWebUIAddress(address string) ClientOpt
- type HTTPClient
- type RSASigner
- type Signer
- type Transport
Constants ¶
const ( // GitHub App install permission 'none'. AppInstallPermissionNone = "none" // GitHub App install permission 'read'. AppInstallPermissionRead = "read" // GitHub App install permission 'write'. AppInstallPermissionWrite = "write" )
const ( // GitHub App install contents resource. AppInstallResourceContents = "contents" // GitHub App install checks resource. AppInstallResourceChecks = "checks" // GitHub App install packages resource. AppInstallResourcePackages = "packages" )
Variables ¶
This section is empty.
Functions ¶
func ApplyInstallationPermissions ¶ added in v0.26.0
func ApplyInstallationPermissions(resource, perm string, perms *github.InstallationPermissions) (*github.InstallationPermissions, error)
ApplyInstallationPermissions takes permissions and applies a new permission if valid.
func GetInstallationPermission ¶ added in v0.26.0
func GetInstallationPermission(resource string, appPermissions *github.InstallationPermissions) (string, error)
GetInstallationPermission takes permissions and returns the permission level if valid.
func GetReadWriter ¶ added in v0.26.0
func GetReadWriter(i interface{}) (io.ReadWriter, error)
GetReadWriter converts a body interface into an io.ReadWriter object.
func InstallationHasPermission ¶ added in v0.26.0
InstallationHasPermission takes a resource:perm pair and checks if the actual permission matches the expected permission or is supersceded by a higher permission.
Types ¶
type AppsTransport ¶ added in v0.26.0
type AppsTransport struct { BaseURL string // BaseURL is the scheme and host for GitHub API, defaults to https://api.github.com Client HTTPClient // Client to use to refresh tokens, defaults to http.Client with provided transport // contains filtered or unexported fields }
AppsTransport provides a http.RoundTripper by wrapping an existing http.RoundTripper and provides GitHub Apps authentication as a GitHub App.
Client can also be overwritten, and is useful to change to one which provides retry logic if you do experience retryable errors.
func NewTestAppsTransport ¶ added in v0.26.0
func NewTestAppsTransport(baseURL string) *AppsTransport
NewTestAppsTransport creates a new AppsTransport for testing purposes.
type AppsTransportOption ¶ added in v0.26.0
type AppsTransportOption func(*AppsTransport)
AppsTransportOption is a func option for configuring an AppsTransport.
func WithSigner ¶ added in v0.26.0
func WithSigner(signer Signer) AppsTransportOption
WithSigner configures the AppsTransport to use the given Signer for generating JWT tokens.
type Client ¶ added in v0.26.0
type Client struct { OAuth *oauth2.Config AuthReq *github.AuthorizationRequest Tracing *tracing.Client AppsTransport *AppsTransport settings.SCM // https://pkg.go.dev/github.com/sirupsen/logrus#Entry Logger *logrus.Entry // contains filtered or unexported fields }
func New ¶
New returns a SCM implementation that integrates with a GitHub or a GitHub Enterprise instance.
func NewTest ¶
NewTest returns a SCM implementation that integrates with the provided mock server. Only the url from the mock server is required.
This function is intended for running tests only.
func (*Client) Authenticate ¶ added in v0.27.0
func (c *Client) Authenticate(ctx context.Context, _ http.ResponseWriter, r *http.Request, oAuthState string) (*api.User, error)
Authenticate completes the authentication workflow for the session and returns the remote user details.
func (*Client) AuthenticateToken ¶ added in v0.27.0
AuthenticateToken completes the authentication workflow for the session and returns the remote user details.
func (*Client) Authorize ¶ added in v0.27.0
Authorize uses the given access token to authorize the user.
func (*Client) Changeset ¶ added in v0.27.0
Changeset captures the list of files changed for a commit.
func (*Client) ChangesetPR ¶ added in v0.27.0
ChangesetPR captures the list of files changed for a pull request.
func (*Client) Config ¶ added in v0.27.0
Config gets the pipeline configuration from the GitHub repo.
func (*Client) ConfigBackoff ¶ added in v0.27.0
func (c *Client) ConfigBackoff(ctx context.Context, u *api.User, r *api.Repo, ref string) (data []byte, err error)
ConfigBackoff is a wrapper for Config that will retry five times if the function fails to retrieve the yaml/yml file.
func (*Client) CreateDeployment ¶ added in v0.27.0
func (c *Client) CreateDeployment(ctx context.Context, u *api.User, r *api.Repo, d *api.Deployment) error
CreateDeployment creates a new deployment for the GitHub repo.
func (*Client) CreateWebhook ¶ added in v0.27.0
func (c *Client) CreateWebhook(ctx context.Context, u *api.User, r *api.Repo, h *api.Hook) (*api.Hook, string, error)
CreateWebhook creates a repo's webhook.
func (*Client) DestroyWebhook ¶ added in v0.27.0
DestroyWebhook deletes a repo's webhook.
func (*Client) Enable ¶ added in v0.27.0
func (c *Client) Enable(ctx context.Context, u *api.User, r *api.Repo, h *api.Hook) (*api.Hook, string, error)
Enable activates a repo by creating the webhook.
func (*Client) FinishInstallation ¶ added in v0.27.0
func (c *Client) FinishInstallation(ctx context.Context, _ *http.Request, installID int64) (string, error)
FinishInstallation completes the web flow for a GitHub App installation, returning a redirect to the app installation page.
func (*Client) GetBranch ¶ added in v0.27.0
GetBranch defines a function that retrieves a branch for a repo.
func (*Client) GetDeployment ¶ added in v0.27.0
func (c *Client) GetDeployment(ctx context.Context, u *api.User, r *api.Repo, id int64) (*api.Deployment, error)
GetDeployment gets a deployment from the GitHub repo.
func (*Client) GetDeploymentCount ¶ added in v0.27.0
GetDeploymentCount counts a list of deployments from the GitHub repo.
func (*Client) GetDeploymentList ¶ added in v0.27.0
func (c *Client) GetDeploymentList(ctx context.Context, u *api.User, r *api.Repo, page, perPage int) ([]*api.Deployment, error)
GetDeploymentList gets a list of deployments from the GitHub repo.
func (*Client) GetHTMLURL ¶ added in v0.27.0
func (c *Client) GetHTMLURL(ctx context.Context, u *api.User, org, repo, name, ref string) (string, error)
GetHTMLURL retrieves the html_url from repository contents from the GitHub repo.
func (*Client) GetNetrcPassword ¶ added in v0.27.0
func (c *Client) GetNetrcPassword(ctx context.Context, db database.Interface, r *api.Repo, u *api.User, g yaml.Git) (string, error)
GetNetrcPassword returns a clone token using the repo's github app installation if it exists. If not, it defaults to the user OAuth token.
func (*Client) GetOrgAndRepoName ¶ added in v0.27.0
func (c *Client) GetOrgAndRepoName(ctx context.Context, u *api.User, o string, r string) (string, string, error)
GetOrgAndRepoName returns the name of the org and the repository in the SCM.
func (*Client) GetOrgName ¶ added in v0.27.0
GetOrgName gets org name from Github.
func (*Client) GetPullRequest ¶ added in v0.27.0
func (c *Client) GetPullRequest(ctx context.Context, r *api.Repo, number int) (string, string, string, string, error)
GetPullRequest defines a function that retrieves a pull request for a repo.
func (*Client) GetSettings ¶ added in v0.27.0
GetSettings retrieves the api settings type in the Engine.
func (*Client) ListUserRepos ¶ added in v0.27.0
ListUserRepos returns a list of all repos the user has access to.
func (*Client) ListUsersTeamsForOrg ¶ added in v0.27.0
func (c *Client) ListUsersTeamsForOrg(ctx context.Context, u *api.User, org string) ([]string, error)
ListUsersTeamsForOrg captures the user's teams for an org.
func (*Client) ProcessInstallation ¶ added in v0.27.0
func (c *Client) ProcessInstallation(ctx context.Context, _ *http.Request, webhook *internal.Webhook, db database.Interface) error
ProcessInstallation takes a GitHub installation and processes the changes.
func (*Client) ProcessWebhook ¶ added in v0.27.0
func (c *Client) ProcessWebhook(ctx context.Context, request *http.Request) (*internal.Webhook, error)
ProcessWebhook parses the webhook from a repo.
func (*Client) RedeliverWebhook ¶ added in v0.27.0
RedeliverWebhook redelivers webhooks from GitHub.
func (*Client) RepoAccess ¶ added in v0.27.0
RepoAccess captures the user's access level for a repo.
func (*Client) RepoContributor ¶ added in v0.27.0
func (c *Client) RepoContributor(ctx context.Context, owner *api.User, sender, org, repo string) (bool, error)
RepoContributor lists all contributors from a repository and checks if the sender is one of the contributors.
func (*Client) SetSettings ¶ added in v0.27.0
SetSettings sets the api settings type in the Engine.
func (*Client) Status ¶ added in v0.27.0
Status sends the commit status for the given SHA from the GitHub repo.
func (*Client) StepStatus ¶ added in v0.27.0
func (c *Client) StepStatus(ctx context.Context, b *api.Build, s *api.Step, org, name, token string) error
StepStatus sends the commit status for the given SHA to the GitHub repo with the step as the context.
func (*Client) SyncRepoWithInstallation ¶ added in v0.27.0
SyncRepoWithInstallation ensures the repo is synchronized with the scm installation, if it exists.
func (*Client) TeamAccess ¶ added in v0.27.0
TeamAccess captures the user's access level for a team.
func (*Client) ValidateGitHubApp ¶ added in v0.27.0
ValidateGitHubApp ensures the GitHub App configuration is valid.
func (*Client) ValidateOAuthToken ¶ added in v0.27.0
ValidateOAuthToken takes a user oauth integration token and validates that it was created by the Vela OAuth app. In essence, the function expects either a 200 or 404 from the GitHub API and returns error in any other failure case.
type ClientOpt ¶
ClientOpt represents a configuration option to initialize the scm client for GitHub.
func WithAddress ¶
WithAddress sets the GitHub address in the scm client for GitHub.
func WithClientID ¶
WithClientID sets the OAuth client ID in the scm client for GitHub.
func WithClientSecret ¶
WithClientSecret sets the OAuth client secret in the scm client for GitHub.
func WithGitHubAppPermissions ¶ added in v0.26.0
WithGitHubAppPermissions sets the App permissions in the scm client for GitHub.
func WithGithubAppID ¶ added in v0.26.0
WithGithubAppID sets the ID for the GitHub App in the scm client.
func WithGithubPrivateKey ¶ added in v0.26.0
WithGithubPrivateKey sets the private key for the GitHub App in the scm client.
func WithGithubPrivateKeyPath ¶ added in v0.26.0
WithGithubPrivateKeyPath sets the private key path for the GitHub App in the scm client.
func WithOAuthScopes ¶ added in v0.26.0
WithOAuthScopes sets the OAuth scopes in the scm client for GitHub.
func WithOrgRoleMap ¶ added in v0.27.0
WithOrgRoleMap sets the organization role mapping in the scm client for GitHub.
func WithRepoRoleMap ¶ added in v0.27.0
WithRepoRoleMap sets the repository role mapping in the scm client for GitHub.
func WithServerAddress ¶
WithServerAddress sets the Vela server address in the scm client for GitHub.
func WithServerWebhookAddress ¶
WithServerWebhookAddress sets the Vela server webhook address in the scm client for GitHub.
func WithStatusContext ¶
WithStatusContext sets the context for commit statuses in the scm client for GitHub.
func WithTeamRoleMap ¶ added in v0.27.0
WithTeamRoleMap sets the team role mapping in the scm client for GitHub.
func WithTracing ¶ added in v0.25.0
WithTracing sets the shared tracing config in the scm client for GitHub.
func WithWebUIAddress ¶
WithWebUIAddress sets the Vela web UI address in the scm client for GitHub.
type HTTPClient ¶ added in v0.27.0
HTTPClient is a HTTP client which sends a http.Request and returns a http.Response or an error.
type RSASigner ¶ added in v0.26.0
type RSASigner struct {
// contains filtered or unexported fields
}
RSASigner signs JWT tokens using RSA keys.
func NewRSASigner ¶ added in v0.26.0
func NewRSASigner(method *jwt.SigningMethodRSA, key *rsa.PrivateKey) *RSASigner
NewRSASigner creates a new RSASigner with the given RSA key.
type Signer ¶ added in v0.26.0
type Signer interface { // sign the given claims and returns a JWT token string, as specified // by [jwt.Token.SignedString] Sign(claims jwt.Claims) (string, error) }
Signer is a JWT token signer. This is a wrapper around jwt.SigningMethod with predetermined key material.
type Transport ¶ added in v0.26.0
type Transport struct { BaseURL string // BaseURL is the scheme and host for GitHub API, defaults to https://api.github.com Client HTTPClient // Client to use to refresh tokens, defaults to http.Client with provided transport InstallationTokenOptions *github.InstallationTokenOptions // parameters restrict a token's access // contains filtered or unexported fields }
Transport provides a http.RoundTripper by wrapping an existing http.RoundTripper and provides GitHub Apps authentication as an installation.
Client can also be overwritten, and is useful to change to one which provides retry logic if you do experience retryable errors.
func (*Transport) Expiry ¶ added in v0.26.0
Expiry returns a transport token's expiration time and refresh time. There is a small grace period built in where a token will be refreshed before it expires. expiresAt is the actual token expiry, and refreshAt is when a call to Token() will cause it to be refreshed.