api

package
v0.0.0-...-f5432ee Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddReview

func AddReview(client *Client, repo ghrepo.Interface, pr *PullRequest, input *PullRequestReviewInput) error

func BranchDeleteRemote

func BranchDeleteRemote(client *Client, repo ghrepo.Interface, branch string) error

func CanPushToRepo

func CanPushToRepo(httpClient *http.Client, repo ghrepo.Interface) (bool, error)

func CommentCreate

func CommentCreate(client *Client, repoHost string, params CommentCreateInput) (string, error)

func CurrentLoginName

func CurrentLoginName(client *Client, hostname string) (string, error)

func CurrentUserID

func CurrentUserID(client *Client, hostname string) (string, error)

func HandleHTTPError

func HandleHTTPError(resp *http.Response) error

func IssueClose

func IssueClose(client *Client, repo ghrepo.Interface, issue Issue) error

func IssueDelete

func IssueDelete(client *Client, repo ghrepo.Interface, issue Issue) error

func IssueReopen

func IssueReopen(client *Client, repo ghrepo.Interface, issue Issue) error

func IssueUpdate

func IssueUpdate(client *Client, repo ghrepo.Interface, params githubv4.UpdateIssueInput) error

func NewCachedClient

func NewCachedClient(httpClient *http.Client, cacheTTL time.Duration) *http.Client

func NewHTTPClient

func NewHTTPClient(opts ...ClientOption) *http.Client

NewHTTPClient initializes an http.Client

func ProjectNamesToPaths

func ProjectNamesToPaths(client *Client, repo ghrepo.Interface, projectNames []string) ([]string, error)

func ProjectsToPaths

func ProjectsToPaths(projects []RepoProject, names []string) ([]string, error)

func PullRequestClose

func PullRequestClose(client *Client, repo ghrepo.Interface, pr *PullRequest) error

func PullRequestReady

func PullRequestReady(client *Client, repo ghrepo.Interface, pr *PullRequest) error

func PullRequestReopen

func PullRequestReopen(client *Client, repo ghrepo.Interface, pr *PullRequest) error

func RepoDefaultBranch

func RepoDefaultBranch(client *Client, repo ghrepo.Interface) (string, error)

func RepoParent

func RepoParent(client *Client, repo ghrepo.Interface) (ghrepo.Interface, error)

RepoParent finds out the parent repository of a fork

func UpdatePullRequest

func UpdatePullRequest(client *Client, repo ghrepo.Interface, params githubv4.UpdatePullRequestInput) error

func UpdatePullRequestReviews

func UpdatePullRequestReviews(client *Client, repo ghrepo.Interface, params githubv4.RequestReviewsInput) error

Types

type Assignees

type Assignees struct {
	Nodes []struct {
		Login string
	}
	TotalCount int
}

func (Assignees) Logins

func (a Assignees) Logins() []string

type Author

type Author struct {
	Login string
}

type BranchRef

type BranchRef struct {
	Name string
}

BranchRef is the branch name in a GitHub repository

type Client

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

Client facilitates making HTTP requests to the GitHub API

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient initializes a Client

func NewClientFromHTTP

func NewClientFromHTTP(httpClient *http.Client) *Client

NewClientFromHTTP takes in an http.Client instance

func (Client) GraphQL

func (c Client) GraphQL(hostname string, query string, variables map[string]interface{}, data interface{}) error

GraphQL performs a GraphQL request and parses the response

func (*Client) HTTP

func (c *Client) HTTP() *http.Client

func (Client) PullRequestDiff

func (c Client) PullRequestDiff(baseRepo ghrepo.Interface, prNumber int) (io.ReadCloser, error)

func (Client) REST

func (c Client) REST(hostname string, method string, p string, body io.Reader, data interface{}) error

REST performs a REST request and parses the response.

type ClientOption

type ClientOption = func(http.RoundTripper) http.RoundTripper

ClientOption represents an argument to NewClient

func AddHeader

func AddHeader(name, value string) ClientOption

AddHeader turns a RoundTripper into one that adds a request header

func AddHeaderFunc

func AddHeaderFunc(name string, getValue func(*http.Request) (string, error)) ClientOption

AddHeaderFunc is an AddHeader that gets the string value from a function

func CacheResponse

func CacheResponse(ttl time.Duration, dir string) ClientOption

CacheResponse produces a RoundTripper that caches HTTP responses to disk for a specified amount of time

func ReplaceTripper

func ReplaceTripper(tr http.RoundTripper) ClientOption

ReplaceTripper substitutes the underlying RoundTripper with a custom one

func VerboseLog

func VerboseLog(out io.Writer, logTraffic bool, colorize bool) ClientOption

VerboseLog enables request/response logging within a RoundTripper

type Comment

type Comment struct {
	Author              Author
	AuthorAssociation   string
	Body                string
	CreatedAt           time.Time
	IncludesCreatedEdit bool
	IsMinimized         bool
	MinimizedReason     string
	ReactionGroups      ReactionGroups
}

func (Comment) Association

func (c Comment) Association() string

func (Comment) AuthorLogin

func (c Comment) AuthorLogin() string

func (Comment) Content

func (c Comment) Content() string

func (Comment) Created

func (c Comment) Created() time.Time

func (Comment) HiddenReason

func (c Comment) HiddenReason() string

func (Comment) IsEdited

func (c Comment) IsEdited() bool

func (Comment) IsHidden

func (c Comment) IsHidden() bool
func (c Comment) Link() string

func (Comment) Reactions

func (c Comment) Reactions() ReactionGroups

func (Comment) Status

func (c Comment) Status() string

type CommentCreateInput

type CommentCreateInput struct {
	Body      string
	SubjectId string
}

type Comments

type Comments struct {
	Nodes      []Comment
	TotalCount int
	PageInfo   PageInfo
}

func CommentsForIssue

func CommentsForIssue(client *Client, repo ghrepo.Interface, issue *Issue) (*Comments, error)

func CommentsForPullRequest

func CommentsForPullRequest(client *Client, repo ghrepo.Interface, pr *PullRequest) (*Comments, error)

type GraphQLError

type GraphQLError struct {
	Type    string
	Path    []string
	Message string
}

GraphQLError is a single error returned in a GraphQL response

type GraphQLErrorResponse

type GraphQLErrorResponse struct {
	Errors []GraphQLError
}

GraphQLErrorResponse contains errors returned in a GraphQL response

func (GraphQLErrorResponse) Error

func (gr GraphQLErrorResponse) Error() string

type HTTPError

type HTTPError struct {
	StatusCode  int
	RequestURL  *url.URL
	Message     string
	OAuthScopes string
	Errors      []HTTPErrorItem
}

HTTPError is an error returned by a failed API call

func (HTTPError) Error

func (err HTTPError) Error() string

type HTTPErrorItem

type HTTPErrorItem struct {
	Message  string
	Resource string
	Field    string
	Code     string
}

type Issue

type Issue struct {
	ID             string
	Number         int
	Title          string
	URL            string
	State          string
	Closed         bool
	Body           string
	CreatedAt      time.Time
	UpdatedAt      time.Time
	Comments       Comments
	Author         Author
	Assignees      Assignees
	Labels         Labels
	ProjectCards   ProjectCards
	Milestone      Milestone
	ReactionGroups ReactionGroups
}

func IssueByNumber

func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, error)

func IssueCreate

func IssueCreate(client *Client, repo *Repository, params map[string]interface{}) (*Issue, error)

IssueCreate creates an issue in a GitHub repository

func (Issue) Identifier

func (i Issue) Identifier() string
func (i Issue) Link() string

type IssuesAndTotalCount

type IssuesAndTotalCount struct {
	Issues     []Issue
	TotalCount int
}

func IssueList

func IssueList(client *Client, repo ghrepo.Interface, state string, assigneeString string, limit int, authorString string, mentionString string, milestoneString string) (*IssuesAndTotalCount, error)

func IssueSearch

func IssueSearch(client *Client, repo ghrepo.Interface, searchQuery string, limit int) (*IssuesAndTotalCount, error)

type IssuesDisabledError

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

type IssuesPayload

type IssuesPayload struct {
	Assigned  IssuesAndTotalCount
	Mentioned IssuesAndTotalCount
	Authored  IssuesAndTotalCount
}

func IssueStatus

func IssueStatus(client *Client, repo ghrepo.Interface, currentUsername string) (*IssuesPayload, error)

type Labels

type Labels struct {
	Nodes []struct {
		Name string
	}
	TotalCount int
}

func (Labels) Names

func (l Labels) Names() []string

type Milestone

type Milestone struct {
	Title string
}

type NotFoundError

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

func (*NotFoundError) Unwrap

func (err *NotFoundError) Unwrap() error

type OrgTeam

type OrgTeam struct {
	ID   string
	Slug string
}

func OrganizationTeams

func OrganizationTeams(client *Client, repo ghrepo.Interface) ([]OrgTeam, error)

OrganizationTeams fetches all the teams in an organization

type PageInfo

type PageInfo struct {
	HasNextPage bool
	EndCursor   string
}

type ProjectCards

type ProjectCards struct {
	Nodes []struct {
		Project struct {
			Name string
		}
		Column struct {
			Name string
		}
	}
	TotalCount int
}

func (ProjectCards) ProjectNames

func (p ProjectCards) ProjectNames() []string

type PullRequest

type PullRequest struct {
	ID               string
	Number           int
	Title            string
	State            string
	Closed           bool
	URL              string
	BaseRefName      string
	HeadRefName      string
	Body             string
	Mergeable        string
	Additions        int
	Deletions        int
	MergeStateStatus string

	Author struct {
		Login string
	}
	HeadRepositoryOwner struct {
		Login string
	}
	HeadRepository struct {
		Name             string
		DefaultBranchRef struct {
			Name string
		}
	}
	IsCrossRepository   bool
	IsDraft             bool
	MaintainerCanModify bool

	BaseRef struct {
		BranchProtectionRule struct {
			RequiresStrictStatusChecks bool
		}
	}

	ReviewDecision string

	Commits struct {
		TotalCount int
		Nodes      []struct {
			Commit struct {
				Oid               string
				StatusCheckRollup struct {
					Contexts struct {
						Nodes []struct {
							Name        string
							Context     string
							State       string
							Status      string
							Conclusion  string
							StartedAt   time.Time
							CompletedAt time.Time
							DetailsURL  string
							TargetURL   string
						}
					}
				}
			}
		}
	}
	Assignees      Assignees
	Labels         Labels
	ProjectCards   ProjectCards
	Milestone      Milestone
	Comments       Comments
	ReactionGroups ReactionGroups
	Reviews        PullRequestReviews
	ReviewRequests ReviewRequests
}

func CreatePullRequest

func CreatePullRequest(client *Client, repo *Repository, params map[string]interface{}) (*PullRequest, error)

CreatePullRequest creates a pull request in a GitHub repository

func PullRequestByNumber

func PullRequestByNumber(client *Client, repo ghrepo.Interface, number int) (*PullRequest, error)

func PullRequestForBranch

func PullRequestForBranch(client *Client, repo ghrepo.Interface, baseBranch, headBranch string, stateFilters []string) (*PullRequest, error)

func (*PullRequest) ChecksStatus

func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus)

func (*PullRequest) DisplayableReviews

func (pr *PullRequest) DisplayableReviews() PullRequestReviews

func (PullRequest) HeadLabel

func (pr PullRequest) HeadLabel() string

func (PullRequest) Identifier

func (pr PullRequest) Identifier() string
func (pr PullRequest) Link() string

func (*PullRequest) ReviewStatus

func (pr *PullRequest) ReviewStatus() PullRequestReviewStatus

type PullRequestAndTotalCount

type PullRequestAndTotalCount struct {
	TotalCount   int
	PullRequests []PullRequest
}

type PullRequestChecksStatus

type PullRequestChecksStatus struct {
	Pending int
	Failing int
	Passing int
	Total   int
}

type PullRequestReview

type PullRequestReview struct {
	Author              Author
	AuthorAssociation   string
	Body                string
	CreatedAt           time.Time
	IncludesCreatedEdit bool
	ReactionGroups      ReactionGroups
	State               string
	URL                 string
}

func (PullRequestReview) Association

func (prr PullRequestReview) Association() string

func (PullRequestReview) AuthorLogin

func (prr PullRequestReview) AuthorLogin() string

func (PullRequestReview) Content

func (prr PullRequestReview) Content() string

func (PullRequestReview) Created

func (prr PullRequestReview) Created() time.Time

func (PullRequestReview) HiddenReason

func (prr PullRequestReview) HiddenReason() string

func (PullRequestReview) IsEdited

func (prr PullRequestReview) IsEdited() bool

func (PullRequestReview) IsHidden

func (prr PullRequestReview) IsHidden() bool
func (prr PullRequestReview) Link() string

func (PullRequestReview) Reactions

func (prr PullRequestReview) Reactions() ReactionGroups

func (PullRequestReview) Status

func (prr PullRequestReview) Status() string

type PullRequestReviewInput

type PullRequestReviewInput struct {
	Body  string
	State PullRequestReviewState
}

type PullRequestReviewState

type PullRequestReviewState int
const (
	ReviewApprove PullRequestReviewState = iota
	ReviewRequestChanges
	ReviewComment
)

type PullRequestReviewStatus

type PullRequestReviewStatus struct {
	ChangesRequested bool
	Approved         bool
	ReviewRequired   bool
}

type PullRequestReviews

type PullRequestReviews struct {
	Nodes      []PullRequestReview
	PageInfo   PageInfo
	TotalCount int
}

func ReviewsForPullRequest

func ReviewsForPullRequest(client *Client, repo ghrepo.Interface, pr *PullRequest) (*PullRequestReviews, error)

type PullRequestsPayload

type PullRequestsPayload struct {
	ViewerCreated   PullRequestAndTotalCount
	ReviewRequested PullRequestAndTotalCount
	CurrentPR       *PullRequest
	DefaultBranch   string
}

func PullRequests

func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, currentPRHeadRef, currentUsername string) (*PullRequestsPayload, error)

type ReactionGroup

type ReactionGroup struct {
	Content string
	Users   ReactionGroupUsers
}

func (ReactionGroup) Count

func (rg ReactionGroup) Count() int

func (ReactionGroup) Emoji

func (rg ReactionGroup) Emoji() string

type ReactionGroupUsers

type ReactionGroupUsers struct {
	TotalCount int
}

type ReactionGroups

type ReactionGroups []ReactionGroup

type RepoAssignee

type RepoAssignee struct {
	ID    string
	Login string
}

func RepoAssignableUsers

func RepoAssignableUsers(client *Client, repo ghrepo.Interface) ([]RepoAssignee, error)

RepoAssignableUsers fetches all the assignable users for a repository

type RepoLabel

type RepoLabel struct {
	ID   string
	Name string
}

func RepoLabels

func RepoLabels(client *Client, repo ghrepo.Interface) ([]RepoLabel, error)

RepoLabels fetches all the labels in a repository

type RepoMetadataInput

type RepoMetadataInput struct {
	Assignees  bool
	Reviewers  bool
	Labels     bool
	Projects   bool
	Milestones bool
}

type RepoMetadataResult

type RepoMetadataResult struct {
	AssignableUsers []RepoAssignee
	Labels          []RepoLabel
	Projects        []RepoProject
	Milestones      []RepoMilestone
	Teams           []OrgTeam
}

func RepoMetadata

func RepoMetadata(client *Client, repo ghrepo.Interface, input RepoMetadataInput) (*RepoMetadataResult, error)

RepoMetadata pre-fetches the metadata for attaching to issues and pull requests

func RepoResolveMetadataIDs

func RepoResolveMetadataIDs(client *Client, repo ghrepo.Interface, input RepoResolveInput) (*RepoMetadataResult, error)

RepoResolveMetadataIDs looks up GraphQL node IDs in bulk

func (*RepoMetadataResult) LabelsToIDs

func (m *RepoMetadataResult) LabelsToIDs(names []string) ([]string, error)

func (*RepoMetadataResult) MembersToIDs

func (m *RepoMetadataResult) MembersToIDs(names []string) ([]string, error)

func (*RepoMetadataResult) Merge

func (m *RepoMetadataResult) Merge(m2 *RepoMetadataResult)

func (*RepoMetadataResult) MilestoneToID

func (m *RepoMetadataResult) MilestoneToID(title string) (string, error)

func (*RepoMetadataResult) ProjectsToIDs

func (m *RepoMetadataResult) ProjectsToIDs(names []string) ([]string, error)

func (*RepoMetadataResult) TeamsToIDs

func (m *RepoMetadataResult) TeamsToIDs(names []string) ([]string, error)

type RepoMilestone

type RepoMilestone struct {
	ID    string
	Title string
}

func MilestoneByNumber

func MilestoneByNumber(client *Client, repo ghrepo.Interface, number int32) (*RepoMilestone, error)

func MilestoneByTitle

func MilestoneByTitle(client *Client, repo ghrepo.Interface, state, title string) (*RepoMilestone, error)

func RepoMilestones

func RepoMilestones(client *Client, repo ghrepo.Interface, state string) ([]RepoMilestone, error)

RepoMilestones fetches milestones in a repository

type RepoNetworkResult

type RepoNetworkResult struct {
	ViewerLogin  string
	Repositories []*Repository
}

RepoNetworkResult describes the relationship between related repositories

func RepoNetwork

func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, error)

RepoNetwork inspects the relationship between multiple GitHub repositories

type RepoProject

type RepoProject struct {
	ID           string
	Name         string
	ResourcePath string
}

func OrganizationProjects

func OrganizationProjects(client *Client, repo ghrepo.Interface) ([]RepoProject, error)

OrganizationProjects fetches all open projects for an organization

func RepoAndOrgProjects

func RepoAndOrgProjects(client *Client, repo ghrepo.Interface) ([]RepoProject, error)

RepoAndOrgProjects fetches all open projects for a repository and its org

func RepoProjects

func RepoProjects(client *Client, repo ghrepo.Interface) ([]RepoProject, error)

RepoProjects fetches all open projects for a repository

type RepoResolveInput

type RepoResolveInput struct {
	Assignees  []string
	Reviewers  []string
	Labels     []string
	Projects   []string
	Milestones []string
}

type Repository

type Repository struct {
	ID          string
	Name        string
	Description string
	URL         string
	CloneURL    string
	CreatedAt   time.Time
	Owner       RepositoryOwner

	IsPrivate        bool
	HasIssuesEnabled bool
	HasWikiEnabled   bool
	ViewerPermission string
	DefaultBranchRef BranchRef

	Parent *Repository

	MergeCommitAllowed bool
	RebaseMergeAllowed bool
	SquashMergeAllowed bool
	// contains filtered or unexported fields
}

Repository contains information about a GitHub repo

func ForkRepo

func ForkRepo(client *Client, repo ghrepo.Interface) (*Repository, error)

ForkRepo forks the repository on GitHub and returns the new repository

func GitHubRepo

func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error)

func InitRepoHostname

func InitRepoHostname(repo *Repository, hostname string) *Repository

func RepoFindForks

func RepoFindForks(client *Client, repo ghrepo.Interface, limit int) ([]*Repository, error)

RepoFindForks finds forks of the repo that are affiliated with the viewer

func (Repository) IsFork

func (r Repository) IsFork() bool

IsFork is true when this repository has a parent repository

func (Repository) RepoHost

func (r Repository) RepoHost() string

RepoHost is the GitHub hostname of the repository

func (Repository) RepoName

func (r Repository) RepoName() string

RepoName is the name of the repository

func (Repository) RepoOwner

func (r Repository) RepoOwner() string

RepoOwner is the login name of the owner

func (Repository) ViewerCanPush

func (r Repository) ViewerCanPush() bool

ViewerCanPush is true when the requesting user has push access

func (Repository) ViewerCanTriage

func (r Repository) ViewerCanTriage() bool

ViewerCanTriage is true when the requesting user can triage issues and pull requests

type RepositoryOwner

type RepositoryOwner struct {
	Login string
}

RepositoryOwner is the owner of a GitHub repository

type ReviewRequests

type ReviewRequests struct {
	Nodes []struct {
		RequestedReviewer struct {
			TypeName string `json:"__typename"`
			Login    string
			Name     string
		}
	}
	TotalCount int
}

func (ReviewRequests) Logins

func (r ReviewRequests) Logins() []string

Jump to

Keyboard shortcuts

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