Documentation
¶
Overview ¶
Package backend provides a GitHub API client for git-janitor.
It fetches repository metadata (visibility, fork status, description, issues/PR counts, etc.) to power GitHub-specific checks and enrich the Facts tab in the TUI.
Authentication uses GITHUB_TOKEN or GH_TOKEN from the environment. When no token is available, all GitHub features are silently disabled.
Index ¶
- Variables
- func CollectSecurityAlerts(ctx context.Context, c *Client, data *models.PlatformInfo)
- func ExtractOwnerRepo(rawURL string) (owner, repo string, err error)
- type Cache
- type Client
- func (c *Client) AddIssueAssignees(ctx context.Context, owner, repo string, number int, logins []string) error
- func (c *Client) AuthenticatedLogin(ctx context.Context) (string, error)
- func (c *Client) Available() bool
- func (c *Client) CloseIssue(ctx context.Context, owner, repo string, number int) error
- func (c *Client) DisableActions(ctx context.Context, owner, repo string) error
- func (c *Client) EnableBranchProtection(ctx context.Context, owner, repo, branch string) error
- func (c *Client) EnableDeleteBranchOnMerge(ctx context.Context, owner, repo string) error
- func (c *Client) Fetch(ctx context.Context, owner, repo string, opts FetchOptions) *models.PlatformInfo
- func (c *Client) GetIssueDetail(ctx context.Context, owner, repo string, number int) *models.IssueDetail
- func (c *Client) GetPullRequestDetail(ctx context.Context, owner, repo string, number int) *models.PullRequestDetail
- func (c *Client) GetWorkflowRunDetail(ctx context.Context, owner, repo string, runID int64) *models.WorkflowRunDetail
- func (c *Client) ListIssues(ctx context.Context, owner, repo string, page, perPage int) ([]models.Issue, bool, error)
- func (c *Client) ListPullRequests(ctx context.Context, owner, repo string, page, perPage int) ([]models.PullRequest, bool, error)
- func (c *Client) ListWorkflowRuns(ctx context.Context, owner, repo string, page, perPage int) ([]models.WorkflowRun, bool, error)
- func (c *Client) Rate() RateInfo
- func (c *Client) Scopes() string
- func (c *Client) SetDescription(ctx context.Context, owner, repo, description string) error
- type FetchOptions
- type RateInfo
- type Runner
Constants ¶
This section is empty.
Variables ¶
var ErrRateLimited = errors.New("github: rate limited, try again later")
ErrRateLimited is returned when the GitHub API rate limit is too low to safely make more requests.
Functions ¶
func CollectSecurityAlerts ¶
func CollectSecurityAlerts(ctx context.Context, c *Client, data *models.PlatformInfo)
CollectSecurityAlerts fetches open security alert counts from all three GitHub security APIs (Dependabot, code scanning, secret scanning).
Each API call is independent — a 403 (insufficient permissions) on one does not prevent the others from being queried. Fields remain -1 when the corresponding API is not accessible.
Total: up to 3 API calls.
func ExtractOwnerRepo ¶
ExtractOwnerRepo parses a GitHub remote URL into owner and repo.
Supported formats:
- git@github.com:owner/repo.git
- https://github.com/owner/repo.git
- https://github.com/owner/repo
- ssh://git@github.com/owner/repo.git
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a simple TTL cache for GitHub PlatformInfo, keyed by "owner/repo".
func (*Cache) Get ¶
func (c *Cache) Get(key string) (*models.PlatformInfo, bool)
Get returns cached data if present and not expired.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the go-github client with token resolution and rate-limit awareness.
func NewClient ¶
func NewClient() *Client
NewClient creates a Client from environment variables.
It checks GITHUB_TOKEN first, then GH_TOKEN as fallback. If neither is set, Available() returns false and all fetch operations return immediately with a nil PlatformInfo.
func (*Client) AddIssueAssignees ¶
func (c *Client) AddIssueAssignees(ctx context.Context, owner, repo string, number int, logins []string) error
AddIssueAssignees assigns the given logins to the specified issue. The call requires at least triage permission on the repository; GitHub silently drops logins that are not allowed to be assigned, so callers should verify the effect via a follow-up fetch if certainty is needed.
func (*Client) AuthenticatedLogin ¶
AuthenticatedLogin returns the GitHub login of the token holder, fetching it on first use and caching the result. Returns "" when the token is not available or the lookup fails.
func (*Client) CloseIssue ¶
CloseIssue transitions the given issue to the "closed" state. Requires the token holder to have write access to the repository.
func (*Client) DisableActions ¶
DisableActions disables GitHub Actions on the given repository.
func (*Client) EnableBranchProtection ¶
EnableBranchProtection sets a minimal branch protection rule on the given branch: requires at least one pull request review before merging.
func (*Client) EnableDeleteBranchOnMerge ¶
EnableDeleteBranchOnMerge enables the "Automatically delete head branches" setting on the given repository.
func (*Client) Fetch ¶
func (c *Client) Fetch(ctx context.Context, owner, repo string, opts FetchOptions) *models.PlatformInfo
Fetch retrieves GitHub repo data, using the cache unless ForceRefresh is true.
func (*Client) GetIssueDetail ¶
func (c *Client) GetIssueDetail(ctx context.Context, owner, repo string, number int) *models.IssueDetail
GetIssueDetail fetches full detail for a single issue.
func (*Client) GetPullRequestDetail ¶
func (c *Client) GetPullRequestDetail(ctx context.Context, owner, repo string, number int) *models.PullRequestDetail
GetPullRequestDetail fetches full detail for a single pull request.
func (*Client) GetWorkflowRunDetail ¶
func (c *Client) GetWorkflowRunDetail(ctx context.Context, owner, repo string, runID int64) *models.WorkflowRunDetail
GetWorkflowRunDetail fetches full detail for a single workflow run.
func (*Client) ListIssues ¶
func (c *Client) ListIssues(ctx context.Context, owner, repo string, page, perPage int) ([]models.Issue, bool, error)
ListIssues fetches a page of open issues sorted by last updated (descending). Returns the issues, whether more pages exist, and any error. The GitHub API includes PRs in the issues endpoint — we filter them out.
func (*Client) ListPullRequests ¶
func (c *Client) ListPullRequests(ctx context.Context, owner, repo string, page, perPage int) ([]models.PullRequest, bool, error)
ListPullRequests fetches a page of open pull requests sorted by last updated (descending). Returns the PRs, whether more pages exist, and any error.
func (*Client) ListWorkflowRuns ¶
func (c *Client) ListWorkflowRuns(ctx context.Context, owner, repo string, page, perPage int) ([]models.WorkflowRun, bool, error)
ListWorkflowRuns fetches a page of recent workflow runs. Returns the runs, whether more pages exist, and any error.
type FetchOptions ¶
FetchOptions controls what data to fetch.