github

package
v0.5.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2026 License: MPL-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package github provides github related code

templ: version: v0.3.1001

Index

Constants

View Source
const (
	TokenKindID vcs.KindID    = "github-token"
	AppKindID   vcs.KindID    = "github-app"
	Source      source.Source = "github"
)
View Source
const AppEventsPath = "/webhooks/github-app"

AppEventsPath is the URL path for the endpoint receiving VCS events from the Github App

Variables

View Source
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 DefaultBaseURL added in v0.4.0

func DefaultBaseURL() *internal.WebURL

func HandleEvent

func HandleEvent(r *http.Request, secret string) (*vcs.EventPayload, error)

func Icon added in v0.3.24

func Icon() templ.Component

func NewOAuthClient added in v0.1.14

func RegisterOAuthHandler added in v0.3.24

func RegisterOAuthHandler(
	authenticatorService *authenticator.Service,
	baseURL *internal.WebURL,
	clientID, clientSecret string,
	skipTLSVerification bool,
) error

Types

type App added in v0.1.14

type App struct {
	ID            AppID  `db:"github_app_id"` // github's app id
	Slug          string // github's "slug" name
	WebhookSecret string `db:"webhook_secret"`
	PrivateKey    string `db:"private_key"`

	// Organization is the name of the *github* organization that owns the
	// app. If the app is owned by a user then this is nil.
	Organization *string `db:"organization"`
	GithubURL    *internal.WebURL

	*Client
}

App is a Github App. Includes a client for interacting with Github authenticated as the app.

func (*App) AdvancedURL added in v0.1.14

func (a *App) AdvancedURL() templ.SafeURL

AdvancedURL returns the URL for the "advanced" settings on github

func (*App) DeleteInstallation added in v0.3.24

func (a *App) DeleteInstallation(ctx context.Context, installID int64) error

DeleteInstallation deletes an installation of a github app with the given installation ID.

func (*App) GetInstallation added in v0.3.24

func (a *App) GetInstallation(ctx context.Context, installID int64) (vcs.Installation, error)
func (a *App) InstallationLink() templ.SafeURL

func (*App) ListInstallations added in v0.3.24

func (a *App) ListInstallations(ctx context.Context) ([]vcs.Installation, error)

ListInstallations lists installations of the currently authenticated app.

func (*App) LogValue added in v0.1.14

func (a *App) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (*App) NewInstallURL added in v0.1.14

func (a *App) NewInstallURL(hostname string) string

NewInstallURL returns the GitHub URL for creating a new install of the app.

func (*App) String added in v0.1.14

func (a *App) String() string

func (*App) URL added in v0.1.14

func (a *App) URL(hostname string) string

URL returns the app's URL on GitHub

type AppCredentials added in v0.1.14

type AppCredentials struct {
	// Github app ID
	ID AppID
	// 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 AppEventHandler added in v0.3.24

type AppEventHandler struct {
	logr.Logger
	vcs.Publisher

	VCSService *vcs.Service
	GithubApps *Service
}

func (*AppEventHandler) AddHandlers added in v0.3.24

func (h *AppEventHandler) AddHandlers(r *mux.Router)

func (*AppEventHandler) ServeHTTP added in v0.3.24

func (h *AppEventHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type AppID added in v0.3.17

type AppID int64

func (AppID) String added in v0.3.17

func (id AppID) String() string

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

func (g *Client) CreateWebhook(ctx context.Context, opts vcs.CreateWebhookOptions) (string, error)

CreateWebhook creates a webhook on a github repository.

func (*Client) DeleteWebhook

func (g *Client) DeleteWebhook(ctx context.Context, opts vcs.DeleteWebhookOptions) error

func (*Client) ExchangeCode added in v0.1.14

func (g *Client) ExchangeCode(ctx context.Context, code string) (*github.AppConfig, error)

func (*Client) GetCommit added in v0.1.8

func (g *Client) GetCommit(ctx context.Context, repo vcs.Repo, ref string) (vcs.Commit, error)

func (*Client) GetCurrentUser added in v0.1.8

func (g *Client) GetCurrentUser(ctx context.Context) (authenticator.UserInfo, error)

func (*Client) GetDefaultBranch added in v0.3.24

func (g *Client) GetDefaultBranch(ctx context.Context, identifier string) (string, error)

func (*Client) GetRepoTarball

func (g *Client) GetRepoTarball(ctx context.Context, opts vcs.GetRepoTarballOptions) ([]byte, string, error)

func (*Client) GetWebhook

func (g *Client) GetWebhook(ctx context.Context, opts vcs.GetWebhookOptions) (vcs.Webhook, error)

func (*Client) ListPullRequestFiles added in v0.1.4

func (g *Client) ListPullRequestFiles(ctx context.Context, repo vcs.Repo, pull int) ([]string, error)

func (*Client) ListRepositories

func (g *Client) ListRepositories(ctx context.Context, opts vcs.ListRepositoriesOptions) ([]vcs.Repo, 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) ListTags

func (g *Client) ListTags(ctx context.Context, opts vcs.ListTagsOptions) ([]string, error)

func (*Client) SetStatus

func (g *Client) SetStatus(ctx context.Context, opts vcs.SetStatusOptions) error

func (*Client) UpdateWebhook

func (g *Client) UpdateWebhook(ctx context.Context, id string, opts vcs.UpdateWebhookOptions) error

type ClientOptions added in v0.1.14

type ClientOptions struct {
	// BaseURL is the base URL for github.
	BaseURL             *internal.WebURL
	SkipTLSVerification bool

	// Only specify one of the following
	OAuthToken    *oauth2.Token
	PersonalToken *string
	*AppCredentials
	*InstallCredentials
}

type CreateAppOptions added in v0.1.14

type CreateAppOptions struct {
	BaseURL             *internal.WebURL
	AppID               int64
	WebhookSecret       string
	PrivateKey          string
	Slug                string
	Organization        *string
	SkipTLSVerification bool
}

type GithubService added in v0.5.18

type GithubService = Service

Alias service to permit embedding it with other services in a struct without a name clash.

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 Options added in v0.1.14

type Options struct {
	DB                  *sql.DB
	Logger              logr.Logger
	GithubAPIURL        *internal.WebURL
	SkipTLSVerification bool
	Authorizer          *authz.Authorizer
	VCSService          *vcs.Service
	VCSEventBroker      *vcs.Broker
}

type Service added in v0.1.14

type Service struct {
	logr.Logger
	*authz.Authorizer
	// contains filtered or unexported fields
}

Service is the service for github app management

func NewService added in v0.1.14

func NewService(opts Options) *Service

func (*Service) CreateApp added in v0.2.2

func (a *Service) CreateApp(ctx context.Context, opts CreateAppOptions) (*App, error)

func (*Service) DeleteApp added in v0.2.2

func (a *Service) DeleteApp(ctx context.Context) error

func (*Service) DeleteInstallation added in v0.1.14

func (a *Service) DeleteInstallation(ctx context.Context, installID int64) error

func (*Service) GetApp added in v0.2.2

func (a *Service) GetApp(ctx context.Context) (*App, error)

func (*Service) GetInstallation added in v0.3.24

func (a *Service) GetInstallation(ctx context.Context, installID int64) (vcs.Installation, error)

func (*Service) ListInstallations added in v0.1.14

func (a *Service) ListInstallations(ctx context.Context) ([]vcs.Installation, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL