github

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: AGPL-3.0 Imports: 28 Imported by: 2

Documentation

Index

Constants

View Source
const Provider = "github"

Variables

View Source
var (
	// ErrLineOutOfDiff is returned when the file line number is not
	// in the patch diff
	ErrLineOutOfDiff = errors.NewKind("line number is not in diff")
	// ErrLineNotAddition is returned when the file line number is not
	// a + change in the patch diff
	ErrLineNotAddition = errors.NewKind("line number is not an added change")
	// ErrFileNotFound is returned when the file name is not part of the diff
	ErrFileNotFound = errors.NewKind("file not found")
	// ErrBadPatch is returned when there was a problem parsing the diff
	ErrBadPatch = errors.NewKind("diff patch could not be parsed")
)
View Source
var (
	// ErrGitHubAPI signals an error while making a request to the GitHub API.
	ErrGitHubAPI = errors.NewKind("github api error: %s")
	// ErrEventNotSupported signals that this provider does not support the
	// given event for a given operation.
	ErrEventNotSupported = errors.NewKind("event not supported")
)
View Source
var (
	ErrEmptyTemplate = errors.NewKind("empty footer template")
	ErrOldTemplate   = errors.NewKind("old footer template: '%%s' placeholder is no longer supported: '%s'")
	ErrParseTemplate = errors.NewKind("error parsing footer template: %s")
	ErrTemplateError = errors.NewKind("error generating the footer: %s")
)
View Source
var (
	NoErrNotModified       = errors.NewKind("Not modified")
	ErrParsingEventPayload = errors.NewKind("Parse error in event")

	// RequestTimeout is the max time to wait until the request context is
	// cancelled.
	RequestTimeout = time.Second * 5
)

Functions

func CanPostStatus added in v0.10.0

func CanPostStatus(client *Client, repo *repositoryInfo) error

CanPostStatus check if the client has push access to a repository which is required for updating status. It assumes client has correct scope. returns error if it permission is missed

func ValidateTokenPermissions added in v0.10.0

func ValidateTokenPermissions(client *Client) error

ValidateTokenPermissions checks that client has necessary permissions required by lookout returns error if any is missed

Types

type Client added in v0.1.0

type Client struct {
	*github.Client
	// contains filtered or unexported fields
}

Client is a wrapper for github.Client that supports cache and provides rate limit information

func NewClient added in v0.1.0

func NewClient(
	t http.RoundTripper,
	cache *cache.ValidableCache,
	watchMinInterval string,
	gitAuth gitAuthFn,
	timeout time.Duration,
) *Client

NewClient creates new Client. A timeout of zero means no timeout.

func (*Client) PollInterval added in v0.1.0

func (c *Client) PollInterval(cat pollLimitCategory) time.Duration

PollInterval returns last duration from X-Poll-Interval for a client by category

func (*Client) Rate added in v0.1.0

func (c *Client) Rate(cat rateLimitCategory) github.Rate

Rate returns last github.Rate for a client by category

func (*Client) Username added in v0.10.0

func (c *Client) Username() (string, error)

Username returns name of the user for the current client

func (*Client) Validate added in v0.1.0

func (c *Client) Validate(path string) error

Validate validates cache by path

type ClientConfig added in v0.1.1

type ClientConfig struct {
	User        string
	Token       string
	MinInterval string
}

ClientConfig holds github username, token and watch interval

func (ClientConfig) IsZero added in v0.1.1

func (c ClientConfig) IsZero() bool

IsZero return true if config is empty and false otherwise

type ClientPool added in v0.1.0

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

ClientPool holds mapping of repositories to clients

func NewClientPool added in v0.1.5

func NewClientPool() *ClientPool

NewClientPool creates new pool of clients with repositories

func NewClientPoolFromTokens added in v0.1.0

func NewClientPoolFromTokens(
	urlToConfig map[string]ClientConfig,
	cache *cache.ValidableCache,
	timeout time.Duration,
) (*ClientPool, error)

NewClientPoolFromTokens creates new ClientPool based on map[repoURL]ClientConfig later we will need another constructor that would request installations and create pool from it

func (*ClientPool) Client added in v0.1.0

func (p *ClientPool) Client(username, repo string) (*Client, bool)

Client returns client, ok by username and repository name

func (*ClientPool) Clients added in v0.1.0

func (p *ClientPool) Clients() map[*Client][]*repositoryInfo

Clients returns map[Client]RepositoryInfo

func (*ClientPool) GitAuth added in v0.3.0

GitAuth returns a go-git auth method for a repo

func (*ClientPool) RemoveClient added in v0.1.5

func (p *ClientPool) RemoveClient(c *Client)

RemoveClient removes client from the pool and notifies about it

func (*ClientPool) Repos added in v0.1.5

func (p *ClientPool) Repos() []string

Repos returns list of repositories in the pool

func (*ClientPool) ReposByClient added in v0.1.5

func (p *ClientPool) ReposByClient(c *Client) []*repositoryInfo

ReposByClient returns list of repositories by client

func (*ClientPool) Subscribe added in v0.1.5

func (p *ClientPool) Subscribe(ch chan ClientPoolEvent)

Subscribe allows to subscribe to changes in the pool

func (*ClientPool) Unsubscribe added in v0.1.5

func (p *ClientPool) Unsubscribe(ch chan ClientPoolEvent)

Unsubscribe stops sending changes to the channel

func (*ClientPool) Update added in v0.1.5

func (p *ClientPool) Update(c *Client, newRepos []*repositoryInfo)

Update updates list of repositories for a client

type ClientPoolEvent added in v0.1.5

type ClientPoolEvent struct {
	Type   ClientPoolEventType
	Client *Client
}

ClientPoolEvent defines change in ClientPool

type ClientPoolEventType added in v0.1.5

type ClientPoolEventType string

ClientPoolEventType type of the change in ClientPool

const (
	// ClientPoolEventAdd happens when new client is added in the pool
	ClientPoolEventAdd ClientPoolEventType = "add"
	// ClientPoolEventRemove happens when client is removed from the pool
	ClientPoolEventRemove ClientPoolEventType = "remove"
)

type Installations added in v0.1.5

type Installations struct {
	Pool *ClientPool
	// contains filtered or unexported fields
}

Installations keeps github installations and allows to sync them

func NewInstallations added in v0.1.5

func NewInstallations(
	appID int, privateKey string,
	cache *cache.ValidableCache,
	watchMinInterval string,
	clientTimeout time.Duration,
) (*Installations, error)

NewInstallations creates a new Installations using the App ID and private key

func (*Installations) Sync added in v0.1.5

func (t *Installations) Sync() error

Sync update state from github

type Poster

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

Poster posts comments as Pull Request Reviews.

func NewPoster

func NewPoster(pool *ClientPool, conf ProviderConfig) (*Poster, error)

NewPoster creates a new poster for the GitHub API.

func (*Poster) Post

func (p *Poster) Post(ctx context.Context, e lookout.Event,
	aCommentsList []lookout.AnalyzerComments, safe bool) error

Post posts comments as a Pull Request Review. If the event is not a GitHub Pull Request, ErrEventNotSupported is returned. If a GitHub API request fails, ErrGitHubAPI is returned.

func (*Poster) Status added in v0.0.3

func (p *Poster) Status(ctx context.Context, e lookout.Event, status lookout.AnalysisStatus) error

Status sets the Pull Request global status, visible from the GitHub UI If a GitHub API request fails, ErrGitHubAPI is returned.

type ProviderConfig added in v0.0.4

type ProviderConfig struct {
	CommentFooter            string `yaml:"comment_footer"`
	PrivateKey               string `yaml:"private_key"`
	AppID                    int    `yaml:"app_id"`
	InstallationSyncInterval string `yaml:"installation_sync_interval"`
	WatchMinInterval         string `yaml:"watch_min_interval"`
}

ProviderConfig represents the yml config

type StatusCreator added in v0.0.3

type StatusCreator interface {
	// CreateStatus creates a new status for a repository at the specified
	// reference. Ref can be a SHA, a branch name, or a tag name.
	CreateStatus(ctx context.Context, owner, repo, ref string, status *github.RepoStatus) (
		*github.RepoStatus, *github.Response, error)
}

StatusCreator creates statuses on GitHub. *github.RepositoriesService fulfills this interface.

type Watcher

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

func NewWatcher

func NewWatcher(pool *ClientPool) (*Watcher, error)

NewWatcher returns a new

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context, cb lookout.EventHandler) error

Watch start to make request to the GitHub API and return the new events.

Jump to

Keyboard shortcuts

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