Documentation
¶
Overview ¶
Package client is the GitHub API client. It authenticates as a GitHub App, checks merged pull requests for compliance, syncs team membership, and lists security alerts.
Index ¶
- Constants
- func ParsePrivateKey(privateKeyPEM []byte) (*rsa.PrivateKey, error)
- type Client
- func (c *Client) CheckPRCompliance(ctx context.Context, owner, repo string, prNumber int) (*domain.PRComplianceResult, error)
- func (c *Client) GetAppSlug(ctx context.Context) (string, error)
- func (c *Client) GetTeamMembers(ctx context.Context, teamSlug string) ([]string, error)
- func (c *Client) ListOrgMembers(ctx context.Context) ([]string, error)
- func (c *Client) ListSecurityAlerts(ctx context.Context, minAgeDays int, minSeverity string) (*domain.SecurityAlertsReport, error)
- func (c *Client) ResolveTeam(ctx context.Context, name, privacy string, create bool) (string, error)
- func (c *Client) SyncTeamMembers(ctx context.Context, teamSlug string, desiredMembers []string, ...) (*domain.TeamSyncResult, error)
- type Options
Constants ¶
const ( AlertTypeDependabot = "dependabot" AlertTypeCodeScanning = "code_scanning" AlertTypeSecretScanning = "secret_scanning" )
Alert types in a security alerts report.
Variables ¶
This section is empty.
Functions ¶
func ParsePrivateKey ¶ added in v1.0.0
func ParsePrivateKey(privateKeyPEM []byte) (*rsa.PrivateKey, error)
ParsePrivateKey parses a PEM-encoded RSA private key in PKCS#1 or PKCS#8 form. Escaped newlines ("\n"), as found in single-line environment variables, are accepted.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a GitHub API client authenticated as a GitHub App installation. It is safe for concurrent use. Implements domain.GitHubClient.
func New ¶ added in v1.0.0
New creates a Client. It makes no API calls: credentials are exchanged for an installation token on first use and refreshed before they expire.
func (*Client) CheckPRCompliance ¶
func (c *Client) CheckPRCompliance(ctx context.Context, owner, repo string, prNumber int) (*domain.PRComplianceResult, error)
CheckPRCompliance verifies whether a merged PR met the requirements of its base branch: the approving reviews and status checks required by legacy branch protection and by repository rulesets. When it did not, the merger's repository role is recorded as the likely reason it could merge.
func (*Client) GetAppSlug ¶
GetAppSlug returns the GitHub App's slug, used to recognize changes the app made itself. It is fetched once and cached.
func (*Client) GetTeamMembers ¶
GetTeamMembers returns the logins of all team members.
func (*Client) ListOrgMembers ¶
ListOrgMembers returns the logins of all organization members. Outside collaborators are not members, so they are not included.
func (*Client) ListSecurityAlerts ¶ added in v0.22.0
func (c *Client) ListSecurityAlerts(ctx context.Context, minAgeDays int, minSeverity string) (*domain.SecurityAlertsReport, error)
ListSecurityAlerts fetches open security alerts across the org that were created more than minAgeDays ago and are at or above minSeverity. It covers dependabot, code scanning, and secret scanning alerts. A source that fails is recorded in the report's errors and the others still run.
func (*Client) ResolveTeam ¶ added in v1.0.0
func (c *Client) ResolveTeam(ctx context.Context, name, privacy string, create bool) (string, error)
ResolveTeam returns the slug of the team with the given name, creating the team when it is missing and create is true.
func (*Client) SyncTeamMembers ¶
func (c *Client) SyncTeamMembers(ctx context.Context, teamSlug string, desiredMembers []string, safetyThreshold float64) (*domain.TeamSyncResult, error)
SyncTeamMembers adds and removes members so the team matches desiredMembers. Errors for individual users are collected and the rest continue. Members of child teams and users who are not org members are not removed, and no one is removed if more than safetyThreshold of the team's direct members would be, which guards against an empty or partial member list from Okta.
type Options ¶ added in v1.0.0
type Options struct {
AppID int64
// InstallationID is the app's installation on Org. When zero, the
// installation is looked up on first use.
InstallationID int64
// PrivateKey is the app's PEM-encoded RSA private key.
PrivateKey []byte
Org string
// BaseURL is the API base URL, such as https://ghe.example.com/api/v3
// for GitHub Enterprise Server. Empty means https://api.github.com.
BaseURL string
// HTTPClient is the client requests are sent with. Its transport is
// wrapped to add authentication. Defaults to a client with a timeout.
HTTPClient *http.Client
}
Options configures a Client.