github

package
v0.0.0-...-8864ed4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockGitHubMux

func NewMockGitHubMux(cfg MockConfig) *http.ServeMux

NewMockGitHubMux returns an *http.ServeMux pre-wired with canned GitHub API responses for cfg. Use this when you want to attach the handlers to your own net/http server (e.g. a standalone long-running process) rather than an httptest.Server.

func NewMockGitHubServer

func NewMockGitHubServer(t MockTestHelper, cfg MockConfig) (*httptest.Server, *http.ServeMux)

NewMockGitHubServer starts an httptest.Server wired with canned GitHub API responses derived from cfg. It returns the server and its mux so individual tests can register additional more-specific patterns (note: http.ServeMux panics on duplicate pattern registration, so existing handlers cannot be replaced — only extended with more-specific paths).

To redirect go-github requests at this server, construct the client with WithEnterpriseURLs(srv.URL+"/api/v3/", srv.URL+"/").

Types

type CollobaratorWithPermission

type CollobaratorWithPermission struct {
	Collobarator string
	Permission   string
}

type DefaultOrganizationProvider

type DefaultOrganizationProvider struct {
	// contains filtered or unexported fields
}

func (*DefaultOrganizationProvider) ChangeToMember

func (o *DefaultOrganizationProvider) ChangeToMember(ctx context.Context, user string) error

func (*DefaultOrganizationProvider) ChangeToOwner

func (o *DefaultOrganizationProvider) ChangeToOwner(ctx context.Context, user string) error

func (*DefaultOrganizationProvider) ExtendedMembers

func (o *DefaultOrganizationProvider) ExtendedMembers(ctx context.Context) ([]*github.User, []*github.User, error)

func (*DefaultOrganizationProvider) Members

func (*DefaultOrganizationProvider) Owners

func (*DefaultOrganizationProvider) OwnersExtended

func (o *DefaultOrganizationProvider) OwnersExtended(ctx context.Context) ([]GithubMember, error)

func (*DefaultOrganizationProvider) RemoveFromOrg

func (o *DefaultOrganizationProvider) RemoveFromOrg(ctx context.Context, user string) error

type DefaultRepositoryProvider

type DefaultRepositoryProvider struct {
	// contains filtered or unexported fields
}

func (*DefaultRepositoryProvider) ExtendedList

func (*DefaultRepositoryProvider) IsPrivate

func (t *DefaultRepositoryProvider) IsPrivate(ctx context.Context, repo string) (bool, error)

func (*DefaultRepositoryProvider) List

func (*DefaultRepositoryProvider) RepositoryCollobaratorRemove

func (t *DefaultRepositoryProvider) RepositoryCollobaratorRemove(ctx context.Context, repo string, user string) (bool, error)

func (*DefaultRepositoryProvider) RepositoryCollobarators

func (t *DefaultRepositoryProvider) RepositoryCollobarators(ctx context.Context, repo string) ([]string, error)

func (*DefaultRepositoryProvider) RepositoryTeamAdd

func (t *DefaultRepositoryProvider) RepositoryTeamAdd(ctx context.Context, repo, team string, permission repoguardsapv1.GithubTeamPermission) error

func (*DefaultRepositoryProvider) RepositoryTeamRemove

func (t *DefaultRepositoryProvider) RepositoryTeamRemove(ctx context.Context, repo, team string) error

func (*DefaultRepositoryProvider) RepositoryTeams

type DefaultTeamsProvider

type DefaultTeamsProvider struct {
	// contains filtered or unexported fields
}

func (DefaultTeamsProvider) AddTeam

func (t DefaultTeamsProvider) AddTeam(ctx context.Context, team string) error

func (DefaultTeamsProvider) AddUser

func (t DefaultTeamsProvider) AddUser(ctx context.Context, team, user string) (bool, error)

func (*DefaultTeamsProvider) List

func (t *DefaultTeamsProvider) List(ctx context.Context) ([]string, error)

func (DefaultTeamsProvider) Members

func (t DefaultTeamsProvider) Members(ctx context.Context, team string) ([]string, error)

func (DefaultTeamsProvider) MembersExtended

func (t DefaultTeamsProvider) MembersExtended(ctx context.Context, team string) ([]GithubMember, error)

func (DefaultTeamsProvider) RemoveTeam

func (t DefaultTeamsProvider) RemoveTeam(ctx context.Context, team string) error

func (DefaultTeamsProvider) RemoveUser

func (t DefaultTeamsProvider) RemoveUser(ctx context.Context, team, user string) error

type DefaultUsersProvider

type DefaultUsersProvider struct {
	// contains filtered or unexported fields
}

func (*DefaultUsersProvider) GithubIDByUsername

func (u *DefaultUsersProvider) GithubIDByUsername(username string) (string, bool, error)

GithubIDByUsername returns the GitHub user ID string for a given login. It returns (id, found, error).

func (*DefaultUsersProvider) GithubUsernameByID

func (u *DefaultUsersProvider) GithubUsernameByID(id string) (string, bool, error)

GithubUsernameByID returns the GitHub login for a given GitHub user ID. It returns (username, found, error).

func (*DefaultUsersProvider) HasVerifiedEmailDomainForGithubUID

func (u *DefaultUsersProvider) HasVerifiedEmailDomainForGithubUID(ctx context.Context, org string, uid string, domain string) (bool, error)

HasVerifiedEmailDomainForGithubUID implements UsersProvider.HasVerifiedEmailDomainForGithubUID. It uses the GitHub GraphQL API to query User.organizationVerifiedDomainEmails and checks whether any email has the requested domain. This requires appropriate permissions and works with an installation-scoped client when the app is installed in an organization where the user is a member.

func (*DefaultUsersProvider) IsMemberOfOrg

func (u *DefaultUsersProvider) IsMemberOfOrg(ctx context.Context, org string, uid string) (bool, error)

type GithubMember

type GithubMember struct {
	Login string
	UID   int64
}

type MockConfig

type MockConfig struct {
	Org     string
	Members []MockUser // all org members (role=all)
	Owners  []MockUser // org owners (role=admin)
	Teams   []MockTeam
	Repos   []MockRepo
}

MockConfig defines the canned data served by the mock GitHub HTTP server.

type MockRepo

type MockRepo struct {
	Name    string
	Private bool
	Teams   []MockTeamWithPermission
}

MockRepo represents a GitHub repository for mock purposes.

type MockTeam

type MockTeam struct {
	ID   int64
	Name string
	Slug string
}

MockTeam represents a GitHub team for mock purposes.

type MockTeamWithPermission

type MockTeamWithPermission struct {
	Slug       string
	ID         int64
	Permission string
}

MockTeamWithPermission pairs a team slug with a permission for a repo.

type MockTestHelper

type MockTestHelper interface {
	Cleanup(func())
}

MockTestHelper is a minimal interface satisfied by both *testing.T and Ginkgo's GinkgoT(), allowing NewMockGitHubServer to be called from either standard Go tests or Ginkgo test suites.

type MockUser

type MockUser struct {
	Login string
	ID    int64
}

MockUser represents a GitHub user for mock purposes.

type OrganizationProvider

type OrganizationProvider interface {
	Owners(ctx context.Context) ([]string, error)
	OwnersExtended(ctx context.Context) ([]GithubMember, error)
	Members(ctx context.Context) ([]string, error)
	ExtendedMembers(ctx context.Context) ([]*github.User, []*github.User, error)
	ChangeToOwner(ctx context.Context, user string) error
	ChangeToMember(ctx context.Context, user string) error
	RemoveFromOrg(ctx context.Context, user string) error
}

func NewOrganizationProvider

func NewOrganizationProvider(cc githubapp.ClientCreator, organization string, installationID int64) (OrganizationProvider, error)

installationID can be found at Organizations - Settings - Installed Github Apps and check the URL

type RepositoryProvider

type RepositoryProvider interface {
	List(ctx context.Context) ([]string, []string, error)
	ExtendedList(ctx context.Context) ([]repoguardsapv1.GithubRepository, []repoguardsapv1.GithubRepository, error)
	RepositoryTeams(ctx context.Context, repo string) ([]repoguardsapv1.GithubTeamWithPermission, error)
	RepositoryTeamAdd(ctx context.Context, repo, team string, permission repoguardsapv1.GithubTeamPermission) error
	RepositoryTeamRemove(ctx context.Context, repo, team string) error
	RepositoryCollobarators(ctx context.Context, repo string) ([]string, error)
	RepositoryCollobaratorRemove(ctx context.Context, repo string, user string) (bool, error)
	IsPrivate(ctx context.Context, repo string) (bool, error)
}

func NewRepositoryProvider

func NewRepositoryProvider(cc githubapp.ClientCreator, organization string, installationID int64) (RepositoryProvider, error)

installationID can be found at Organizations - Settings - Installed Github Apps and check the URL

type TeamsProvider

type TeamsProvider interface {
	List(ctx context.Context) ([]string, error)
	Members(ctx context.Context, team string) ([]string, error)
	MembersExtended(ctx context.Context, team string) ([]GithubMember, error)
	AddTeam(ctx context.Context, team string) error
	RemoveTeam(ctx context.Context, team string) error
	AddUser(ctx context.Context, team, user string) (bool, error)
	RemoveUser(ctx context.Context, team, user string) error
}

func NewTeamsProvider

func NewTeamsProvider(cc githubapp.ClientCreator, organization string, installationID int64) (TeamsProvider, error)

installationID can be found at Organizations - Settings - Installed Github Apps and check the URL

type UsersProvider

type UsersProvider interface {
	GithubUsernameByID(id string) (string, bool, error)
	GithubIDByUsername(username string) (string, bool, error)
	// IsMemberOfOrg checks whether the GitHub user with the given UID is a member of the organization.
	IsMemberOfOrg(ctx context.Context, org string, uid string) (bool, error)
	// HasVerifiedEmailDomainForGithubUID checks whether the GitHub user with the given UID
	// has an email address visible to the given organization that matches the provided domain.
	// This uses the organization members endpoint which exposes members' verified emails to
	// organization owners, per GitHub changelog 2019-03-25.
	HasVerifiedEmailDomainForGithubUID(ctx context.Context, org string, uid string, domain string) (bool, error)
}

func NewUsersProvider

func NewUsersProvider(cc githubapp.ClientCreator, installationID int64) (UsersProvider, error)

Jump to

Keyboard shortcuts

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