github

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetRateLimitTransport

func SetRateLimitTransport(client *http.Client, logger log.Logger)

SetRateLimitTransport wraps the passed client.Transport with a RateLimitTransport

func SetRetryTransport

func SetRetryTransport(client *http.Client)

SetRetryTransport wraps the passed client.Transport with a RetryTransport

Types

type Connection

type Connection interface {
	Len() int
	GetTotalCount() int
	GetPageInfo() graphql.PageInfo
}

Connection is a unified interface for GraphQL connections

type Downloader

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

Downloader fetches GitHub data using the v4 API

func NewDownloader

func NewDownloader(httpClient *http.Client, db *sql.DB) (*Downloader, error)

NewDownloader creates a new Downloader that will store the GitHub metadata in the given DB. The HTTP client is expected to have the proper authentication setup

func NewMemoryDownloader

func NewMemoryDownloader(httpClient *http.Client, memory *testutils.Memory) (*Downloader, error)

NewMemoryDownloader creates a new Downloader that stores GitHub data in memory. The HTTP client is expected to have the proper authentication setup

func NewStdoutDownloader

func NewStdoutDownloader(httpClient *http.Client) (*Downloader, error)

NewStdoutDownloader creates a new Downloader that will print the GitHub metadata to stdout. The HTTP client is expected to have the proper authentication setup

func (Downloader) Cleanup

func (d Downloader) Cleanup(ctx context.Context, currentVersion int) error

Cleanup deletes from the DB all records that do not belong to the currentVersion

func (Downloader) DownloadOrganization

func (d Downloader) DownloadOrganization(ctx context.Context, name string, version int) error

DownloadOrganization downloads the metadata for the given organization and its member users

func (Downloader) DownloadRepository

func (d Downloader) DownloadRepository(ctx context.Context, owner string, name string, version int) error

DownloadRepository downloads the metadata for the given repository and all its resources (issues, PRs, comments, reviews)

func (Downloader) ListRepositories

func (d Downloader) ListRepositories(ctx context.Context, name string, noForks bool) ([]string, error)

func (Downloader) RateRemaining

func (d Downloader) RateRemaining(ctx context.Context) (int, error)

RateRemaining returns the remaining rate limit for the v4 GitHub API

func (Downloader) SetCurrent

func (d Downloader) SetCurrent(ctx context.Context, version int) error

SetCurrent enables the given version as the current one accessible in the DB

type ErrAbuseRateLimit

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

ErrAbuseRateLimit is returned when a request triggers any GitHub abuse detection mechanism https://developer.github.com/v3/#abuse-rate-limits

func (*ErrAbuseRateLimit) Error

func (e *ErrAbuseRateLimit) Error() string

type ErrRateLimit

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

ErrRateLimit is returned when a request failed because of a RateLimit https://developer.github.com/v4/guides/resource-limitations/#rate-limit

func (*ErrRateLimit) Error

func (e *ErrRateLimit) Error() string

type ErrUnauthorized added in v0.1.1

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

ErrUnauthorized is returned when a response returns 401

func (*ErrUnauthorized) Error added in v0.1.1

func (e *ErrUnauthorized) Error() string

type Query

type Query interface {
	Connection() Connection
}

Query is a GraphQL query that returns Connection

type RateLimitTransport

type RateLimitTransport struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RateLimitTransport implements GitHub GraphQL API v4 best practices for avoiding rate limits https://developer.github.com/v4/guides/resource-limitations/#rate-limit https://developer.github.com/v3/#abuse-rate-limits RateLimitTransport will process a Request, and if the response could not be fetched because of a RateLimit or an AbuseRateLimit, it will return an ErrorRateLimit and it no longer process any further Requests until the Limit has been expired. RateLimitTransport does not retry; that behaviour must be implemented by another Transport Each client (with its own token) should use its own RateLimitTransport

func NewRateLimitTransport

func NewRateLimitTransport(rt http.RoundTripper, logger log.Logger) *RateLimitTransport

NewRateLimitTransport returns a new NewRateLimitTransport, who will call the passed http.RoundTripper to process the http.Request Each client (with its own token) should use its own RateLimitTransport

func (*RateLimitTransport) RoundTrip

func (rt *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction, returning a Response for the provided Request. If the request hitted an API RateLimit or Abuse, it will return an ErrorRateLimit and it no longer process any further Requests until the Limit has been expired.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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