api

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: MIT Imports: 19 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddReview added in v0.8.0

func AddReview(client *Client, pr *PullRequest, input *PullRequestReviewInput) error

func BranchDeleteRemote added in v0.9.0

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

func CurrentLoginName added in v0.10.0

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

func IssueClose added in v0.8.0

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

func IssueReopen added in v0.8.0

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

func NewHTTPClient added in v0.10.0

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

NewHTTPClient initializes an http.Client

func PullRequestClose added in v0.8.0

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

func PullRequestMerge added in v0.9.0

func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m PullRequestMergeMethod) error

func PullRequestReady added in v0.9.0

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

func PullRequestReopen added in v0.8.0

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

func RepoDefaultBranch added in v0.11.0

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

func RepoParent added in v0.6.3

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

RepoParent finds out the parent repository of a fork

func RepositoryReadme added in v0.6.3

func RepositoryReadme(client *Client, fullName string) (string, error)

Types

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 (Client) GraphQL

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

GraphQL performs a GraphQL request and parses the response

func (Client) HasScopes added in v0.9.0

func (c Client) HasScopes(wantedScopes ...string) (bool, string, error)

Returns whether or not scopes are present, appID, and error

func (Client) PullRequestDiff added in v0.9.0

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

func (Client) REST

func (c Client) REST(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 added in v0.8.0

func AddHeaderFunc(name string, value func() string) ClientOption

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

func CheckScopes added in v0.8.0

func CheckScopes(wantedScope string, cb func(string) error) ClientOption

CheckScopes checks whether an OAuth scope is present in a response

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 Gist added in v0.9.0

type Gist struct {
	Description string                    `json:"description,omitempty"`
	Public      bool                      `json:"public,omitempty"`
	Files       map[GistFilename]GistFile `json:"files,omitempty"`
	HTMLURL     string                    `json:"html_url,omitempty"`
}

Gist represents a GitHub's gist.

func GistCreate added in v0.9.0

func GistCreate(client *Client, description string, public bool, files map[string]string) (*Gist, error)

Create a gist for authenticated user.

GitHub API docs: https://developer.github.com/v3/gists/#create-a-gist

type GistFile added in v0.9.0

type GistFile struct {
	Content string `json:"content,omitempty"`
}

type GistFilename added in v0.9.0

type GistFilename string

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 added in v0.11.0

type HTTPError struct {
	StatusCode int
	RequestURL *url.URL
	Message    string
}

HTTPError is an error returned by a failed API call

func (HTTPError) Error added in v0.11.0

func (err HTTPError) Error() 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  struct {
		TotalCount int
	}
	Author struct {
		Login string
	}
	Assignees struct {
		Nodes []struct {
			Login string
		}
		TotalCount int
	}
	Labels struct {
		Nodes []struct {
			Name string
		}
		TotalCount int
	}
	ProjectCards struct {
		Nodes []struct {
			Project struct {
				Name string
			}
			Column struct {
				Name string
			}
		}
		TotalCount int
	}
	Milestone struct {
		Title string
	}
}

Ref. https://developer.github.com/v4/object/issue/

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

type IssuesAndTotalCount

type IssuesAndTotalCount struct {
	Issues     []Issue
	TotalCount int
}

func IssueList

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

type IssuesDisabledError added in v0.8.0

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 NotFoundError

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

type OrgTeam added in v0.8.0

type OrgTeam struct {
	ID   string
	Slug string
}

func OrganizationTeams added in v0.8.0

func OrganizationTeams(client *Client, owner string) ([]OrgTeam, error)

OrganizationTeams fetches all the teams in an organization

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

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

	ReviewDecision string

	Commits struct {
		TotalCount int
		Nodes      []struct {
			Commit struct {
				StatusCheckRollup struct {
					Contexts struct {
						Nodes []struct {
							State      string
							Status     string
							Conclusion string
						}
					}
				}
			}
		}
	}
	ReviewRequests struct {
		Nodes []struct {
			RequestedReviewer struct {
				TypeName string `json:"__typename"`
				Login    string
				Name     string
			}
		}
		TotalCount int
	}
	Reviews struct {
		Nodes []struct {
			Author struct {
				Login string
			}
			State string
		}
	}
	Assignees struct {
		Nodes []struct {
			Login string
		}
		TotalCount int
	}
	Labels struct {
		Nodes []struct {
			Name string
		}
		TotalCount int
	}
	ProjectCards struct {
		Nodes []struct {
			Project struct {
				Name string
			}
			Column struct {
				Name string
			}
		}
		TotalCount int
	}
	Milestone struct {
		Title string
	}
}

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) (*PullRequest, error)

func (*PullRequest) ChecksStatus

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

func (PullRequest) HeadLabel

func (pr PullRequest) HeadLabel() string

func (*PullRequest) ReviewStatus

func (pr *PullRequest) ReviewStatus() PullRequestReviewStatus

type PullRequestAndTotalCount

type PullRequestAndTotalCount struct {
	TotalCount   int
	PullRequests []PullRequest
}

func PullRequestList

func PullRequestList(client *Client, vars map[string]interface{}, limit int) (*PullRequestAndTotalCount, error)

type PullRequestChecksStatus

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

type PullRequestMergeMethod added in v0.9.0

type PullRequestMergeMethod int
const (
	PullRequestMergeMethodMerge PullRequestMergeMethod = iota
	PullRequestMergeMethodRebase
	PullRequestMergeMethodSquash
)

type PullRequestReviewInput added in v0.8.0

type PullRequestReviewInput struct {
	Body  string
	State PullRequestReviewState
}

type PullRequestReviewState added in v0.8.0

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

type PullRequestReviewStatus

type PullRequestReviewStatus struct {
	ChangesRequested bool
	Approved         bool
	ReviewRequired   bool
}

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 RepoAssignee added in v0.8.0

type RepoAssignee struct {
	ID    string
	Login string
}

func RepoAssignableUsers added in v0.8.0

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

RepoAssignableUsers fetches all the assignable users for a repository

type RepoCreateInput added in v0.6.0

type RepoCreateInput struct {
	Name        string `json:"name"`
	Visibility  string `json:"visibility"`
	HomepageURL string `json:"homepageUrl,omitempty"`
	Description string `json:"description,omitempty"`

	OwnerID string `json:"ownerId,omitempty"`
	TeamID  string `json:"teamId,omitempty"`

	HasIssuesEnabled bool `json:"hasIssuesEnabled"`
	HasWikiEnabled   bool `json:"hasWikiEnabled"`
}

RepoCreateInput represents input parameters for RepoCreate

type RepoLabel added in v0.8.0

type RepoLabel struct {
	ID   string
	Name string
}

func RepoLabels added in v0.8.0

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

RepoLabels fetches all the labels in a repository

type RepoMetadataInput added in v0.8.0

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

type RepoMetadataResult added in v0.8.0

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

func RepoMetadata added in v0.8.0

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 added in v0.9.0

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

RepoResolveMetadataIDs looks up GraphQL node IDs in bulk

func (*RepoMetadataResult) LabelsToIDs added in v0.8.0

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

func (*RepoMetadataResult) MembersToIDs added in v0.8.0

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

func (*RepoMetadataResult) MilestoneToID added in v0.8.0

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

func (*RepoMetadataResult) ProjectsToIDs added in v0.8.0

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

func (*RepoMetadataResult) TeamsToIDs added in v0.8.0

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

type RepoMilestone added in v0.8.0

type RepoMilestone struct {
	ID    string
	Title string
}

func RepoMilestones added in v0.8.0

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

RepoMilestones fetches all open 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 added in v0.8.0

type RepoProject struct {
	ID   string
	Name string
}

func OrganizationProjects added in v0.8.0

func OrganizationProjects(client *Client, owner string) ([]RepoProject, error)

OrganizationProjects fetches all open projects for an organization

func RepoProjects added in v0.8.0

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

RepoProjects fetches all open projects for a repository

type RepoResolveInput added in v0.9.0

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
	ViewerPermission string
	DefaultBranchRef struct {
		Name string
	}

	Parent *Repository
	// 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 RepoCreate added in v0.6.0

func RepoCreate(client *Client, input RepoCreateInput) (*Repository, error)

RepoCreate creates a new GitHub repository

func RepoFindFork added in v0.6.3

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

RepoFindFork finds a fork of repo 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 added in v0.11.0

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 added in v0.8.0

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

Jump to

Keyboard shortcuts

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