client

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 13 Imported by: 0

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

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

func NewAppClient(appID, installationID int64, privateKeyPEM []byte, org string) (*Client, error)

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

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do executes an HTTP request with authentication. ensures token is valid before executing request.

func (*Client) GetAppSlug

func (c *Client) GetAppSlug(ctx context.Context) (string, error)

GetAppSlug fetches the GitHub App slug identifier. used to detect changes made by the app itself. requires JWT authentication (not installation token).

func (*Client) GetClient

func (c *Client) GetClient() *github.Client

GetClient returns the underlying go-github client.

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) GetOrg

func (c *Client) GetOrg() string

GetOrg returns the GitHub organization name.

func (*Client) GetTeamMembers

func (c *Client) GetTeamMembers(ctx context.Context, teamSlug string) ([]string, error)

GetTeamMembers returns GitHub usernames of all team members.

func (*Client) IsExternalCollaborator

func (c *Client) IsExternalCollaborator(ctx context.Context, username string) (bool, error)

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

func (c *Client) ListOrgMembers(ctx context.Context) ([]string, error)

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

type ComplianceViolation struct {
	Type        string
	Description string
}

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.

type TeamSyncResult

type TeamSyncResult struct {
	TeamName               string
	MembersAdded           []string
	MembersRemoved         []string
	MembersSkippedExternal []string
	Errors                 []string
}

TeamSyncResult contains the results of syncing team membership.

Jump to

Keyboard shortcuts

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