lazygithub

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GitHubGistURL             = "https://gist.github.com"
	GitHubIssuesURL           = "https://github.com/issues"
	GitHubPullsURL            = "https://github.com/pulls"
	GitHubRepoIssuesURLSuffix = "%s/issues"
	GitHubRepoPullsURLSuffix  = "%s/pulls"
)

GitHubGistURL is the base GitHub Gist URL. GitHubIssuesURL is the GitHub issues URL. GitHubPullsURL is GitHub URL for user pulls. GitHubRepoIssuesURLSuffix is the suffix for issues. GitHubRepoPullsURLSuffix is the suffix for pulls.

View Source
const (
	ErrStrAuthFailed              = "Can not login at GitHub: %s"
	ErrStrNoValidFilter           = "%s is no valid filter"
	ErrStrNoValidOrderByAttribute = "%s is no valid order attribute"
	ErrStrNoValidStateFilter      = "%s is no valid state filter"
	ErrStrNoValidVisibilityFilter = "%s is no valid visibility filter"
)

ErrStrAuthFailed is the error when the authentication failed. ErrStrNoValidFilter is the error message if no valid filter is present. ErrStrNoValidOrderByAttribute is the error message if no valid order attribute is present. ErrStrNoValidStateFilter is the error message if no valid state filter is present. ErrStrNoValidVisibilityFilter is the error message if no valid visibility filter is present.

View Source
const (
	IssuesFilterAssigned   = "assigned"
	IssuesFilterCreated    = "created"
	IssuesFilterMentioned  = "mentioned"
	IssuesFilterSubscribed = "subscribed"
)

IssueFilterAssigned is the filter for issues which are assigned to an user. IssueFilterCreated is the filter for issues that are created by an user. IssueFilterMentioned is the filter for issues where an user is mentioned. IssueFilterSubscribed is the filter for issues where an user has subscribed.

View Source
const (
	IssuesOrderByComments  = "comments"
	IssuesOrderByCreatedAt = "created"
	IssuesOrderByUpdatedAt = "updated"
)

IssueOrderByComments orders issues by the amount of comments. IssueOrderByCreatedAt orders issues by their created at date and time. IssueOrderByUpdatedAt orders issues by their last update date and time.

View Source
const (
	IssuesStateAll    = "all"
	IssuesStateClosed = "closed"
	IssuesStateOpen   = "open"
)

IssuesStateAll is the state for all issues. IssuesStateClosed is the state for all closed issues. IssuesStateOpen is the state for all open issues.

View Source
const (
	PullsFilterAssigned        = "assigned"
	PullsFilterCreated         = "created"
	PullsFilterMentioned       = "mentioned"
	PullsFilterReviewRequested = "review-requested"
)

PullsFilterAssigned is the filter for pulls which are assigned to an user. PullsFilterCreated is the filter for pulls that are created by an user. PullsFilterMentioned is the filter for pulls where an user is mentioned. PullsFilterReviewRequested is the filter for pulls where an review is requested by for an user.

View Source
const (
	PullsOrderByCreatedAt   = "created"
	PullsOrderByLongRunning = "long-running"
	PullsOrderByPopularity  = "popularity"
	PullsOrderByUpdatedAt   = "updated"
)

PullsOrderByCreatedAt orders pulls by their created at date and time. PullsOrderByLongRunning orders pulls by long-running. PullsOrderByPopularity orders pulls by their popularity. PullsOrderByUpdatedAt orders pulls by their last updated at date and time.

View Source
const (
	PullsStateAll    = "all"
	PullsStateClosed = "closed"
	PullsStateOpen   = "open"
)

PullsStateAll is the state for all pull requests. PullsStateClosed is the state for all closed pull requests. PullsStateOpen is the state for all open pull requests.

View Source
const (
	RepoTypeAll     = "all"
	RepoTypeDefault = ""
	RepoTypeMember  = "member"
	RepoTypeOwner   = "owner"
	RepoTypePrivate = "private"
	RepoTypePublic  = "public"
)

RepoTypeAll is the filter type for all. RepoTypeDefault is the filter type for the default. RepoTypeMember is the filter type for member. RepoTypeOwner is the filter type for owner. RepoTypePrivate is the filter type for private. RepoTypePublic is the filter type for public.

View Source
const (
	ReposOrderByCreatedAt = "created"
	ReposOrderByName      = "name"
	ReposOrderByPushed    = "pushed"
	ReposOrderByUpdatedAt = "updated"
)

ReposOrderByCreatedAt orders repos by their created at date and time. ReposOrderByName orders repos by their full name. ReposOrderByPushed orders repos by their pushed state ReposOrderByUpdatedAt orders repos by their last update date and time.

View Source
const (
	RepoVisibilityAll     = "all"
	RepoVisibilityDefault = ""
	RepoVisibilityPrivate = "private"
	RepoVisibilityPublic  = "public"
)

RepoVisibilityAll is the state for all repos. RepoVisibilityDefault is the filter type for the default. RepoVisibilityPrivate is the state for all private repos. RepoVisibilityPublic is the state for all public repos.

View Source
const GitHubDefaultItemLimit = 50

GitHubDefaultItemLimit is defining the maximum amount of items to fetch per API request.

Variables

View Source
var (
	ErrNoGistsFound = errors.New("Can not find gists")
	NullGists       = []Gist{}
)

ErrNoGistsFound is the error when no gists can be found. NullGists is an empty response if no GitHub gists are present.

View Source
var (
	ErrNoIssuesFound = errors.New("Can not find issues")
	NullIssues       = []Issue{}
)

ErrNoIssuesFound is the error when issues can't be found. NullIssues is an empty response if no GitHub issues are present.

View Source
var (
	ErrNoPullFound  = errors.New("Can not find pull request")
	ErrNoPullsFound = errors.New("Can not find pull requests")
	NullPull        = Pull{}
	NullPulls       = []Pull{}
)

ErrNoPullsFound is the error when pulls can't be found. ErrStrNoValidPullStateFilter is the error message string if no valid pr filter is present. NullPull is an empty response if no GitHub pull is present. NullPulls is an empty response if no GitHub pulls are present.

View Source
var (
	ErrRepoNotFound = errors.New("Can not find repository")
	NullRepo        Repo
	NullRepos       = []Repo{}
)

ErrRepoNotFound is the error when a repository can't be found. NullRepo is an empty response if no GitHub repo is present. NullRepos is an empty response if no GitHub repos are present.

View Source
var NullGitHubResponse = githubV3.Response{}

NullGitHubResponse is an empty github response.

View Source
var NullGitWorktree *git.Worktree

NullGitWorktree is an empty git worktree.

Functions

func Clone

func Clone(wd string, repo Repo) (*git.Repository, error)

Clone is cloning a GitHub repo to a given path.

func GitHubHubRepoFullNameByURL

func GitHubHubRepoFullNameByURL(htmlURL string) string

GitHubHubRepoFullNameByURL is generating the same result like *githubV3.Repository.GetFullName() This is used to limit the requests to the GitHub API when no repository object is present.

func IsGitRepo

func IsGitRepo(path string) (*git.Worktree, error)

IsGitRepo is checking if a given folder is a valid git directory and returning the worktree.

func Update

func Update(repo LocalRepo) error

Update is updating a given local git repo.

Types

type Auth

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

Auth is the struct for the GitHub authentication.

func NewAuth

func NewAuth() *Auth

NewAuth is returning a new Auth struct.

func (*Auth) Anonymous

func (auth *Auth) Anonymous() bool

Anonymous is returning the anonymous value.

func (*Auth) OTP

func (auth *Auth) OTP() string

OTP is returning the OTP.

func (*Auth) Password

func (auth *Auth) Password() string

Password is returning the password .

func (*Auth) SetAnonymous

func (auth *Auth) SetAnonymous(anonymous bool) *Auth

SetAnonymous is setting the authentication to anonymous.

func (*Auth) SetOTP

func (auth *Auth) SetOTP(otp string) *Auth

SetOTP is setting the OTP.

func (*Auth) SetPassword

func (auth *Auth) SetPassword(password string) *Auth

SetPassword is setting the password.

func (*Auth) SetToken

func (auth *Auth) SetToken(token string) *Auth

SetToken is setting the token.

func (*Auth) SetUser

func (auth *Auth) SetUser(user User) *Auth

SetUser is setting the user.

func (*Auth) SetUsername

func (auth *Auth) SetUsername(username string) *Auth

SetUsername is setting the username.

func (*Auth) Token

func (auth *Auth) Token() string

Token is returning the token.

func (*Auth) User

func (auth *Auth) User() User

User is returning the GitHub user.

func (*Auth) Username

func (auth *Auth) Username() string

Username is returning the username.

type Client

type Client struct {
	Gists         *GistsService
	Issues        *IssuesService
	Organizations *OrganizationsService
	Pulls         *PullsService
	RateLimits    *RateLimitsService
	Repos         *ReposService
	Search        *SearchService
	Users         *UsersService
	// contains filtered or unexported fields
}

Client is the struct for the lazygithub Client. The ideas for the service based architecture is taken from go-github.

func NewClient

func NewClient() *Client

NewClient is returning a new Client struct.

func (*Client) Auth

func (client *Client) Auth() *Auth

Auth is returning the Auth struct.

func (*Client) Authenticate

func (client *Client) Authenticate() error

Authenticate doing the authentication against GitHub and setting the Client which should be used. This can be either an oauth2 http client (when using a token) or a basic auth client (when using a username and password).

func (*Client) Ctx

func (client *Client) Ctx() context.Context

Ctx is returning the context.

func (*Client) GitHub

func (client *Client) GitHub() *githubV3.Client

GitHub is returning the GitHub client.

func (*Client) SetAnonymous

func (client *Client) SetAnonymous(anonymous bool) *Client

SetAnonymous is invalidating all credentials and setting the GitHub client to a new and empty one.

func (*Client) SetAuth

func (client *Client) SetAuth(auth *Auth) *Client

SetAuth is setting the authentication details for the GitHub client. Authenticate should be called to load and validate new values.

func (*Client) SetCtx

func (client *Client) SetCtx(ctx context.Context) *Client

SetCtx is setting the context.

func (*Client) SetGitHubClient

func (client *Client) SetGitHubClient(ghclient *githubV3.Client) *Client

SetGitHubClient is setting the client for GitHub.

type Gist

type Gist struct {
	*githubV3.Gist
}

Gist represents a GitHub gist.

type Gists

type Gists []Gist

Gists represents multiple GitHub gists.

func (Gists) Filter

func (gists Gists) Filter(filters []string) Gists

Filter filters gists based on one or more strings which can be a RegExp.

func (Gists) MaxLen

func (gists Gists) MaxLen() (int, int)

MaxLen is getting the maximum length of the file name in Gists.

type GistsService

type GistsService Service

GistsService handles all gists related communication.

func (*GistsService) ByUser

func (s *GistsService) ByUser(userStr string, limit int) (Gists, error)

ByUser is getting gists for a user.

type Issue

type Issue struct {
	githubV3.Issue
}

Issue represents a GitHub issue.

func (Issue) GetFullRepoName

func (issue Issue) GetFullRepoName() string

GetFullRepoName is a wrapper for issues which don't have a valid repo.

func (Issue) GetFullRepoNameLen

func (issue Issue) GetFullRepoNameLen() int

GetFullRepoNameLen is a wrapper to get the count of the full repo name.

func (Issue) GetTitleLen

func (issue Issue) GetTitleLen() int

GetTitleLen is getting the count of the title.

type Issues

type Issues []Issue

Issues represents multiple GitHub issues.

func (Issues) Filter

func (issues Issues) Filter(filters []string) Issues

Filter filters issues based on one or more strings which can be a RegExp.

func (Issues) MaxLen

func (issues Issues) MaxLen() (int, int, int, int, bool)

MaxLen is getting the maximum length of the comments, number, repository and title in Issues.

func (Issues) OrderBy

func (issues Issues) OrderBy(orderBy string) Issues

OrderBy orders issues based on a field.

type IssuesService

type IssuesService Service

IssuesService handles all issues related communication.

func (*IssuesService) ListByAuthenticatedUser

func (s *IssuesService) ListByAuthenticatedUser(all bool, filter string, state string, orderBy string, limit int) (Issues, error)

ListByAuthenticatedUser is getting issues for the authenticated user.

func (*IssuesService) ListByRepo

func (s *IssuesService) ListByRepo(userStr string, repoStr string, state string, orderBy string, limit int) (Issues, error)

ListByRepo is getting issues from a repo.

type LocalRepo

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

LocalRepo is the struct for a local git repo.

func NewLocalRepo

func NewLocalRepo() *LocalRepo

NewLocalRepo is returning a new LocalRepo struct.

func (*LocalRepo) Name

func (lgr *LocalRepo) Name() string

Name is returning the name of the local git repo.

func (*LocalRepo) Path

func (lgr *LocalRepo) Path() string

Path is returning the path of the local git repo.

func (*LocalRepo) SetName

func (lgr *LocalRepo) SetName(name string) *LocalRepo

SetName is setting the name of the local git repo.

func (*LocalRepo) SetPath

func (lgr *LocalRepo) SetPath(path string) *LocalRepo

SetPath is setting the path of the local git repo.

type LocalRepoScanner

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

LocalRepoScanner is the struct for the local git repo scanner.

func NewLocalRepoScanner

func NewLocalRepoScanner() *LocalRepoScanner

NewLocalRepoScanner is returning a new LocalRepoScanner struct.

func (*LocalRepoScanner) Scan

func (lgrs *LocalRepoScanner) Scan() (LocalRepos, error)

Scan is scanning for local git repos.

func (*LocalRepoScanner) SetWD

func (lgrs *LocalRepoScanner) SetWD(wd string) *LocalRepoScanner

SetWD is setting the working directory of the local git repo scanner.

func (*LocalRepoScanner) WD

func (lgrs *LocalRepoScanner) WD() string

WD is returning the working directory of the local git repo scanner.

type LocalRepos

type LocalRepos []LocalRepo

LocalRepos represents multiple local git repos.

var NullLocalRepos LocalRepos

NullLocalRepos is an empty local git repo scanner.

func (LocalRepos) Filter

func (repos LocalRepos) Filter(filters []string) LocalRepos

Filter filters repos based on one or more strings which can be a RegExp.

type Organization

type Organization struct {
	*githubV3.Organization
}

Organization represents a GitHub organization.

var (
	ErrOrganizationNotFound = errors.New("Can not find organization")
	NullOrganization        Organization
)

ErrOrgNotFound is the error when an organization can't be found. NullOrganization an empty response if no GitHub organization is present.

type OrganizationsService

type OrganizationsService Service

OrganizationsService handles all user related communication.

func (*OrganizationsService) Get

func (s *OrganizationsService) Get(orgStr string) (Organization, error)

Get is getting a organization.

type Pull

type Pull struct {
	githubV3.PullRequest
}

Pull represents a GitHub pull request.

func (Pull) GetFullRepoName

func (pr Pull) GetFullRepoName() string

GetFullRepoName is a wrapper to get the full repo name.

func (Pull) GetFullRepoNameLen

func (pr Pull) GetFullRepoNameLen() int

GetFullRepoNameLen is a wrapper to get the count of the full repo name.

func (Pull) GetTitleLen

func (pr Pull) GetTitleLen() int

GetTitleLen is getting the count of the title.

type Pulls

type Pulls []Pull

Pulls represents multiple GitHub pull requests.

func (Pulls) Filter

func (pulls Pulls) Filter(filters []string) Pulls

Filter filters pulls based on one or more strings which can be a RegExp.

func (Pulls) MaxLen

func (pulls Pulls) MaxLen() (int, int, int, int, bool)

MaxLen is getting the maximum length of the comments, number, repository and title in Pulls. It's also checking there are closed pulls which will impact the view.

func (Pulls) OrderBy

func (pulls Pulls) OrderBy(orderBy string) Pulls

OrderBy orders pulls based on a field.

type PullsService

type PullsService Service

PullsService handles all pull requests related communication.

func (*PullsService) Get

func (s *PullsService) Get(userStr string, repoStr string, number int) (Pull, error)

Get is getting a single pull.

func (*PullsService) List

func (s *PullsService) List(userStr string, repoStr string, state string, orderBy string, limit int) (Pulls, error)

List is getting pulls from a repo.

type RateLimits

type RateLimits struct {
	githubV3.RateLimits
}

RateLimits represents GitHub rate limits.

var (
	ErrCanNotGetRateLimits = errors.New("Can not get rate limits")
	NullRateLimits         RateLimits
)

ErrCanNotGetRateLimits is the error when rates limits can't be queried. NullRateLimits is an empty response if no GitHub rate limits are present.

type RateLimitsService

type RateLimitsService Service

RateLimitsService handles all rate limits related communication.

func (*RateLimitsService) Get

func (s *RateLimitsService) Get() (RateLimits, error)

Get is getting the rate limits information.

type Repo

type Repo struct {
	*githubV3.Repository
}

Repo represents a GitHub repo.

type Repos

type Repos []Repo

Repos represents multiple GitHub repos.

func (Repos) Filter

func (repos Repos) Filter(filters []string) Repos

Filter filters repos based on one or more strings which can be a RegExp.

func (Repos) MaxLen

func (repos Repos) MaxLen() (int, int, bool)

MaxLen is getting the maximum length of the repository (full name and name) in Repos. It's also checking if there are private repositories which will impact the view.

func (Repos) OrderBy

func (repos Repos) OrderBy(orderBy string) Repos

OrderBy orders issues based on a field.

type ReposService

type ReposService Service

ReposService handles all repositories related communication.

func (*ReposService) Get

func (s *ReposService) Get(userStr string, repoStr string) (Repo, error)

Get is getting a single repo.

func (*ReposService) ListByOrg

func (s *ReposService) ListByOrg(orgStr string, visibility string, orderBy string, limit int) (Repos, error)

ListByOrg is getting repos for an organization.

func (*ReposService) ListByUser

func (s *ReposService) ListByUser(userStr string, repoType string, visibility string, orderBy string, limit int) (Repos, error)

ListByUser is getting repos for an user.

type SearchService

type SearchService Service

SearchService handles all search related communication.

func (*SearchService) IssuesByUser

func (s *SearchService) IssuesByUser(userStr string, filter string, state string, orderBy string, limit int) (Issues, error)

IssuesByUser is searching for issues for a user.

func (*SearchService) PullsByUser

func (s *SearchService) PullsByUser(userStr string, state string, filter string, orderBy string, limit int) (Pulls, error)

PullsByUser is searching for pulls for a user.

type Service

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

Service is the struct for the generic service.

type User

type User struct {
	*githubV3.User
}

User represents a GitHub user.

var (
	ErrUserNotFound = errors.New("Can not find user")
	NullUser        User
)

ErrUserNotFound is the error when a user can't be found. NullUser is an empty response if no GitHub user is present.

func (User) GetGistsHTMLURL

func (user User) GetGistsHTMLURL() string

GetGistsHTMLURL returns the Gists URL for an GitHub user.

type UsersService

type UsersService Service

UsersService handles all user related communication.

func (*UsersService) Get

func (s *UsersService) Get(userStr string) (User, error)

Get is getting a user.

Jump to

Keyboard shortcuts

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