Documentation ¶
Overview ¶
Package branch_protection is a generated GoMock package.
Index ¶
- Constants
- Variables
- func CleanGithubRepoName(githubRepoName string) string
- func EnableBranchProtectionForPattern(ctx context.Context, repositoryOwner, repositoryName string, ...) error
- func IsEnforceAdminEnabled(protection *BranchProtectionRule) bool
- type BranchProtectionRepository
- func (bp *BranchProtectionRepository) EnableBranchProtection(ctx context.Context, owner, repoName, branchName string, enforceAdmin bool, ...) error
- func (bp *BranchProtectionRepository) GetDefaultBranchForRepo(ctx context.Context, owner, repoName string) (string, error)
- func (bp *BranchProtectionRepository) GetOwnerName(ctx context.Context, orgName, repoName string) (string, error)
- func (bp *BranchProtectionRepository) GetProtectedBranch(ctx context.Context, owner, repoName, protectedBranchName string) (*BranchProtectionRule, error)
- type BranchProtectionRepositoryOption
- type BranchProtectionRepositoryV4
- func (r *BranchProtectionRepositoryV4) CreateBranchProtection(ctx context.Context, input *githubv4.CreateBranchProtectionRuleInput) (*CreateRepoBranchProtectionMutation, error)
- func (r *BranchProtectionRepositoryV4) GetRepositoryBranchProtections(ctx context.Context, repositoryOwner, repositoryName string) (*RepoBranchProtectionQueryResult, error)
- func (r *BranchProtectionRepositoryV4) GetRepositoryIDFromName(ctx context.Context, repositoryOwner, repositoryName string) (string, error)
- func (r *BranchProtectionRepositoryV4) UpdateBranchProtection(ctx context.Context, input *githubv4.UpdateBranchProtectionRuleInput) (*UpdateRepoBranchProtectionMutation, error)
- type BranchProtectionRule
- type BranchProtectionRuleQueryParam
- type BranchProtectionRuleRepositoryParam
- type CombinedRepository
- type CreateRepoBranchProtectionMutation
- type MockCombinedRepository
- func (m *MockCombinedRepository) CreateBranchProtection(arg0 context.Context, arg1 *githubv4.CreateBranchProtectionRuleInput) (*CreateRepoBranchProtectionMutation, error)
- func (m *MockCombinedRepository) EXPECT() *MockCombinedRepositoryMockRecorder
- func (m *MockCombinedRepository) Get(arg0 context.Context, arg1, arg2 string) (*github.Repository, *github.Response, error)
- func (m *MockCombinedRepository) GetRepositoryBranchProtections(arg0 context.Context, arg1, arg2 string) (*RepoBranchProtectionQueryResult, error)
- func (m *MockCombinedRepository) GetRepositoryIDFromName(arg0 context.Context, arg1, arg2 string) (string, error)
- func (m *MockCombinedRepository) ListByOrg(arg0 context.Context, arg1 string, arg2 *github.RepositoryListByOrgOptions) ([]*github.Repository, *github.Response, error)
- func (m *MockCombinedRepository) UpdateBranchProtection(arg0 context.Context, arg1 *githubv4.UpdateBranchProtectionRuleInput) (*UpdateRepoBranchProtectionMutation, error)
- type MockCombinedRepositoryMockRecorder
- func (mr *MockCombinedRepositoryMockRecorder) CreateBranchProtection(arg0, arg1 interface{}) *gomock.Call
- func (mr *MockCombinedRepositoryMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call
- func (mr *MockCombinedRepositoryMockRecorder) GetRepositoryBranchProtections(arg0, arg1, arg2 interface{}) *gomock.Call
- func (mr *MockCombinedRepositoryMockRecorder) GetRepositoryIDFromName(arg0, arg1, arg2 interface{}) *gomock.Call
- func (mr *MockCombinedRepositoryMockRecorder) ListByOrg(arg0, arg1, arg2 interface{}) *gomock.Call
- func (mr *MockCombinedRepositoryMockRecorder) UpdateBranchProtection(arg0, arg1 interface{}) *gomock.Call
- type RepoBranchProtectionQueryResult
- type UpdateRepoBranchProtectionMutation
- type V3Repositories
- type V4BranchProtectionRepository
Constants ¶
const (
// DefaultBranchName is the default branch we'll be working with if not specified
DefaultBranchName = "main"
)
Variables ¶
var ( // ErrBranchNotProtected indicates the situation where the branch is not enabled for protection on github side ErrBranchNotProtected = errors.New("not protected") )
Functions ¶
func CleanGithubRepoName ¶
CleanGithubRepoName removes the orgname if existing in the string
func EnableBranchProtectionForPattern ¶
func EnableBranchProtectionForPattern(ctx context.Context, repositoryOwner, repositoryName string, input *BranchProtectionRule) error
EnableBranchProtectionForPattern enables branch protection for the given branch protection input
func IsEnforceAdminEnabled ¶
func IsEnforceAdminEnabled(protection *BranchProtectionRule) bool
IsEnforceAdminEnabled checks if enforce admin option is enabled for the branch protection
Types ¶
type BranchProtectionRepository ¶
type BranchProtectionRepository struct {
// contains filtered or unexported fields
}
BranchProtectionRepository contains helper methods interacting with github api related to branch protection
func NewBranchProtectionRepository ¶
func NewBranchProtectionRepository(installationID int64, opts ...BranchProtectionRepositoryOption) (*BranchProtectionRepository, error)
NewBranchProtectionRepository creates a new BranchProtectionRepository
func (*BranchProtectionRepository) EnableBranchProtection ¶
func (bp *BranchProtectionRepository) EnableBranchProtection(ctx context.Context, owner, repoName, branchName string, enforceAdmin bool, enableStatusChecks, disableStatusChecks []string) error
EnableBranchProtection enables branch protection if not enabled and makes sure passed arguments such as enforceAdmin statusChecks are applied. The operation makes sure it doesn't override the existing checks.
func (*BranchProtectionRepository) GetDefaultBranchForRepo ¶
func (bp *BranchProtectionRepository) GetDefaultBranchForRepo(ctx context.Context, owner, repoName string) (string, error)
GetDefaultBranchForRepo helps with pulling the default branch for the given repo
func (*BranchProtectionRepository) GetOwnerName ¶
func (bp *BranchProtectionRepository) GetOwnerName(ctx context.Context, orgName, repoName string) (string, error)
GetOwnerName retrieves the owner name of the given org and repo name
func (*BranchProtectionRepository) GetProtectedBranch ¶
func (bp *BranchProtectionRepository) GetProtectedBranch(ctx context.Context, owner, repoName, protectedBranchName string) (*BranchProtectionRule, error)
GetProtectedBranch fetches the protected branch details
type BranchProtectionRepositoryOption ¶
type BranchProtectionRepositoryOption func(config *branchProtectionRepositoryConfig)
BranchProtectionRepositoryOption enables optional parameters to BranchProtectionRepository
func EnableBlockingLimiter ¶
func EnableBlockingLimiter() BranchProtectionRepositoryOption
EnableBlockingLimiter enables the blocking limiter
func EnableNonBlockingLimiter ¶
func EnableNonBlockingLimiter() BranchProtectionRepositoryOption
EnableNonBlockingLimiter enables the non-blocking limiter
type BranchProtectionRepositoryV4 ¶
type BranchProtectionRepositoryV4 struct {
// contains filtered or unexported fields
}
BranchProtectionRepositoryV4 wraps a v4 github client
func NewBranchProtectionRepositoryV4 ¶
func NewBranchProtectionRepositoryV4(installationID int64) (*BranchProtectionRepositoryV4, error)
NewBranchProtectionRepositoryV4 creates a new BranchProtectionRepositoryV4
func (*BranchProtectionRepositoryV4) CreateBranchProtection ¶
func (r *BranchProtectionRepositoryV4) CreateBranchProtection(ctx context.Context, input *githubv4.CreateBranchProtectionRuleInput) (*CreateRepoBranchProtectionMutation, error)
CreateBranchProtection creates the repository branch protections for the specified repository
func (*BranchProtectionRepositoryV4) GetRepositoryBranchProtections ¶
func (r *BranchProtectionRepositoryV4) GetRepositoryBranchProtections(ctx context.Context, repositoryOwner, repositoryName string) (*RepoBranchProtectionQueryResult, error)
GetRepositoryBranchProtections returns the repository branch protections for the specified repository
func (*BranchProtectionRepositoryV4) GetRepositoryIDFromName ¶
func (r *BranchProtectionRepositoryV4) GetRepositoryIDFromName(ctx context.Context, repositoryOwner, repositoryName string) (string, error)
GetRepositoryIDFromName when provided the organization and repository name, returns the repository ID
func (*BranchProtectionRepositoryV4) UpdateBranchProtection ¶
func (r *BranchProtectionRepositoryV4) UpdateBranchProtection(ctx context.Context, input *githubv4.UpdateBranchProtectionRuleInput) (*UpdateRepoBranchProtectionMutation, error)
UpdateBranchProtection updates the repository branch protections for the specified repository
type BranchProtectionRule ¶
type BranchProtectionRule struct { ID string Pattern string RequiredStatusCheckContexts []string RequiresStatusChecks bool IsAdminEnforced bool AllowsDeletions bool AllowsForcePushes bool }
BranchProtectionRule is the data structure that's used to reflect the remote github branch protection rule
type BranchProtectionRuleQueryParam ¶
type BranchProtectionRuleQueryParam struct { TotalCount int Nodes []BranchProtectionRule }
BranchProtectionRuleQueryParam is part of RepoBranchProtectionQueryResult extracted here so can easily be initialized
type BranchProtectionRuleRepositoryParam ¶
type BranchProtectionRuleRepositoryParam struct { Name string ID string BranchProtectionRules BranchProtectionRuleQueryParam `graphql:"branchProtectionRules(first:10)"` }
BranchProtectionRuleRepositoryParam is part of RepoBranchProtectionQueryResult extracted here so can easily be initialized
type CombinedRepository ¶
type CombinedRepository interface { V3Repositories V4BranchProtectionRepository }
CombinedRepository is combination of V3Repositories and V4BranchProtectionRepository
func NewBlockLimiterRepositories ¶
func NewBlockLimiterRepositories(repo CombinedRepository) CombinedRepository
NewBlockLimiterRepositories returns a new instance of V3Repositories interface with blocking rate limiting where when the limit is reached the next call blocks till the bucket is ready again
func NewNonBlockLimiterRepositories ¶
func NewNonBlockLimiterRepositories(repo CombinedRepository) CombinedRepository
NewNonBlockLimiterRepositories returns a new instance of V3Repositories interface with non blocking rate limiting
type CreateRepoBranchProtectionMutation ¶
type CreateRepoBranchProtectionMutation struct { CreateBranchProtectionRule struct { BranchProtectionRule struct { Repository struct { Name string } Pattern string IsAdminEnforced bool RequiresStatusChecks bool AllowsDeletions bool AllowsForcePushes bool } } `graphql:"createBranchProtectionRule(input: $input)"` }
CreateRepoBranchProtectionMutation adds a new branch protection rule
type MockCombinedRepository ¶
type MockCombinedRepository struct {
// contains filtered or unexported fields
}
MockCombinedRepository is a mock of CombinedRepository interface
func NewMockCombinedRepository ¶
func NewMockCombinedRepository(ctrl *gomock.Controller) *MockCombinedRepository
NewMockCombinedRepository creates a new mock instance
func (*MockCombinedRepository) CreateBranchProtection ¶
func (m *MockCombinedRepository) CreateBranchProtection(arg0 context.Context, arg1 *githubv4.CreateBranchProtectionRuleInput) (*CreateRepoBranchProtectionMutation, error)
CreateBranchProtection mocks base method
func (*MockCombinedRepository) EXPECT ¶
func (m *MockCombinedRepository) EXPECT() *MockCombinedRepositoryMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockCombinedRepository) Get ¶
func (m *MockCombinedRepository) Get(arg0 context.Context, arg1, arg2 string) (*github.Repository, *github.Response, error)
Get mocks base method
func (*MockCombinedRepository) GetRepositoryBranchProtections ¶
func (m *MockCombinedRepository) GetRepositoryBranchProtections(arg0 context.Context, arg1, arg2 string) (*RepoBranchProtectionQueryResult, error)
GetRepositoryBranchProtections mocks base method
func (*MockCombinedRepository) GetRepositoryIDFromName ¶
func (m *MockCombinedRepository) GetRepositoryIDFromName(arg0 context.Context, arg1, arg2 string) (string, error)
GetRepositoryIDFromName mocks base method
func (*MockCombinedRepository) ListByOrg ¶
func (m *MockCombinedRepository) ListByOrg(arg0 context.Context, arg1 string, arg2 *github.RepositoryListByOrgOptions) ([]*github.Repository, *github.Response, error)
ListByOrg mocks base method
func (*MockCombinedRepository) UpdateBranchProtection ¶
func (m *MockCombinedRepository) UpdateBranchProtection(arg0 context.Context, arg1 *githubv4.UpdateBranchProtectionRuleInput) (*UpdateRepoBranchProtectionMutation, error)
UpdateBranchProtection mocks base method
type MockCombinedRepositoryMockRecorder ¶
type MockCombinedRepositoryMockRecorder struct {
// contains filtered or unexported fields
}
MockCombinedRepositoryMockRecorder is the mock recorder for MockCombinedRepository
func (*MockCombinedRepositoryMockRecorder) CreateBranchProtection ¶
func (mr *MockCombinedRepositoryMockRecorder) CreateBranchProtection(arg0, arg1 interface{}) *gomock.Call
CreateBranchProtection indicates an expected call of CreateBranchProtection
func (*MockCombinedRepositoryMockRecorder) Get ¶
func (mr *MockCombinedRepositoryMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call
Get indicates an expected call of Get
func (*MockCombinedRepositoryMockRecorder) GetRepositoryBranchProtections ¶
func (mr *MockCombinedRepositoryMockRecorder) GetRepositoryBranchProtections(arg0, arg1, arg2 interface{}) *gomock.Call
GetRepositoryBranchProtections indicates an expected call of GetRepositoryBranchProtections
func (*MockCombinedRepositoryMockRecorder) GetRepositoryIDFromName ¶
func (mr *MockCombinedRepositoryMockRecorder) GetRepositoryIDFromName(arg0, arg1, arg2 interface{}) *gomock.Call
GetRepositoryIDFromName indicates an expected call of GetRepositoryIDFromName
func (*MockCombinedRepositoryMockRecorder) ListByOrg ¶
func (mr *MockCombinedRepositoryMockRecorder) ListByOrg(arg0, arg1, arg2 interface{}) *gomock.Call
ListByOrg indicates an expected call of ListByOrg
func (*MockCombinedRepositoryMockRecorder) UpdateBranchProtection ¶
func (mr *MockCombinedRepositoryMockRecorder) UpdateBranchProtection(arg0, arg1 interface{}) *gomock.Call
UpdateBranchProtection indicates an expected call of UpdateBranchProtection
type RepoBranchProtectionQueryResult ¶
type RepoBranchProtectionQueryResult struct { RepositoryOwner struct { Repository BranchProtectionRuleRepositoryParam `graphql:"repository(name: $name)"` } `graphql:"repositoryOwner(login: $login)"` }
RepoBranchProtectionQueryResult is the query which queries for given owner and repository name
type UpdateRepoBranchProtectionMutation ¶
type UpdateRepoBranchProtectionMutation struct { UpdateBranchProtectionRule struct { BranchProtectionRule struct { Repository struct { Name string } Pattern string IsAdminEnforced bool RequiresStatusChecks bool AllowsDeletions bool AllowsForcePushes bool } } `graphql:"updateBranchProtectionRule(input: $input)"` }
UpdateRepoBranchProtectionMutation updates existing branch protection rule
type V3Repositories ¶
type V3Repositories interface { ListByOrg(ctx context.Context, org string, opt *github.RepositoryListByOrgOptions) ([]*github.Repository, *github.Response, error) Get(ctx context.Context, owner, repo string) (*github.Repository, *github.Response, error) }
V3Repositories is part of the interface working with github repositories, it's inside of the github client It's extracted here as interface so we can mock that functionality in the tests.
type V4BranchProtectionRepository ¶
type V4BranchProtectionRepository interface { GetRepositoryBranchProtections(ctx context.Context, repositoryOwner, repositoryName string) (*RepoBranchProtectionQueryResult, error) CreateBranchProtection(ctx context.Context, input *githubv4.CreateBranchProtectionRuleInput) (*CreateRepoBranchProtectionMutation, error) UpdateBranchProtection(ctx context.Context, input *githubv4.UpdateBranchProtectionRuleInput) (*UpdateRepoBranchProtectionMutation, error) GetRepositoryIDFromName(ctx context.Context, repositoryOwner, repositoryName string) (string, error) }
V4BranchProtectionRepository has v4 (graphQL) branch protection functionality