github

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package github implements the GitHub APIs used by Cogito (Commit status API).

See the README and CONTRIBUTING files for additional information, caveats about GitHub API and imposed limits, and reference to official documentation.

Index

Constants

View Source
const GhDefaultHostname = "github.com"

GhDefaultHostname is the default GitHub hostname (used for git but not for the API)

Variables

This section is empty.

Functions

func ApiRoot added in v0.12.0

func ApiRoot(h string) string

ApiRoot constructs the root part of the GitHub API URL for a given hostname. Example: if hostname is github.com it returns https://api.github.com if hostname looks like a httptest server, it returns http://127.0.0.1:PORT otherwise, hostname is assumed to be of a Github Enterprise instance. For example, github.mycompany.org returns https://github.mycompany.org/api/v3

func Backoff added in v0.11.0

func Backoff(first bool, previous, limit time.Duration, err error) time.Duration

Backoff implements retry.BackoffFunc for GitHub.

func Classifier added in v0.11.0

func Classifier(err error) retry.Action

Classifier implements retry.ClassifierFunc for GitHub.

func NewGitHubError added in v0.11.0

func NewGitHubError(httpResp *http.Response, innerErr error) error

func RateLimited added in v0.11.0

func RateLimited(err GitHubError) bool

RateLimited returns true if the http.Response in err reports being rate limited. See https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#exceeding-the-rate-limit

func TransientError added in v0.11.0

func TransientError(statusCode int) bool

TransientError returns true if the http.Response in err has a status code that can be retried.

Types

type AddRequest added in v0.8.0

type AddRequest struct {
	State       string `json:"state"`
	TargetURL   string `json:"target_url"`
	Description string `json:"description"`
	Context     string `json:"context"`
}

AddRequest is the JSON object sent to the API.

type CommitStatus added in v0.7.0

type CommitStatus struct {
	// contains filtered or unexported fields
}

CommitStatus is a wrapper to the GitHub API to set the commit status for a specific GitHub owner and repo. See also: - NewCommitStatus - https://docs.github.com/en/rest/commits/statuses

func NewCommitStatus added in v0.7.0

func NewCommitStatus(target *Target, token, owner, repo, context string, log *slog.Logger) CommitStatus

NewCommitStatus returns a CommitStatus object associated to a specific GitHub owner and repo. Parameter token is the personal OAuth token of a user that has write access to the repo. It only needs the repo:status scope. Parameter context is what created the status, for example "JOBNAME", or "PIPELINENAME/JOBNAME". The name comes from the GitHub API. Be careful when using PIPELINENAME: if that name is ephemeral, it will make it impossible to use GitHub repository branch protection rules.

See also: - https://docs.github.com/en/rest/commits/statuses

func (CommitStatus) Add added in v0.7.0

func (cs CommitStatus) Add(sha, state, targetURL, description string) error

Add sets the commit state to the given sha, decorating it with targetURL and optional description. In case of transient errors or rate limiting by the backend, Add performs a certain number of attempts before giving up. The retry logic is configured in the Target.Retry parameter of NewCommitStatus. Parameter sha is the 40 hexadecimal digit sha associated to the commit to decorate. Parameter state is one of error, failure, pending, success. Parameter targetURL (optional) points to the specific process (for example, a CI build) that generated this state. Parameter description (optional) gives more information about the status. The returned error contains some diagnostic information to help troubleshooting.

See also: https://docs.github.com/en/rest/commits/statuses#create-a-commit-status

type GitHubError added in v0.11.0

type GitHubError struct {
	StatusCode         int
	OauthInfo          string
	Date               time.Time
	RateLimitRemaining int
	RateLimitReset     time.Time
	// contains filtered or unexported fields
}

func (GitHubError) Error added in v0.11.0

func (ghe GitHubError) Error() string

func (GitHubError) Unwrap added in v0.11.0

func (ghe GitHubError) Unwrap() error

type GitURL added in v0.12.1

type GitURL struct {
	URL      *url.URL
	Owner    string
	Repo     string
	FullName string
}

func ParseGitPseudoURL added in v0.12.1

func ParseGitPseudoURL(rawURL string) (GitURL, error)

ParseGitPseudoURL attempts to parse rawURL as a git remote URL compatible with the Github naming conventions.

It supports the following types of git pseudo URLs:

type StatusError added in v0.2.0

type StatusError struct {
	What       string
	StatusCode int
	Details    string
}

StatusError is one of the possible errors returned by the github package.

func (*StatusError) Error added in v0.2.0

func (e *StatusError) Error() string

type Target added in v0.10.0

type Target struct {
	// Server is the GitHub API server.
	Server string
	// Retry controls the retry logic.
	Retry retry.Retry
}

Jump to

Keyboard shortcuts

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