github

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EventGUID is sent by Github in a header of every webhook request.
	// Used as a log field across prow.
	EventGUID = "event-GUID"
	// PrLogField is the number of a PR.
	// Used as a log field across prow.
	PrLogField = "pr"
	// OrgLogField is the organization of a PR.
	// Used as a log field across prow.
	OrgLogField = "org"
	// RepoLogField is the repository of a PR.
	// Used as a log field across prow.
	RepoLogField = "repo"
)
View Source
const (
	StatusPending = "pending"
	StatusSuccess = "success"
	StatusError   = "error"
	StatusFailure = "failure"
)

These are possible State entries for a Status.

View Source
const (
	ReactionThumbsUp   = "+1"
	ReactionThumbsDown = "-1"
	ReactionLaugh      = "laugh"
	ReactionConfused   = "confused"
	ReactionHeart      = "heart"
	ReactionHooray     = "hooray"
)

Possible contents for reactions.

View Source
const (
	// PullRequestActionAssigned means assignees were added.
	PullRequestActionAssigned PullRequestEventAction = "assigned"
	// PullRequestActionUnassigned means assignees were removed.
	PullRequestActionUnassigned = "unassigned"
	// PullRequestActionReviewRequested means review requests were added.
	PullRequestActionReviewRequested = "review_requested"
	// PullRequestActionReviewRequestRemoved means review requests were removed.
	PullRequestActionReviewRequestRemoved = "review_request_removed"
	// PullRequestActionLabeled means means labels were added.
	PullRequestActionLabeled = "labeled"
	// PullRequestActionUnlabeled means labels were removed
	PullRequestActionUnlabeled = "unlabeled"
	// PullRequestActionOpened means the PR was created
	PullRequestActionOpened = "opened"
	// PullRequestActionEdited means means the PR body changed.
	PullRequestActionEdited = "edited"
	// PullRequestActionClosed means the PR was closed (or was merged).
	PullRequestActionClosed = "closed"
	// PullRequestActionReopened means the PR was reopened.
	PullRequestActionReopened = "reopened"
	// PullRequestActionSynchronize means the git state changed.
	PullRequestActionSynchronize = "synchronize"
)
View Source
const (
	// PullRequestFileModified means a file changed.
	PullRequestFileModified PullRequestFileStatus = "modified"
	// PullRequestFileAdded means a file was added.
	PullRequestFileAdded = "added"
	// PullRequestFileRemoved means a file was deleted.
	PullRequestFileRemoved = "removed"
	// PullRequestFileRenamed means a file moved.
	PullRequestFileRenamed = "renamed"
)
View Source
const (
	// IssueActionAssigned means assignees were added.
	IssueActionAssigned IssueEventAction = "assigned"
	// IssueActionUnassigned means assignees were added.
	IssueActionUnassigned = "unassigned"
	// IssueActionLabeled means labels were added.
	IssueActionLabeled = "labeled"
	// IssueActionUnlabeled means labels were removed.
	IssueActionUnlabeled = "unlabeled"
	// IssueActionOpened means issue was opened/created.
	IssueActionOpened = "opened"
	// IssueActionEdited means issue body was edited.
	IssueActionEdited = "edited"
	// IssueActionMilestoned means the milestone was added/changed.
	IssueActionMilestoned = "milestoned"
	// IssueActionDemilestoned means a milestone was removed.
	IssueActionDemilestoned = "demilestoned"
	// IssueActionClosed means issue was closed.
	IssueActionClosed = "closed"
	// IssueActionReopened means issue was reopened.
	IssueActionReopened = "reopened"
)
View Source
const (
	// IssueCommentActionCreated means the comment was created.
	IssueCommentActionCreated IssueCommentEventAction = "created"
	// IssueCommentActionEdited means the comment was edited.
	IssueCommentActionEdited = "edited"
	// IssueCommentActionDeleted means the comment was deleted.
	IssueCommentActionDeleted = "deleted"
)
View Source
const (
	// ReviewActionSubmitted means the review was submitted.
	ReviewActionSubmitted ReviewEventAction = "submitted"
	// ReviewActionEdited means the review was edited.
	ReviewActionEdited = "edited"
	// ReviewActionDismissed means the review was dismissed.
	ReviewActionDismissed = "dismissed"
)
View Source
const (
	ReviewStateApproved         ReviewState = "APPROVED"
	ReviewStateChangesRequested             = "CHANGES_REQUESTED"
	ReviewStateCommented                    = "COMMENTED"
	ReviewStateDismissed                    = "DISMISSED"
	ReviewStatePending                      = "PENDING"
)

Possible review states.

View Source
const (
	// ReviewCommentActionCreated means the comment was created.
	ReviewCommentActionCreated ReviewCommentEventAction = "created"
	// ReviewCommentActionEdited means the comment was edited.
	ReviewCommentActionEdited = "edited"
	// ReviewCommentActionDeleted means the comment was deleted.
	ReviewCommentActionDeleted = "deleted"
)
View Source
const (
	Approve        ReviewAction = "APPROVE"
	RequestChanges              = "REQUEST_CHANGES"
	Comment                     = "COMMENT"
)

Possible review actions. Leave Action blank for a pending review.

View Source
const (
	// PrivacySecret memberships are only visible to other team members.
	PrivacySecret = "secret"
	// PrivacyClosed memberships are visible to org members.
	PrivacyClosed = "closed"
)
View Source
const (
	// RoleAll lists both members and admins
	RoleAll = "all"
	// RoleAdmin specifies the user is an org admin, or lists only admins
	RoleAdmin = "admin"
	// RoleMaintainer specifies the user is a team maintainer, or lists only maintainers
	RoleMaintainer = "maintainer"
	// RoleMember specifies the user is a regular user, or only lists regular users
	RoleMember = "member"
	// StatePending specifies the user has an invitation to the org/team.
	StatePending = "pending"
	// StateActive specifies the user's membership is active.
	StateActive = "active"
)
View Source
const (
	// GenericCommentActionCreated means something was created/opened/submitted
	GenericCommentActionCreated GenericCommentEventAction = "created" // "opened", "submitted"
	// GenericCommentActionEdited means something was edited.
	GenericCommentActionEdited = "edited"
	// GenericCommentActionDeleted means something was deleted/dismissed.
	GenericCommentActionDeleted = "deleted" // "dismissed"
)

Comments indicate values that are coerced to the specified value.

Variables

View Source
var NormLogin = strings.ToLower

NormLogin normalizes GitHub login strings

Functions

func HasLabel

func HasLabel(label string, issueLabels []Label) bool

HasLabel checks if label is in the label set "issueLabels".

func ImageTooBig

func ImageTooBig(url string) (bool, error)

ImageTooBig checks if image is bigger than github limits

func PayloadSignature

func PayloadSignature(payload []byte, key []byte) string

PayloadSignature returns the signature that matches the payload.

func ValidatePayload

func ValidatePayload(payload []byte, sig string, key []byte) bool

ValidatePayload ensures that the request payload signature matches the key.

Types

type Branch

type Branch struct {
	Name      string `json:"name"`
	Protected bool   `json:"protected"` // only included for ?protection=true requests

}

Branch contains general branch information.

type BranchProtectionRequest

type BranchProtectionRequest struct {
	RequiredStatusChecks       *RequiredStatusChecks       `json:"required_status_checks"`
	EnforceAdmins              *bool                       `json:"enforce_admins"`
	RequiredPullRequestReviews *RequiredPullRequestReviews `json:"required_pull_request_reviews"`
	Restrictions               *Restrictions               `json:"restrictions"`
}

BranchProtectionRequest represents protections in place for a branch. See also: https://developer.github.com/v3/repos/branches/#update-branch-protection

type Client

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

Client interacts with the github api.

func NewClient

func NewClient(getToken func() []byte, bases ...string) *Client

NewClient creates a new fully operational GitHub client. 'getToken' is a generator for the GitHub access token to use. 'bases' is a variadic slice of endpoints to use in order of preference.

An endpoint is used when all preceding endpoints have returned a conn err.
This should be used when using the ghproxy GitHub proxy cache to allow
this client to bypass the cache if it is temporarily unavailable.

func NewDryRunClient

func NewDryRunClient(getToken func() []byte, bases ...string) *Client

NewDryRunClient creates a new client that will not perform mutating actions such as setting statuses or commenting, but it will still query GitHub and use up API tokens. 'getToken' is a generator the GitHub access token to use. 'bases' is a variadic slice of endpoints to use in order of preference.

An endpoint is used when all preceding endpoints have returned a conn err.
This should be used when using the ghproxy GitHub proxy cache to allow
this client to bypass the cache if it is temporarily unavailable.

func NewFakeClient

func NewFakeClient() *Client

NewFakeClient creates a new client that will not perform any actions at all.

func (*Client) AddLabel

func (c *Client) AddLabel(org, repo string, number int, label string) error

AddLabel adds label to org/repo#number, returning an error on a bad response code.

See https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue

func (*Client) AddRepoLabel

func (c *Client) AddRepoLabel(org, repo, label, description, color string) error

AddRepoLabel adds a defined label given org/repo

See https://developer.github.com/v3/issues/labels/#create-a-label

func (*Client) AssignIssue

func (c *Client) AssignIssue(org, repo string, number int, logins []string) error

AssignIssue adds logins to org/repo#number, returning an error if any login is missing after making the call.

See https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue

func (*Client) BotName

func (c *Client) BotName() (string, error)

BotName returns the login of the authenticated identity.

See https://developer.github.com/v3/users/#get-the-authenticated-user

func (*Client) ClearMilestone

func (c *Client) ClearMilestone(org, repo string, num int) error

ClearMilestone clears the milestone from the specified issue

See https://developer.github.com/v3/issues/#edit-an-issue

func (*Client) CloseIssue

func (c *Client) CloseIssue(org, repo string, number int) error

CloseIssue closes the existing, open issue provided

See https://developer.github.com/v3/issues/#edit-an-issue

func (*Client) ClosePR

func (c *Client) ClosePR(org, repo string, number int) error

ClosePR closes the existing, open PR provided TODO: Rename to ClosePullRequest

See https://developer.github.com/v3/pulls/#update-a-pull-request

func (*Client) CreateComment

func (c *Client) CreateComment(org, repo string, number int, comment string) error

CreateComment creates a comment on the issue.

See https://developer.github.com/v3/issues/comments/#create-a-comment

func (*Client) CreateCommentReaction

func (c *Client) CreateCommentReaction(org, repo string, id int, reaction string) error

CreateCommentReaction responds emotionally to comment id in org/repo.

See https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment

func (*Client) CreateFork

func (c *Client) CreateFork(owner, repo string) error

CreateFork creates a fork for the authenticated user. Forking a repository happens asynchronously. Therefore, we may have to wait a short period before accessing the git objects. If this takes longer than 5 minutes, Github recommends contacting their support.

See https://developer.github.com/v3/repos/forks/#create-a-fork

func (*Client) CreateIssueReaction

func (c *Client) CreateIssueReaction(org, repo string, id int, reaction string) error

CreateIssueReaction responds emotionally to org/repo#id

See https://developer.github.com/v3/reactions/#create-reaction-for-an-issue

func (*Client) CreatePullRequest

func (c *Client) CreatePullRequest(org, repo, title, body, head, base string, canModify bool) (int, error)

CreatePullRequest creates a new pull request and returns its number if the creation is successful, otherwise any error that is encountered.

See https://developer.github.com/v3/pulls/#create-a-pull-request

func (*Client) CreateReview

func (c *Client) CreateReview(org, repo string, number int, r DraftReview) error

CreateReview creates a review using the draft.

https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review

func (*Client) CreateStatus

func (c *Client) CreateStatus(org, repo, sha string, s Status) error

CreateStatus creates or updates the status of a commit.

See https://developer.github.com/v3/repos/statuses/#create-a-status

func (*Client) CreateTeam

func (c *Client) CreateTeam(org string, team Team) (*Team, error)

CreateTeam adds a team with name to the org, returning a struct with the new ID.

See https://developer.github.com/v3/teams/#create-team

func (*Client) DeleteComment

func (c *Client) DeleteComment(org, repo string, id int) error

DeleteComment deletes the comment.

See https://developer.github.com/v3/issues/comments/#delete-a-comment

func (*Client) DeleteRepoLabel

func (c *Client) DeleteRepoLabel(org, repo, label string) error

DeleteRepoLabel deletes a label in org/repo

See https://developer.github.com/v3/issues/labels/#delete-a-label

func (*Client) DeleteStaleComments

func (c *Client) DeleteStaleComments(org, repo string, number int, comments []IssueComment, isStale func(IssueComment) bool) error

DeleteStaleComments iterates over comments on an issue/PR, deleting those which the 'isStale' function identifies as stale. If 'comments' is nil, the comments will be fetched from GitHub.

func (*Client) DeleteTeam

func (c *Client) DeleteTeam(id int) error

DeleteTeam removes team.ID from GitHub.

See https://developer.github.com/v3/teams/#delete-team

func (*Client) EditComment

func (c *Client) EditComment(org, repo string, id int, comment string) error

EditComment changes the body of comment id in org/repo.

See https://developer.github.com/v3/issues/comments/#edit-a-comment

func (*Client) EditOrg

func (c *Client) EditOrg(name string, config Organization) (*Organization, error)

EditOrg will update the metadata for this org.

https://developer.github.com/v3/orgs/#edit-an-organization

func (*Client) EditTeam

func (c *Client) EditTeam(t Team) (*Team, error)

EditTeam patches team.ID to contain the specified other values.

See https://developer.github.com/v3/teams/#edit-team

func (*Client) Email

func (c *Client) Email() (string, error)

Email returns the user-configured email for the authenticated identity.

See https://developer.github.com/v3/users/#get-the-authenticated-user

func (*Client) FindIssues

func (c *Client) FindIssues(query, sort string, asc bool) ([]Issue, error)

FindIssues uses the GitHub search API to find issues which match a particular query.

Input query the same way you would into the website. Order returned results with sort (usually "updated"). Control whether oldest/newest is first with asc.

See https://help.github.com/articles/searching-issues-and-pull-requests/ for details.

func (*Client) GetBranches

func (c *Client) GetBranches(org, repo string, onlyProtected bool) ([]Branch, error)

GetBranches returns all branches in the repo.

If onlyProtected is true it will only return repos with protection enabled, and branch.Protected will be true. Otherwise Protected is the default value (false).

This call uses multiple API tokens when results are paginated.

See https://developer.github.com/v3/repos/branches/#list-branches

func (*Client) GetCombinedStatus

func (c *Client) GetCombinedStatus(org, repo, ref string) (*CombinedStatus, error)

GetCombinedStatus returns the latest statuses for a given ref.

See https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref

func (*Client) GetFile

func (c *Client) GetFile(org, repo, filepath, commit string) ([]byte, error)

GetFile uses GitHub repo contents API to retrieve the content of a file with commit sha. If commit is empty, it will grab content from repo's default branch, usually master. TODO(krzyzacy): Support retrieve a directory

See https://developer.github.com/v3/repos/contents/#get-contents

func (*Client) GetIssueLabels

func (c *Client) GetIssueLabels(org, repo string, number int) ([]Label, error)

GetIssueLabels returns the list of labels currently on issue org/repo#number.

See https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue

func (*Client) GetOrg

func (c *Client) GetOrg(name string) (*Organization, error)

GetOrg returns current metadata for the org

https://developer.github.com/v3/orgs/#get-an-organization

func (*Client) GetPullRequest

func (c *Client) GetPullRequest(org, repo string, number int) (*PullRequest, error)

GetPullRequest gets a pull request.

See https://developer.github.com/v3/pulls/#get-a-single-pull-request

func (*Client) GetPullRequestChanges

func (c *Client) GetPullRequestChanges(org, repo string, number int) ([]PullRequestChange, error)

GetPullRequestChanges gets a list of files modified in a pull request.

See https://developer.github.com/v3/pulls/#list-pull-requests-files

func (*Client) GetPullRequestPatch

func (c *Client) GetPullRequestPatch(org, repo string, number int) ([]byte, error)

GetPullRequestPatch gets the patch version of a pull request.

See https://developer.github.com/v3/media/#commits-commit-comparison-and-pull-requests

func (*Client) GetRef

func (c *Client) GetRef(org, repo, ref string) (string, error)

GetRef returns the SHA of the given ref, such as "heads/master".

See https://developer.github.com/v3/git/refs/#get-a-reference

func (*Client) GetRepo

func (c *Client) GetRepo(owner, name string) (Repo, error)

GetRepo returns the repo for the provided owner/name combination.

See https://developer.github.com/v3/repos/#get

func (*Client) GetRepoLabels

func (c *Client) GetRepoLabels(org, repo string) ([]Label, error)

GetRepoLabels returns the list of labels accessible to org/repo.

See https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository

func (*Client) GetRepos

func (c *Client) GetRepos(org string, isUser bool) ([]Repo, error)

GetRepos returns all repos in an org.

This call uses multiple API tokens when results are paginated.

See https://developer.github.com/v3/repos/#list-organization-repositories

func (*Client) GetUserPermission

func (c *Client) GetUserPermission(org, repo, user string) (string, error)

GetUserPermission returns the user's permission level for a repo

https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level

func (*Client) HasPermission

func (c *Client) HasPermission(org, repo, user string, roles ...string) (bool, error)

HasPermission returns true if GetUserPermission() returns any of the roles.

func (*Client) IsCollaborator

func (c *Client) IsCollaborator(org, repo, user string) (bool, error)

IsCollaborator returns whether or not the user is a collaborator of the repo. From GitHub's API reference: For organization-owned repositories, the list of collaborators includes outside collaborators, organization members that are direct collaborators, organization members with access through team memberships, organization members with access through default organization permissions, and organization owners.

See https://developer.github.com/v3/repos/collaborators/

func (*Client) IsMember

func (c *Client) IsMember(org, user string) (bool, error)

IsMember returns whether or not the user is a member of the org.

See https://developer.github.com/v3/orgs/members/#check-membership

func (*Client) IsMergeable

func (c *Client) IsMergeable(org, repo string, number int, sha string) (bool, error)

IsMergeable determines if a PR can be merged. Mergeability is calculated by a background job on GitHub and is not immediately available when new commits are added so the PR must be polled until the background job completes.

func (*Client) ListCollaborators

func (c *Client) ListCollaborators(org, repo string) ([]User, error)

ListCollaborators gets a list of all users who have access to a repo (and can become assignees or requested reviewers).

See 'IsCollaborator' for more details. See https://developer.github.com/v3/repos/collaborators/

func (*Client) ListIssueComments

func (c *Client) ListIssueComments(org, repo string, number int) ([]IssueComment, error)

ListIssueComments returns all comments on an issue.

Each page of results consumes one API token.

See https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue

func (*Client) ListIssueEvents

func (c *Client) ListIssueEvents(org, repo string, num int) ([]ListedIssueEvent, error)

ListIssueEvents gets a list events from GitHub's events API that pertain to the specified issue. The events that are returned have a different format than webhook events and certain event types are excluded.

See https://developer.github.com/v3/issues/events/

func (*Client) ListMilestones

func (c *Client) ListMilestones(org, repo string) ([]Milestone, error)

ListMilestones list all milestones in a repo

See https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository/

func (*Client) ListOrgInvitations

func (c *Client) ListOrgInvitations(org string) ([]OrgInvitation, error)

ListOrgInvitations lists pending invitations to th org.

https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations

func (*Client) ListOrgMembers

func (c *Client) ListOrgMembers(org, role string) ([]TeamMember, error)

ListOrgMembers list all users who are members of an organization. If the authenticated user is also a member of this organization then both concealed and public members will be returned.

Role options are "all", "admin" and "member"

https://developer.github.com/v3/orgs/members/#members-list

func (*Client) ListPullRequestComments

func (c *Client) ListPullRequestComments(org, repo string, number int) ([]ReviewComment, error)

ListPullRequestComments returns all *review* comments on a pull request.

Multiple-pages of comments consumes multiple API tokens.

See https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request

func (*Client) ListReviews

func (c *Client) ListReviews(org, repo string, number int) ([]Review, error)

ListReviews returns all reviews on a pull request.

Multiple-pages of results consumes multiple API tokens.

See https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request

func (*Client) ListStatuses

func (c *Client) ListStatuses(org, repo, ref string) ([]Status, error)

ListStatuses gets commit statuses for a given ref.

See https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref

func (*Client) ListTeamMembers

func (c *Client) ListTeamMembers(id int, role string) ([]TeamMember, error)

ListTeamMembers gets a list of team members for the given team id

Role options are "all", "maintainer" and "member"

https://developer.github.com/v3/teams/members/#list-team-members

func (*Client) ListTeams

func (c *Client) ListTeams(org string) ([]Team, error)

ListTeams gets a list of teams for the given org

See https://developer.github.com/v3/teams/#list-teams

func (*Client) Merge

func (c *Client) Merge(org, repo string, pr int, details MergeDetails) error

Merge merges a PR.

See https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button

func (*Client) Query

func (c *Client) Query(ctx context.Context, q interface{}, vars map[string]interface{}) error

Query runs a GraphQL query using shurcooL/githubql's client.

func (*Client) RemoveBranchProtection

func (c *Client) RemoveBranchProtection(org, repo, branch string) error

RemoveBranchProtection unprotects org/repo=branch.

See https://developer.github.com/v3/repos/branches/#remove-branch-protection

func (*Client) RemoveLabel

func (c *Client) RemoveLabel(org, repo string, number int, label string) error

RemoveLabel removes label from org/repo#number, returning an error on any failure.

See https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue

func (*Client) RemoveOrgMembership

func (c *Client) RemoveOrgMembership(org, user string) error

RemoveOrgMembership removes the user from the org.

https://developer.github.com/v3/orgs/members/#remove-organization-membership

func (*Client) RemoveTeamMembership

func (c *Client) RemoveTeamMembership(id int, user string) error

RemoveTeamMembership removes the user from the team (but not the org).

https://developer.github.com/v3/teams/members/#remove-team-member

func (*Client) ReopenIssue

func (c *Client) ReopenIssue(org, repo string, number int) error

ReopenIssue re-opens the existing, closed issue provided

See https://developer.github.com/v3/issues/#edit-an-issue

func (*Client) ReopenPR

func (c *Client) ReopenPR(org, repo string, number int) error

ReopenPR re-opens the existing, closed PR provided TODO: Rename to ReopenPullRequest

See https://developer.github.com/v3/pulls/#update-a-pull-request

func (*Client) RequestReview

func (c *Client) RequestReview(org, repo string, number int, logins []string) error

RequestReview tries to add the users listed in 'logins' as requested reviewers of the specified PR. If any user in the 'logins' slice is not a contributor of the repo, the entire POST will fail without adding any reviewers. The GitHub API response does not specify which user(s) were invalid so if we fail to request reviews from the members of 'logins' we try to request reviews from each member individually. We try first with all users in 'logins' for efficiency in the common case.

See https://developer.github.com/v3/pulls/review_requests/#create-a-review-request

func (*Client) SetMilestone

func (c *Client) SetMilestone(org, repo string, issueNum, milestoneNum int) error

SetMilestone sets the milestone from the specified issue (if it is a valid milestone)

See https://developer.github.com/v3/issues/#edit-an-issue

func (*Client) Throttle

func (c *Client) Throttle(hourlyTokens, burst int)

Throttle client to a rate of at most hourlyTokens requests per hour, allowing burst tokens.

func (*Client) UnassignIssue

func (c *Client) UnassignIssue(org, repo string, number int, logins []string) error

UnassignIssue removes logins from org/repo#number, returns an error if any login remains assigned.

See https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue

func (*Client) UnrequestReview

func (c *Client) UnrequestReview(org, repo string, number int, logins []string) error

UnrequestReview tries to remove the users listed in 'logins' from the requested reviewers of the specified PR. The GitHub API treats deletions of review requests differently than creations. Specifically, if 'logins' contains a user that isn't a requested reviewer, other users that are valid are still removed. Furthermore, the API response lists the set of requested reviewers after the deletion (unlike request creations), so we can determine if each deletion was successful. The API responds with http status code 200 no matter what the content of 'logins' is.

See https://developer.github.com/v3/pulls/review_requests/#delete-a-review-request

func (*Client) UpdateBranchProtection

func (c *Client) UpdateBranchProtection(org, repo, branch string, config BranchProtectionRequest) error

UpdateBranchProtection configures org/repo=branch.

See https://developer.github.com/v3/repos/branches/#update-branch-protection

func (*Client) UpdateOrgMembership

func (c *Client) UpdateOrgMembership(org, user string, admin bool) (*OrgMembership, error)

UpdateOrgMembership invites a user to the org and/or updates their permission level.

If the user is not already a member, this will invite them. This will also change the role to/from admin, on either the invitation or membership setting.

https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership

func (*Client) UpdateRepoLabel

func (c *Client) UpdateRepoLabel(org, repo, label, newName, description, color string) error

UpdateRepoLabel updates a org/repo label to new name, description, and color

See https://developer.github.com/v3/issues/labels/#update-a-label

func (*Client) UpdateTeamMembership

func (c *Client) UpdateTeamMembership(id int, user string, maintainer bool) (*TeamMembership, error)

UpdateTeamMembership adds the user to the team and/or updates their role in that team.

If the user is not a member of the org, GitHub will invite them to become an outside collaborator, setting their status to pending.

https://developer.github.com/v3/teams/members/#add-or-update-team-membership

type ClientError

type ClientError struct {
	Message string `json:"message"`
	Errors  []struct {
		Resource string `json:"resource"`
		Field    string `json:"field"`
		Code     string `json:"code"`
		Message  string `json:"message,omitempty"`
	} `json:"errors,omitempty"`
}

ClientError represents https://developer.github.com/v3/#client-errors

type CombinedStatus

type CombinedStatus struct {
	Statuses []Status `json:"statuses"`
}

CombinedStatus is the latest statuses for a ref.

type Commit

type Commit struct {
	ID       string   `json:"id"`
	Message  string   `json:"message"`
	Added    []string `json:"added"`
	Removed  []string `json:"removed"`
	Modified []string `json:"modified"`
}

Commit represents general info about a commit.

type Content

type Content struct {
	Content string `json:"content"`
	SHA     string `json:"sha"`
}

Content is some base64 encoded github file content

type DraftReview

type DraftReview struct {
	// If unspecified, defaults to the most recent commit in the PR.
	CommitSHA string `json:"commit_id,omitempty"`
	Body      string `json:"body"`
	// If unspecified, defaults to PENDING.
	Action   ReviewAction         `json:"event,omitempty"`
	Comments []DraftReviewComment `json:"comments,omitempty"`
}

DraftReview is what we give GitHub when we want to make a PR Review. This is different than what we receive when we ask for a Review.

type DraftReviewComment

type DraftReviewComment struct {
	Path string `json:"path"`
	// Position in the patch, not the line number in the file.
	Position int    `json:"position"`
	Body     string `json:"body"`
}

DraftReviewComment is a comment in a draft review.

type ExtraUsers

type ExtraUsers struct {
	Users []string
	// contains filtered or unexported fields
}

ExtraUsers is an error specifying the users that could not be unassigned.

func (ExtraUsers) Error

func (e ExtraUsers) Error() string

type FileNotFound

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

FileNotFound happens when github cannot find the file requested by GetFile().

func (*FileNotFound) Error

func (e *FileNotFound) Error() string

type GenericCommentEvent

type GenericCommentEvent struct {
	IsPR         bool
	Action       GenericCommentEventAction
	Body         string
	HTMLURL      string
	Number       int
	Repo         Repo
	User         User
	IssueAuthor  User
	Assignees    []User
	IssueState   string
	IssueBody    string
	IssueHTMLURL string
	GUID         string
}

GenericCommentEvent is a fake event type that is instantiated for any github event that contains comment like content. The specific events that are also handled as GenericCommentEvents are: - issue_comment events - pull_request_review events - pull_request_review_comment events - pull_request events with action in ["opened", "edited"] - issue events with action in ["opened", "edited"]

Issue and PR "closed" events are not coerced to the "deleted" Action and do not trigger a GenericCommentEvent because these events don't actually remove the comment content from GH.

type GenericCommentEventAction

type GenericCommentEventAction string

GenericCommentEventAction coerces multiple actions into its generic equivalent.

type Issue

type Issue struct {
	User      User      `json:"user"`
	Number    int       `json:"number"`
	Title     string    `json:"title"`
	State     string    `json:"state"`
	HTMLURL   string    `json:"html_url"`
	Labels    []Label   `json:"labels"`
	Assignees []User    `json:"assignees"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Milestone Milestone `json:"milestone"`

	// This will be non-nil if it is a pull request.
	PullRequest *struct{} `json:"pull_request,omitempty"`
}

Issue represents general info about an issue.

func (Issue) HasLabel

func (i Issue) HasLabel(labelToFind string) bool

HasLabel checks if an issue has a given label.

func (Issue) IsAssignee

func (i Issue) IsAssignee(login string) bool

IsAssignee checks if a user is assigned to the issue.

func (Issue) IsAuthor

func (i Issue) IsAuthor(login string) bool

IsAuthor checks if a user is the author of the issue.

func (Issue) IsPullRequest

func (i Issue) IsPullRequest() bool

IsPullRequest checks if an issue is a pull request.

type IssueComment

type IssueComment struct {
	ID        int       `json:"id,omitempty"`
	Body      string    `json:"body"`
	User      User      `json:"user,omitempty"`
	HTMLURL   string    `json:"html_url,omitempty"`
	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

IssueComment represents general info about an issue comment.

type IssueCommentEvent

type IssueCommentEvent struct {
	Action  IssueCommentEventAction `json:"action"`
	Issue   Issue                   `json:"issue"`
	Comment IssueComment            `json:"comment"`
	Repo    Repo                    `json:"repository"`

	// GUID is included in the header of the request received by Github.
	GUID string
}

IssueCommentEvent is what GitHub sends us when an issue comment is changed.

type IssueCommentEventAction

type IssueCommentEventAction string

IssueCommentEventAction enumerates the triggers for this webhook payload type. See also: https://developer.github.com/v3/activity/events/types/#issuecommentevent

type IssueEvent

type IssueEvent struct {
	Action IssueEventAction `json:"action"`
	Issue  Issue            `json:"issue"`
	Repo   Repo             `json:"repository"`
	// Label is specified for IssueActionLabeled and IssueActionUnlabeled events.
	Label Label `json:"label"`

	// GUID is included in the header of the request received by Github.
	GUID string
}

IssueEvent represents an issue event from a webhook payload (not from the events API).

type IssueEventAction

type IssueEventAction string

IssueEventAction enumerates the triggers for this webhook payload type. See also: https://developer.github.com/v3/activity/events/types/#issuesevent

type IssuesSearchResult

type IssuesSearchResult struct {
	Total  int     `json:"total_count,omitempty"`
	Issues []Issue `json:"items,omitempty"`
}

IssuesSearchResult represents the result of an issues search.

type Label

type Label struct {
	URL         string `json:"url"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Color       string `json:"color"`
}

Label describes a GitHub label.

type LabelNotFound

type LabelNotFound struct {
	Owner, Repo string
	Number      int
	Label       string
}

LabelNotFound indicates that a label is not attached to an issue. For example, removing a label from an issue, when the issue does not have that label.

func (*LabelNotFound) Error

func (e *LabelNotFound) Error() string

type ListedIssueEvent

type ListedIssueEvent struct {
	Event     IssueEventAction `json:"event"` // This is the same as IssueEvent.Action.
	Actor     User             `json:"actor"`
	Label     Label            `json:"label"`
	CreatedAt time.Time        `json:"created_at"`
}

ListedIssueEvent represents an issue event from the events API (not from a webhook payload). https://developer.github.com/v3/issues/events/

type Membership

type Membership struct {
	// admin or member
	Role string `json:"role"`
	// pending or active
	State string `json:"state,omitempty"`
}

Membership specifies the role and state details for an org and/or team.

type MergeDetails

type MergeDetails struct {
	// CommitTitle defaults to the automatic message.
	CommitTitle string `json:"commit_title,omitempty"`
	// CommitMessage defaults to the automatic message.
	CommitMessage string `json:"commit_message,omitempty"`
	// The PR HEAD must match this to prevent races.
	SHA string `json:"sha,omitempty"`
	// Can be "merge", "squash", or "rebase". Defaults to merge.
	MergeMethod string `json:"merge_method,omitempty"`
}

MergeDetails contains desired properties of the merge.

See https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button

type Milestone

type Milestone struct {
	Title  string `json:"title"`
	Number int    `json:"number"`
}

Milestone is a milestone defined on a github repository

type MissingUsers

type MissingUsers struct {
	Users []string
	// contains filtered or unexported fields
}

MissingUsers is an error specifying the users that could not be unassigned.

func (MissingUsers) Error

func (m MissingUsers) Error() string

type ModifiedHeadError

type ModifiedHeadError string

ModifiedHeadError happens when github refuses to merge a PR because the PR changed.

func (ModifiedHeadError) Error

func (e ModifiedHeadError) Error() string

type OrgInvitation

type OrgInvitation struct {
	TeamMember
	Inviter TeamMember `json:"login"`
}

OrgInvitation contains Login and other details about the invitation.

type OrgMembership

type OrgMembership struct {
	Membership
}

OrgMembership contains Membership fields for user membership in an org.

type Organization

type Organization struct {
	// BillingEmail holds private billing address
	BillingEmail string `json:"billing_email"`
	Company      string `json:"company"`
	// Email is publicly visible
	Email                        string `json:"email"`
	Location                     string `json:"location"`
	Name                         string `json:"name"`
	Description                  string `json:"description"`
	HasOrganizationProjects      bool   `json:"has_organization_projects"`
	HasRepositoryProjects        bool   `json:"has_repository_projects"`
	DefaultRepositoryPermission  string `json:"default_repository_permission"`
	MembersCanCreateRepositories bool   `json:"members_can_create_repositories"`
}

Organization stores metadata information about an organization

type PullRequest

type PullRequest struct {
	Number             int               `json:"number"`
	HTMLURL            string            `json:"html_url"`
	User               User              `json:"user"`
	Base               PullRequestBranch `json:"base"`
	Head               PullRequestBranch `json:"head"`
	Title              string            `json:"title"`
	Body               string            `json:"body"`
	RequestedReviewers []User            `json:"requested_reviewers"`
	Assignees          []User            `json:"assignees"`
	State              string            `json:"state"`
	Merged             bool              `json:"merged"`
	CreatedAt          time.Time         `json:"created_at,omitempty"`
	UpdatedAt          time.Time         `json:"updated_at,omitempty"`
	// ref https://developer.github.com/v3/pulls/#get-a-single-pull-request
	// If Merged is true, MergeSHA is the SHA of the merge commit, or squashed commit
	// If Merged is false, MergeSHA is a commit SHA that github created to test if
	// the PR can be merged automatically.
	MergeSHA *string `json:"merge_commit_sha"`
	// ref https://developer.github.com/v3/pulls/#response-1
	// The value of the mergeable attribute can be true, false, or null. If the value
	// is null, this means that the mergeability hasn't been computed yet, and a
	// background job was started to compute it. When the job is complete, the response
	// will include a non-null value for the mergeable attribute.
	Mergable *bool `json:"mergeable,omitempty"`
}

PullRequest contains information about a PullRequest.

type PullRequestBranch

type PullRequestBranch struct {
	Ref  string `json:"ref"`
	SHA  string `json:"sha"`
	Repo Repo   `json:"repo"`
}

PullRequestBranch contains information about a particular branch in a PR.

type PullRequestChange

type PullRequestChange struct {
	SHA       string `json:"sha"`
	Filename  string `json:"filename"`
	Status    string `json:"status"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Changes   int    `json:"changes"`
	Patch     string `json:"patch"`
	BlobURL   string `json:"blob_url"`
}

PullRequestChange contains information about what a PR changed.

type PullRequestEvent

type PullRequestEvent struct {
	Action      PullRequestEventAction `json:"action"`
	Number      int                    `json:"number"`
	PullRequest PullRequest            `json:"pull_request"`
	Repo        Repo                   `json:"repository"`
	Label       Label                  `json:"label"`
	Sender      User                   `json:"sender"`

	// Changes holds raw change data, which we must inspect
	// and deserialize later as this is a polymorphic field
	Changes json.RawMessage `json:"changes"`

	// GUID is included in the header of the request received by Github.
	GUID string
}

PullRequestEvent is what GitHub sends us when a PR is changed.

type PullRequestEventAction

type PullRequestEventAction string

PullRequestEventAction enumerates the triggers for this webhook payload type. See also: https://developer.github.com/v3/activity/events/types/#pullrequestevent

type PullRequestFileStatus

type PullRequestFileStatus string

PullRequestFileStatus enumerates the statuses for this webhook payload type.

type PullRequestMergeType

type PullRequestMergeType string

PullRequestMergeType enumerates the types of merges the GitHub API can perform https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button

const (
	MergeMerge  PullRequestMergeType = "merge"
	MergeRebase PullRequestMergeType = "rebase"
	MergeSquash PullRequestMergeType = "squash"
)

Possible types of merges for the GitHub merge API

type PushEvent

type PushEvent struct {
	Ref     string   `json:"ref"`
	Before  string   `json:"before"`
	After   string   `json:"after"`
	Compare string   `json:"compare"`
	Commits []Commit `json:"commits"`
	// Pusher is the user that pushed the commit, valid in a webhook event.
	Pusher User `json:"pusher"`
	// Sender contains more information that Pusher about the user.
	Sender User `json:"sender"`
	Repo   Repo `json:"repository"`

	// GUID is included in the header of the request received by Github.
	GUID string
}

PushEvent is what GitHub sends us when a user pushes to a repo.

func (PushEvent) Branch

func (pe PushEvent) Branch() string

Branch returns the name of the branch to which the user pushed.

type Reaction

type Reaction struct {
	Content string `json:"content"`
}

Reaction holds the type of emotional reaction.

type Repo

type Repo struct {
	Owner         User   `json:"owner"`
	Name          string `json:"name"`
	FullName      string `json:"full_name"`
	HTMLURL       string `json:"html_url"`
	Fork          bool   `json:"fork"`
	DefaultBranch string `json:"default_branch"`
}

Repo contains general repository information.

type RequiredPullRequestReviews

type RequiredPullRequestReviews struct {
	DismissalRestrictions        Restrictions `json:"dismissal_restrictions"`
	DismissStaleReviews          bool         `json:"dismiss_stale_reviews"`
	RequireCodeOwnerReviews      bool         `json:"require_code_owner_reviews"`
	RequiredApprovingReviewCount int          `json:"required_approving_review_count"`
}

RequiredPullRequestReviews controls review rights.

type RequiredStatusChecks

type RequiredStatusChecks struct {
	Strict   bool     `json:"strict"` // PR must be up to date (include latest base branch commit).
	Contexts []string `json:"contexts"`
}

RequiredStatusChecks specifies which contexts must pass to merge.

type Restrictions

type Restrictions struct {
	Users *[]string `json:"users,omitempty"`
	Teams *[]string `json:"teams,omitempty"`
}

Restrictions tells github to restrict an activity to people/teams.

Use *[]string in order to distinguish unset and empty list. This is needed by dismissal_restrictions to distinguish do not restrict (empty object) and restrict everyone (nil user/teams list)

type Review

type Review struct {
	ID          int         `json:"id"`
	User        User        `json:"user"`
	Body        string      `json:"body"`
	State       ReviewState `json:"state"`
	HTMLURL     string      `json:"html_url"`
	SubmittedAt time.Time   `json:"submitted_at"`
}

Review describes a Pull Request review.

type ReviewAction

type ReviewAction string

ReviewAction is the action that a review can be made with.

type ReviewComment

type ReviewComment struct {
	ID        int       `json:"id"`
	ReviewID  int       `json:"pull_request_review_id"`
	User      User      `json:"user"`
	Body      string    `json:"body"`
	Path      string    `json:"path"`
	HTMLURL   string    `json:"html_url"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	// Position will be nil if the code has changed such that the comment is no
	// longer relevant.
	Position *int `json:"position"`
}

ReviewComment describes a Pull Request review.

type ReviewCommentEvent

type ReviewCommentEvent struct {
	Action      ReviewCommentEventAction `json:"action"`
	PullRequest PullRequest              `json:"pull_request"`
	Repo        Repo                     `json:"repository"`
	Comment     ReviewComment            `json:"comment"`

	// GUID is included in the header of the request received by Github.
	GUID string
}

ReviewCommentEvent is what GitHub sends us when a PR review comment is changed.

type ReviewCommentEventAction

type ReviewCommentEventAction string

ReviewCommentEventAction enumerates the triggers for this webhook payload type. See also: https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent

type ReviewEvent

type ReviewEvent struct {
	Action      ReviewEventAction `json:"action"`
	PullRequest PullRequest       `json:"pull_request"`
	Repo        Repo              `json:"repository"`
	Review      Review            `json:"review"`

	// GUID is included in the header of the request received by Github.
	GUID string
}

ReviewEvent is what GitHub sends us when a PR review is changed.

type ReviewEventAction

type ReviewEventAction string

ReviewEventAction enumerates the triggers for this webhook payload type. See also: https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent

type ReviewState

type ReviewState string

ReviewState is the state a review can be in.

type StateCannotBeChanged

type StateCannotBeChanged struct {
	Message string
}

StateCannotBeChanged represents the "custom" GitHub API error that occurs when a resource cannot be changed

func (StateCannotBeChanged) Error

func (s StateCannotBeChanged) Error() string

type Status

type Status struct {
	State       string `json:"state"`
	TargetURL   string `json:"target_url,omitempty"`
	Description string `json:"description,omitempty"`
	Context     string `json:"context,omitempty"`
}

Status is used to set a commit status line.

type StatusEvent

type StatusEvent struct {
	SHA         string `json:"sha,omitempty"`
	State       string `json:"state,omitempty"`
	Description string `json:"description,omitempty"`
	TargetURL   string `json:"target_url,omitempty"`
	ID          int    `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	Context     string `json:"context,omitempty"`
	Sender      User   `json:"sender,omitempty"`
	Repo        Repo   `json:"repository,omitempty"`

	// GUID is included in the header of the request received by Github.
	GUID string
}

StatusEvent fires whenever a git commit changes.

See https://developer.github.com/v3/activity/events/types/#statusevent

type Team

type Team struct {
	ID           int    `json:"id,omitempty"`
	Name         string `json:"name"`
	Description  string `json:"description,omitempty"`
	Privacy      string `json:"privacy,omitempty"`
	Parent       *Team  `json:"parent,omitempty"`         // Only present in responses
	ParentTeamID *int   `json:"parent_team_id,omitempty"` // Only valid in creates/edits
}

Team is a github organizational team

type TeamMember

type TeamMember struct {
	Login string `json:"login"`
}

TeamMember is a member of an organizational team

type TeamMembership

type TeamMembership struct {
	Membership
}

TeamMembership contains Membership fields for user membership on a team.

type UnauthorizedToPushError

type UnauthorizedToPushError string

UnauthorizedToPushError happens when client is not allowed to push to github.

func (UnauthorizedToPushError) Error

func (e UnauthorizedToPushError) Error() string

type UnmergablePRBaseChangedError

type UnmergablePRBaseChangedError string

UnmergablePRBaseChangedError happens when github refuses merging a PR because the base changed.

func (UnmergablePRBaseChangedError) Error

type UnmergablePRError

type UnmergablePRError string

UnmergablePRError happens when github refuses to merge a PR for other reasons (merge confclit).

func (UnmergablePRError) Error

func (e UnmergablePRError) Error() string

type User

type User struct {
	Login string `json:"login"`
	Name  string `json:"name"`
	Email string `json:"email"`
	ID    int    `json:"id"`
}

User is a GitHub user account.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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