Documentation
¶
Overview ¶
Package githubapi contains functionality related to the GitHub API
Index ¶
- func CreatePRDescription(changeInfo config.ChangeInfo) string
- type Client
- func (client *Client) CheckDirectoryExists(org string, repo string, directory string, branchName string) (bool, error)
- func (client *Client) CreateOrUpdatePullRequest(org string, repo string, baseBranch string, prDesc string, content string, ...) error
- func (client *Client) GetFileContent(org string, repo string, path string, branchName string) ([]byte, error)
- func (client *Client) GetRepoFileList(org string, repo string, defaultBranch string) ([]string, error)
- func (client *Client) GetRepository(org string, repo string) (*github.Repository, error)
- func (client *Client) RateLimit() RateLimitState
- type RateLimitState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreatePRDescription ¶
func CreatePRDescription(changeInfo config.ChangeInfo) string
CreatePRDescription renders the body of the PR to be created.
Types ¶
type Client ¶ added in v0.9.5
type Client struct {
// contains filtered or unexported fields
}
Client is a GitHub API client that keeps track of the rate limit reported by the responses it receives. All API calls go through it, so the rate limit state is always derived from real traffic and is scoped to this client rather than shared through package level state.
func NewClient ¶ added in v0.9.5
NewClient returns a GitHub API client authenticated with the given token.
func (*Client) CheckDirectoryExists ¶ added in v0.9.5
func (client *Client) CheckDirectoryExists(org string, repo string, directory string, branchName string) (bool, error)
CheckDirectoryExists checks if a directory exists in the remote GitHub repository.
func (*Client) CreateOrUpdatePullRequest ¶ added in v0.9.5
func (client *Client) CreateOrUpdatePullRequest(org string, repo string, baseBranch string, prDesc string, content string, toolConfig config.ToolConfig) error
CreateOrUpdatePullRequest creates or updates a PR for changes in dependabot.yml
func (*Client) GetFileContent ¶ added in v0.9.5
func (client *Client) GetFileContent(org string, repo string, path string, branchName string) ([]byte, error)
GetFileContent returns the content of a file
func (*Client) GetRepoFileList ¶ added in v0.9.5
func (client *Client) GetRepoFileList(org string, repo string, defaultBranch string) ([]string, error)
GetRepoFileList returns a list (strings) of all files in a repo, including their path.
func (*Client) GetRepository ¶ added in v0.9.5
GetRepository gets a repository object.
func (*Client) RateLimit ¶ added in v0.9.5
func (client *Client) RateLimit() RateLimitState
RateLimit returns the rate limit state observed on this client's most recent API response.
type RateLimitState ¶ added in v0.9.5
type RateLimitState struct {
// Known is false until an API response has been observed.
Known bool
// Remaining is the number of requests left in the current window.
Remaining int
// Reset is the time the current window rolls over.
Reset time.Time
// Exhausted is true if the budget is used up or the last API call was
// rejected because a primary or secondary rate limit had been reached.
Exhausted bool
}
RateLimitState is a snapshot of the GitHub API rate limit, taken from the X-RateLimit-* headers of the most recent API response.
The GET /rate_limit endpoint is deliberately not used. It has been observed reporting an untouched budget (used=0, remaining=5000) with a reset sliding along with wall-clock time, while the counter enforced on the same token's other requests had already been spent. Response headers are what GitHub's own documentation recommends relying on.
func (RateLimitState) WaitFor ¶ added in v0.9.5
func (s RateLimitState) WaitFor(now time.Time) time.Duration
WaitFor returns how long to pause before the next API request, or zero if no pause is needed: the limit has not been reached, or its reset has already passed. No safety buffer is needed, because every API call reports the limit it saw, so exhaustion is noticed as soon as it happens.