Documentation
¶
Overview ¶
Package client provides a GitHub API client with App authentication. Handles JWT generation, installation token management, PR compliance checking, and team membership synchronization.
Index ¶
- type Client
- func (c *Client) CheckPRCompliance(ctx context.Context, owner, repo string, prNumber int) (*PRComplianceResult, error)
- func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)
- func (c *Client) GetAppSlug(ctx context.Context) (string, error)
- func (c *Client) GetClient() *github.Client
- func (c *Client) GetOrCreateTeam(ctx context.Context, teamName, privacy string) (*github.Team, error)
- func (c *Client) GetOrg() string
- func (c *Client) GetTeamMembers(ctx context.Context, teamSlug string) ([]string, error)
- func (c *Client) IsExternalCollaborator(ctx context.Context, username string) (bool, error)
- func (c *Client) ListOrgMembers(ctx context.Context) ([]string, error)
- func (c *Client) SyncTeamMembers(ctx context.Context, teamSlug string, desiredMembers []string, ...) (*TeamSyncResult, error)
- type ComplianceViolation
- type PRComplianceResult
- type TeamSyncResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the GitHub API client with App authentication. automatically refreshes installation tokens before expiry.
func NewAppClient ¶
NewAppClient creates a GitHub App client with default base URL.
func NewAppClientWithBaseURL ¶
func NewAppClientWithBaseURL(appID, installationID int64, privateKeyPEM []byte, org, baseURL string) (*Client, error)
NewAppClientWithBaseURL creates a GitHub App client with custom base URL. supports GitHub Enterprise Server instances.
func (*Client) CheckPRCompliance ¶
func (c *Client) CheckPRCompliance(ctx context.Context, owner, repo string, prNumber int) (*PRComplianceResult, error)
CheckPRCompliance verifies if a merged PR met branch protection requirements. checks review requirements, status checks, and user bypass permissions.
func (*Client) Do ¶
Do executes an HTTP request with authentication. ensures token is valid before executing request.
func (*Client) GetAppSlug ¶
GetAppSlug fetches the GitHub App slug identifier. used to detect changes made by the app itself. requires JWT authentication (not installation token).
func (*Client) GetOrCreateTeam ¶
func (c *Client) GetOrCreateTeam(ctx context.Context, teamName, privacy string) (*github.Team, error)
GetOrCreateTeam fetches an existing team by slug or creates it if missing.
func (*Client) GetTeamMembers ¶
GetTeamMembers returns GitHub usernames of all team members.
func (*Client) IsExternalCollaborator ¶
IsExternalCollaborator checks if a user is an outside collaborator rather than an organization member. returns true if user is not a full org member.
func (*Client) ListOrgMembers ¶
ListOrgMembers returns all organization members excluding external collaborators.
func (*Client) SyncTeamMembers ¶
func (c *Client) SyncTeamMembers(ctx context.Context, teamSlug string, desiredMembers []string, safetyThreshold float64) (*TeamSyncResult, error)
SyncTeamMembers adds and removes members to match desired state. collects errors for individual operations but continues processing. skips removal of external collaborators (outside org members). applies safety threshold to prevent mass removal during outages.
type ComplianceViolation ¶
ComplianceViolation represents a single branch protection rule violation.
type PRComplianceResult ¶
type PRComplianceResult struct {
PR *github.PullRequest
BaseBranch string
Protection *github.Protection
BranchRules *github.BranchRules
Violations []ComplianceViolation
UserHasBypass bool
UserBypassReason string
}
PRComplianceResult contains PR compliance check results including violations and user bypass permissions.
func (*PRComplianceResult) HasViolations ¶
func (r *PRComplianceResult) HasViolations() bool
HasViolations returns true if any compliance violations were detected.
func (*PRComplianceResult) WasBypassed ¶
func (r *PRComplianceResult) WasBypassed() bool
WasBypassed returns true if violations exist and user had bypass permission.