Documentation ¶
Overview ¶
Package github provides github related code
Index ¶
- Constants
- Variables
- func HandleEvent(r *http.Request, secret string) (*vcs.EventPayload, error)
- func NewOAuthClient(cfg authenticator.OAuthConfig, token *oauth2.Token) (authenticator.IdentityProviderClient, error)
- func NewTokenClient(opts vcs.NewTokenClientOptions) (vcs.Client, error)
- func SendEventRequest(t *testing.T, event GithubEvent, url, secret string, payload []byte)
- type App
- type AppCredentials
- type AppInstallRow
- type AppRow
- type Client
- func (g *Client) CreateWebhook(ctx context.Context, opts vcs.CreateWebhookOptions) (string, error)
- func (g *Client) DeleteInstallation(ctx context.Context, installID int64) error
- func (g *Client) DeleteWebhook(ctx context.Context, opts vcs.DeleteWebhookOptions) error
- func (g *Client) ExchangeCode(ctx context.Context, code string) (*github.AppConfig, error)
- func (g *Client) GetCommit(ctx context.Context, repo, ref string) (vcs.Commit, error)
- func (g *Client) GetCurrentUser(ctx context.Context) (string, error)
- func (g *Client) GetInstallation(ctx context.Context, installID int64) (*github.Installation, error)
- func (g *Client) GetRepoTarball(ctx context.Context, opts vcs.GetRepoTarballOptions) ([]byte, string, error)
- func (g *Client) GetRepository(ctx context.Context, identifier string) (vcs.Repository, error)
- func (g *Client) GetWebhook(ctx context.Context, opts vcs.GetWebhookOptions) (vcs.Webhook, error)
- func (g *Client) ListInstallations(ctx context.Context) ([]*github.Installation, error)
- func (g *Client) ListPullRequestFiles(ctx context.Context, repo string, pull int) ([]string, error)
- func (g *Client) ListRepositories(ctx context.Context, opts vcs.ListRepositoriesOptions) ([]string, error)
- func (g *Client) ListTags(ctx context.Context, opts vcs.ListTagsOptions) ([]string, error)
- func (g *Client) SetStatus(ctx context.Context, opts vcs.SetStatusOptions) error
- func (g *Client) UpdateWebhook(ctx context.Context, id string, opts vcs.UpdateWebhookOptions) error
- type ClientOptions
- type CreateAppOptions
- type GithubEvent
- type InstallCredentials
- type Installation
- type Options
- type Service
- func (a *Service) AddHandlers(r *mux.Router)
- func (a *Service) CreateApp(ctx context.Context, opts CreateAppOptions) (*App, error)
- func (a *Service) DeleteApp(ctx context.Context) error
- func (a *Service) DeleteInstallation(ctx context.Context, installID int64) error
- func (a *Service) GetApp(ctx context.Context) (*App, error)
- func (a *Service) GetInstallCredentials(ctx context.Context, installID int64) (*InstallCredentials, error)
- func (a *Service) ListInstallations(ctx context.Context) ([]*Installation, error)
- type TestServer
- type TestServerOption
- func WithArchive(tarball []byte) TestServerOption
- func WithCommit(commit string) TestServerOption
- func WithDefaultBranch(branch string) TestServerOption
- func WithHandler(path string, h http.HandlerFunc) TestServerOption
- func WithPullRequest(pullNumber string, changedPaths ...string) TestServerOption
- func WithRefs(refs ...string) TestServerOption
- func WithRepo(repo string) TestServerOption
- func WithUser(username *string) TestServerOption
Constants ¶
const ( PushEvent GithubEvent = "push" PullRequest GithubEvent = "pull_request" WebhookCreated webhookAction = iota WebhookUpdated WebhookDeleted )
const ( // GithubPath is the URL path for the endpoint receiving VCS events from the // Github App AppEventsPath = "/webhooks/github-app" )
const (
DefaultHostname = "github.com"
)
Variables ¶
var ( OAuthEndpoint = oauth2github.Endpoint // TODO: don't think read:org scope is necessary any more...not since OTF // stopped sync'ing org and team memberships from github. OAuthScopes = []string{"user:email", "read:org"} )
Functions ¶
func HandleEvent ¶
func NewOAuthClient ¶ added in v0.1.14
func NewOAuthClient(cfg authenticator.OAuthConfig, token *oauth2.Token) (authenticator.IdentityProviderClient, error)
func NewTokenClient ¶ added in v0.1.14
func NewTokenClient(opts vcs.NewTokenClientOptions) (vcs.Client, error)
func SendEventRequest ¶ added in v0.1.14
func SendEventRequest(t *testing.T, event GithubEvent, url, secret string, payload []byte)
SendEventRequest sends a GitHub event via a http request to the url, signed with the secret,
Types ¶
type App ¶ added in v0.1.14
type App struct { ID int64 // github's app id Slug string // github's "slug" name WebhookSecret string PrivateKey string // Organization is the name of the organization that owns the app. If // the app is owned by a user then this is nil. Organization *string }
func (*App) AdvancedURL ¶ added in v0.1.14
AdvancedURL returns the URL for the "advanced" settings on github
func (*App) NewInstallURL ¶ added in v0.1.14
NewInstallURL returns the GitHub URL for creating a new install of the app.
type AppCredentials ¶ added in v0.1.14
type AppCredentials struct { // Github app ID ID int64 // Private key in PEM format PrivateKey string }
Credentials for authenticating as an app: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/about-authentication-with-a-github-app#authentication-as-a-github-app
type AppInstallRow ¶ added in v0.3.0
type AppInstallRow struct { GithubAppID pgtype.Int8 `json:"github_app_id"` InstallID pgtype.Int8 `json:"install_id"` Username pgtype.Text `json:"username"` Organization pgtype.Text `json:"organization"` VCSProviderID pgtype.Text `json:"vcs_provider_id"` }
AppInstallRow is a database row for a github app install
type AppRow ¶ added in v0.3.0
type AppRow struct { GithubAppID pgtype.Int8 `json:"github_app_id"` WebhookSecret pgtype.Text `json:"webhook_secret"` PrivateKey pgtype.Text `json:"private_key"` Slug pgtype.Text `json:"slug"` Organization pgtype.Text `json:"organization"` }
AppRow represents a database AppRow for a github app
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapper around the upstream go-github client
func NewClient ¶
func NewClient(cfg ClientOptions) (*Client, error)
func (*Client) CreateWebhook ¶
CreateWebhook creates a webhook on a github repository.
func (*Client) DeleteInstallation ¶ added in v0.1.14
DeleteInstallation deletes an installation of a github app with the given installation ID.
func (*Client) DeleteWebhook ¶
func (*Client) ExchangeCode ¶ added in v0.1.14
func (*Client) GetCurrentUser ¶ added in v0.1.8
func (*Client) GetInstallation ¶ added in v0.1.14
func (*Client) GetRepoTarball ¶
func (*Client) GetRepository ¶
func (*Client) GetWebhook ¶
func (*Client) ListInstallations ¶ added in v0.1.14
ListInstallations lists installations of the currently authenticated app.
func (*Client) ListPullRequestFiles ¶ added in v0.1.4
func (*Client) ListRepositories ¶
func (g *Client) ListRepositories(ctx context.Context, opts vcs.ListRepositoriesOptions) ([]string, error)
ListRepositories has different behaviour depending on the authentication: (a) if authenticated as an app installation then repositories accessible to the installation are listed; *all* repos are listed, in order of last pushed to. (b) if authenticated using a personal access token then repositories belonging to the user are listed; only the first page of repos is listed, those that have most recently been pushed to.
func (*Client) UpdateWebhook ¶
type ClientOptions ¶ added in v0.1.14
type ClientOptions struct { Hostname string SkipTLSVerification bool // Only specify one of the following OAuthToken *oauth2.Token PersonalToken *string *AppCredentials *InstallCredentials }
type CreateAppOptions ¶ added in v0.1.14
type InstallCredentials ¶ added in v0.1.14
type InstallCredentials struct { // Github installation ID ID int64 // Github username if installed in a user account; mutually exclusive // with Organization User *string // Github organization if installed in an organization; mutually // exclusive with User Organization *string AppCredentials }
Credentials for authenticating as an app installation: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/about-authentication-with-a-github-app#authentication-as-an-app-installation
type Installation ¶ added in v0.1.14
type Installation struct {
*github.Installation
}
func (*Installation) String ¶ added in v0.1.14
func (i *Installation) String() string
type Service ¶ added in v0.1.14
Service is the service for github app management
func NewService ¶ added in v0.1.14
func (*Service) AddHandlers ¶ added in v0.2.2
func (*Service) DeleteInstallation ¶ added in v0.1.14
func (*Service) GetInstallCredentials ¶ added in v0.1.14
func (*Service) ListInstallations ¶ added in v0.1.14
func (a *Service) ListInstallations(ctx context.Context) ([]*Installation, error)
type TestServer ¶
type TestServer struct { // webhook created/updated/deleted events channel WebhookEvents chan webhookEvent *httptest.Server // contains filtered or unexported fields }
func NewTestServer ¶
func NewTestServer(t *testing.T, opts ...TestServerOption) (*TestServer, *url.URL)
func (*TestServer) GetStatus ¶
func (s *TestServer) GetStatus(t *testing.T, ctx context.Context) *github.StatusEvent
GetStatus retrieves a commit status event off the queue, timing out after 10 seconds if nothing is on the queue.
func (*TestServer) HasWebhook ¶
func (s *TestServer) HasWebhook() bool
func (*TestServer) SendEvent ¶
func (s *TestServer) SendEvent(t *testing.T, event GithubEvent, payload []byte)
SendEvent sends an event to the registered webhook.
type TestServerOption ¶
type TestServerOption func(*TestServer)
func WithArchive ¶
func WithArchive(tarball []byte) TestServerOption
func WithCommit ¶ added in v0.1.8
func WithCommit(commit string) TestServerOption
func WithDefaultBranch ¶ added in v0.1.8
func WithDefaultBranch(branch string) TestServerOption
func WithHandler ¶ added in v0.1.14
func WithHandler(path string, h http.HandlerFunc) TestServerOption
func WithPullRequest ¶ added in v0.1.4
func WithPullRequest(pullNumber string, changedPaths ...string) TestServerOption
func WithRefs ¶
func WithRefs(refs ...string) TestServerOption
func WithRepo ¶
func WithRepo(repo string) TestServerOption
func WithUser ¶
func WithUser(username *string) TestServerOption