api

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 23 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IssueFields = []string{
	"assignees",
	"author",
	"body",
	"closed",
	"comments",
	"createdAt",
	"closedAt",
	"id",
	"labels",
	"milestone",
	"number",
	"projectCards",
	"reactionGroups",
	"state",
	"title",
	"updatedAt",
	"url",
}
View Source
var PullRequestFields = append(IssueFields,
	"additions",
	"baseRefName",
	"changedFiles",
	"commits",
	"deletions",
	"files",
	"headRefName",
	"headRepository",
	"headRepositoryOwner",
	"isCrossRepository",
	"isDraft",
	"maintainerCanModify",
	"mergeable",
	"mergeCommit",
	"mergedAt",
	"mergedBy",
	"mergeStateStatus",
	"potentialMergeCommit",
	"reviewDecision",
	"reviewRequests",
	"reviews",
	"statusCheckRollup",
)
View Source
var RepositoryFields = []string{
	"id",
	"name",
	"nameWithOwner",
	"owner",
	"parent",
	"templateRepository",
	"description",
	"homepageUrl",
	"openGraphImageUrl",
	"usesCustomOpenGraphImage",
	"url",
	"sshUrl",
	"mirrorUrl",
	"securityPolicyUrl",

	"createdAt",
	"pushedAt",
	"updatedAt",

	"isBlankIssuesEnabled",
	"isSecurityPolicyEnabled",
	"hasIssuesEnabled",
	"hasProjectsEnabled",
	"hasWikiEnabled",
	"mergeCommitAllowed",
	"squashMergeAllowed",
	"rebaseMergeAllowed",

	"forkCount",
	"stargazerCount",
	"watchers",
	"issues",
	"pullRequests",

	"codeOfConduct",
	"contactLinks",
	"defaultBranchRef",
	"deleteBranchOnMerge",
	"diskUsage",
	"fundingLinks",
	"isArchived",
	"isEmpty",
	"isFork",
	"isInOrganization",
	"isMirror",
	"isPrivate",
	"isTemplate",
	"isUserConfigurationRepository",
	"licenseInfo",
	"viewerCanAdminister",
	"viewerDefaultCommitEmail",
	"viewerDefaultMergeMethod",
	"viewerHasStarred",
	"viewerPermission",
	"viewerPossibleCommitEmails",
	"viewerSubscription",

	"repositoryTopics",
	"primaryLanguage",
	"languages",
	"issueTemplates",
	"pullRequestTemplates",
	"labels",
	"milestones",
	"latestRelease",

	"assignableUsers",
	"mentionableUsers",
	"projects",
}

Functions

func CanPushToRepo

func CanPushToRepo(httpClient *http.Client, repo ghrepo.Interface) (bool, 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 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 PullRequestGraphQL

func PullRequestGraphQL(fields []string) string

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 RepositoryGraphQL

func RepositoryGraphQL(fields []string) string

func StatusCheckRollupGraphQL

func StatusCheckRollupGraphQL(after string) string

Types

type BranchRef

type BranchRef struct {
	Name string `json:"name"`
}

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) 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 CodeOfConduct

type CodeOfConduct struct {
	Key  string `json:"key"`
	Name string `json:"name"`
	URL  string `json:"url"`
}

type CodingLanguage

type CodingLanguage struct {
	Name string `json:"name"`
}
type ContactLink struct {
	About string `json:"about"`
	Name  string `json:"name"`
	URL   string `json:"url"`
}
type FundingLink struct {
	Platform string `json:"platform"`
	URL      string `json:"url"`
}

type GitHubUser

type GitHubUser struct {
	ID    string `json:"id"`
	Login string `json:"login"`
	Name  string `json:"name"`
}

type GraphQLError

type GraphQLError struct {
	Type    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 IssueLabel

type IssueLabel struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Color       string `json:"color"`
}

type IssueTemplate

type IssueTemplate struct {
	Name  string `json:"name"`
	Title string `json:"title"`
	Body  string `json:"body"`
	About string `json:"about"`
}

type License

type License struct {
	Key  string `json:"key"`
	Name string `json:"name"`
}

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 PullRequestTemplate

type PullRequestTemplate struct {
	Filename string `json:"filename"`
	Body     string `json:"body"`
}

type ReactionGroup

type ReactionGroup struct {
	Content string             `json:"content"`
	Users   ReactionGroupUsers `json:"users"`
}

func (ReactionGroup) Count

func (rg ReactionGroup) Count() int

func (ReactionGroup) Emoji

func (rg ReactionGroup) Emoji() string

type ReactionGroupUsers

type ReactionGroupUsers struct {
	TotalCount int `json:"totalCount"`
}

type ReactionGroups

type ReactionGroups []ReactionGroup

func (ReactionGroups) MarshalJSON

func (rg ReactionGroups) MarshalJSON() ([]byte, error)

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 `json:"id"`
	Name         string `json:"name"`
	Number       int    `json:"number"`
	ResourcePath string `json:"resourcePath"`
}

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
	NameWithOwner            string
	Owner                    RepositoryOwner
	Parent                   *Repository
	TemplateRepository       *Repository
	Description              string
	HomepageURL              string
	OpenGraphImageURL        string
	UsesCustomOpenGraphImage bool
	URL                      string
	SSHURL                   string
	MirrorURL                string
	SecurityPolicyURL        string

	CreatedAt time.Time
	PushedAt  *time.Time
	UpdatedAt time.Time

	IsBlankIssuesEnabled    bool
	IsSecurityPolicyEnabled bool
	HasIssuesEnabled        bool
	HasProjectsEnabled      bool
	HasWikiEnabled          bool
	MergeCommitAllowed      bool
	SquashMergeAllowed      bool
	RebaseMergeAllowed      bool

	ForkCount      int
	StargazerCount int
	Watchers       struct {
		TotalCount int `json:"totalCount"`
	}

	Issues struct {
		TotalCount int `json:"totalCount"`
	}

	PullRequests struct {
		TotalCount int `json:"totalCount"`
	}

	CodeOfConduct                 *CodeOfConduct
	ContactLinks                  []ContactLink
	DefaultBranchRef              BranchRef
	DeleteBranchOnMerge           bool
	DiskUsage                     int
	FundingLinks                  []FundingLink
	IsArchived                    bool
	IsEmpty                       bool
	IsFork                        bool
	IsInOrganization              bool
	IsMirror                      bool
	IsPrivate                     bool
	IsTemplate                    bool
	IsUserConfigurationRepository bool
	LicenseInfo                   *RepositoryLicense
	ViewerCanAdminister           bool
	ViewerDefaultCommitEmail      string
	ViewerDefaultMergeMethod      string
	ViewerHasStarred              bool
	ViewerPermission              string
	ViewerPossibleCommitEmails    []string
	ViewerSubscription            string

	RepositoryTopics struct {
		Nodes []struct {
			Topic RepositoryTopic
		}
	}
	PrimaryLanguage *CodingLanguage
	Languages       struct {
		Edges []struct {
			Size int            `json:"size"`
			Node CodingLanguage `json:"node"`
		}
	}
	IssueTemplates       []IssueTemplate
	PullRequestTemplates []PullRequestTemplate
	Labels               struct {
		Nodes []IssueLabel
	}
	// Milestones struct {
	// 	Nodes []Milestone
	// }
	LatestRelease *RepositoryRelease

	AssignableUsers struct {
		Nodes []GitHubUser
	}
	MentionableUsers struct {
		Nodes []GitHubUser
	}
	Projects struct {
		Nodes []RepoProject
	}
	// contains filtered or unexported fields
}

Repository contains information about a GitHub repo

func CreateRepoTransformToV4

func CreateRepoTransformToV4(apiClient *Client, hostname string, method string, path string, body io.Reader) (*Repository, error)

func ForkRepo

func ForkRepo(client *Client, repo ghrepo.Interface, org string) (*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) 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 RepositoryLicense

type RepositoryLicense struct {
	Key      string `json:"key"`
	Name     string `json:"name"`
	Nickname string `json:"nickname"`
}

type RepositoryOwner

type RepositoryOwner struct {
	ID    string `json:"id"`
	Login string `json:"login"`
}

RepositoryOwner is the owner of a GitHub repository

type RepositoryRelease

type RepositoryRelease struct {
	Name        string    `json:"name"`
	TagName     string    `json:"tagName"`
	URL         string    `json:"url"`
	PublishedAt time.Time `json:"publishedAt"`
}

type RepositoryTopic

type RepositoryTopic struct {
	Name string `json:"name"`
}

Jump to

Keyboard shortcuts

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