gh

package
v0.0.0-...-3d4bac1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RepoFromGitHub

func RepoFromGitHub(r *github.Repository) host.Repo

RepoFromGitHub wraps a github repository in a Repo

func ReposFromGitHub

func ReposFromGitHub(rs []*github.Repository) []host.Repo

ReposFromGitHub wraps a slice of repositories in a slice of Repos

Types

type AppAuth

type AppAuth struct {
	AppID          string
	ClientID       string
	ClientSecret   string
	SigningKeyPath string
}

AppAuth is a container for authorization configuration

func NewEnvAuth

func NewEnvAuth() *AppAuth

NewEnvAuth instantiates authentication from environment variables

func (*AppAuth) GenerateJWT

func (a *AppAuth) GenerateJWT() (string, *time.Time, error)

GenerateJWT signs a new JWT for use with the GitHub API

func (*AppAuth) Token

func (a *AppAuth) Token() (*oauth2.Token, error)

Token implements oauth2.TokenSource, and is used as an autogenerating token source

type Client

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

Client handles GitHub sync and API requests

func NewClient

func NewClient(ctx context.Context, l *zap.SugaredLogger, auth oauth2.TokenSource) (*Client, error)

NewClient instantiates a new github client. This package offers several implementations of auth, and different clients should be instantiated for different purposes.

  • a "signing client" should use AppAuth and NewSigningClient, and only be used to create installation clients.
  • a "installation client" should use InstallationAuth, and only be created from a SigningClient
  • a "default client" should use nil auth, and be used for unauthenticated requests

func (*Client) GetIssues

func (c *Client) GetIssues(
	ctx context.Context,
	user, repo string,
	filter ItemFilter,
	issuesC chan<- *github.Issue,
	wait *sync.WaitGroup,
) error

GetIssues retrieves all issues for a project

func (*Client) GetPullRequests

func (c *Client) GetPullRequests(
	ctx context.Context,
	user, repo string,
	filter ItemFilter,
	prC chan<- *github.PullRequest,
	wait *sync.WaitGroup,
) error

GetPullRequests retrieves all pull requests for a project

func (*Client) GetRepository

func (c *Client) GetRepository(ctx context.Context, owner, repo string) (*github.Repository, error)

GetRepository fetches the given repository

func (*Client) InstallationToken

func (c *Client) InstallationToken() string

InstallationToken returns the token in use by the client, if there is one

type Event

type Event struct {
	GitHubEvent    string `json:"X-GitHub-Event"`
	GitHubDelivery string `json:"X-GitHub-Delivery"`
	HubSignature   string `json:"X-Hub-Signature"`
}

Event denotes basic event metadata

type InstallationAuth

type InstallationAuth struct {
	ID int64
	// contains filtered or unexported fields
}

InstallationAuth contains parameters for a specific installation

func NewInstallationAuth

func NewInstallationAuth(ctx context.Context, gh *github.Client, logger *zap.SugaredLogger, id string) (*InstallationAuth, error)

NewInstallationAuth instantiates a new installation-specific token generator

func (*InstallationAuth) Token

func (i *InstallationAuth) Token() (*oauth2.Token, error)

Token implements oauth2.TokenSource, and is used as an autogenerating token source. It queries GitHub for an installation-specific token.

type IssueState

type IssueState string

IssueState denotes whether to get issues that are closed, open, or all

const (
	// IssueStateAll = all issues
	IssueStateAll IssueState = "all"
	// IssueStateClosed = closed issues
	IssueStateClosed IssueState = "closed"
	// IssueStateOpen = open issues
	IssueStateOpen IssueState = "open"
)

type ItemFilter

type ItemFilter struct {
	MinNumber int
	State     IssueState
	Interval  time.Duration
}

ItemFilter denotes options to filter issues and PRs by

type Repo

type Repo struct {
	Owner string
	Name  string
}

Repo denotes a repository to sync

type SigningClient

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

SigningClient is a client dedicated to generating installation clients and doing other app-management stuff

func NewSigningClient

func NewSigningClient(l *zap.SugaredLogger, auth oauth2.TokenSource) (*SigningClient, error)

NewSigningClient instantiates a new SigningClient

func (*SigningClient) GetInstallationClient

func (c *SigningClient) GetInstallationClient(ctx context.Context, id string) (*Client, error)

GetInstallationClient gets an installation-specific client

type SyncOptions

type SyncOptions struct {
	Repo                Repo
	Filter              ItemFilter
	DetailsFetchWorkers int
	OutputBufferSize    int
}

SyncOptions denotes options for a syncer

type Syncer

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

Syncer manages all GitHub synchronization tasks

func NewSyncer

func NewSyncer(
	l *zap.SugaredLogger,
	client *Client,
	opts SyncOptions,
) *Syncer

NewSyncer instantiates a new GitHub Syncer. It Syncer::Sync() can only be used once. TODO: should it be reusable?

func (*Syncer) Sync

func (s *Syncer) Sync(ctx context.Context, wg *sync.WaitGroup) (<-chan *host.Item, <-chan error)

Sync pulls all issues from its configured repository and pipes them to the returned channels. It can only be called once.

Jump to

Keyboard shortcuts

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