pull

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// MaxPullRequestFiles is the max number of files returned by GitHub
	// https://developer.github.com/v3/pulls/#list-pull-requests-files
	MaxPullRequestFiles = 3000

	// MaxPullRequestCommits is the max number of commits returned by GitHub
	// https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
	MaxPullRequestCommits = 250
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	CreatedAt time.Time
	Author    string
	Body      string
}

type Commit

type Commit struct {
	SHA             string
	Parents         []string
	CommittedViaWeb bool

	// Author is the login name of the author. It is empty if the author is not
	// a real user.
	Author string

	// Commiter is the login name of the committer. It is empty if the
	// committer is not a real user.
	Committer string

	// PushedAt is the timestamp when the commit was pushed. It is nil if that
	// information is not available for this commit.
	PushedAt *time.Time
}

func (*Commit) Users

func (c *Commit) Users() []string

Users returns the login names of the users associated with this commit.

type Context

type Context interface {
	MembershipContext

	// RepositoryOwner returns the owner of the repo that the pull request targets.
	RepositoryOwner() string

	// RepositoryName returns the repo that the pull request targets.
	RepositoryName() string

	// Number returns the number of the pull request.
	Number() int

	// Author returns the username of the user who opened the pull request.
	Author() string

	// CreatedAt returns the time when the pull request was created.
	CreatedAt() time.Time

	// HeadSHA returns the SHA of the head commit of the pull request.
	HeadSHA() string

	// Branches returns the base (also known as target) and head branch names
	// of this pull request. Branches in this repository have no prefix, while
	// branches in forks are prefixed with the owner of the fork and a colon.
	// The base branch will always be unprefixed.
	Branches() (base string, head string)

	// ChangedFiles returns the files that were changed in this pull request.
	ChangedFiles() ([]*File, error)

	// Commits returns the commits that are part of this pull request. The
	// commit order is implementation dependent.
	Commits() ([]*Commit, error)

	// Comments lists all comments on a Pull Request. The comment order is
	// implementation dependent.
	Comments() ([]*Comment, error)

	// Reviews lists all reviews on a Pull Request. The review order is
	// implementation dependent.
	Reviews() ([]*Review, error)

	// IsDraft returns the draft status of the Pull Request.
	IsDraft() bool

	// RepositoryCollaborators lists the set of collaborators, along with
	// their respective permission on a repo.
	RepositoryCollaborators() (map[string]string, error)

	// Teams lists the set of team collaborators, along with
	// their respective permission on a repo.
	Teams() (map[string]string, error)

	// RequestedReviewers returns any current and dismissed review requests on
	// the pull request.
	RequestedReviewers() ([]*Reviewer, error)

	// LatestStatuses returns a map of status check names to the latest result
	LatestStatuses() (map[string]string, error)

	// Labels returns a list of labels applied on the Pull Request
	Labels() ([]string, error)
}

Context is the context for a pull request. It defines methods to get information about the pull request and the VCS system containing the pull request (e.g. GitHub).

A new Context should be created for each request, so implementations are not required to be thread-safe.

func NewGitHubContext

func NewGitHubContext(ctx context.Context, mbrCtx MembershipContext, client *github.Client, v4client *githubv4.Client, loc Locator) (Context, error)

NewGitHubContext creates a new pull.Context that makes GitHub requests to obtain information. It caches responses for the lifetime of the context. The pull request passed to the context must contain at least the base repository and the number or the function panics.

type File

type File struct {
	Filename  string
	Status    FileStatus
	Additions int
	Deletions int
}

type FileStatus

type FileStatus int
const (
	FileModified FileStatus = iota
	FileAdded
	FileDeleted
)

type GitHubContext

type GitHubContext struct {
	MembershipContext
	// contains filtered or unexported fields
}

GitHubContext is a Context implementation that gets information from GitHub. A new instance must be created for each request.

func (*GitHubContext) Author

func (ghc *GitHubContext) Author() string

func (*GitHubContext) Branches

func (ghc *GitHubContext) Branches() (base string, head string)

Branches returns the names of the base and head branch. If the head branch is from another repository (it is a fork) then the branch name is `owner:branchName`.

func (*GitHubContext) ChangedFiles

func (ghc *GitHubContext) ChangedFiles() ([]*File, error)

func (*GitHubContext) Comments

func (ghc *GitHubContext) Comments() ([]*Comment, error)

func (*GitHubContext) Commits

func (ghc *GitHubContext) Commits() ([]*Commit, error)

func (*GitHubContext) CreatedAt added in v1.20.0

func (ghc *GitHubContext) CreatedAt() time.Time

func (*GitHubContext) HeadSHA

func (ghc *GitHubContext) HeadSHA() string

func (*GitHubContext) IsDraft

func (ghc *GitHubContext) IsDraft() bool

func (*GitHubContext) Labels

func (ghc *GitHubContext) Labels() ([]string, error)

func (*GitHubContext) LatestStatuses

func (ghc *GitHubContext) LatestStatuses() (map[string]string, error)

func (*GitHubContext) Number

func (ghc *GitHubContext) Number() int

func (*GitHubContext) RepositoryCollaborators

func (ghc *GitHubContext) RepositoryCollaborators() (map[string]string, error)

func (*GitHubContext) RepositoryName

func (ghc *GitHubContext) RepositoryName() string

func (*GitHubContext) RepositoryOwner

func (ghc *GitHubContext) RepositoryOwner() string

func (*GitHubContext) RequestedReviewers added in v1.20.0

func (ghc *GitHubContext) RequestedReviewers() ([]*Reviewer, error)

func (*GitHubContext) Reviews

func (ghc *GitHubContext) Reviews() ([]*Review, error)

func (*GitHubContext) Teams

func (ghc *GitHubContext) Teams() (map[string]string, error)

type GitHubMembershipContext

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

func NewGitHubMembershipContext

func NewGitHubMembershipContext(ctx context.Context, client *github.Client) *GitHubMembershipContext

func (*GitHubMembershipContext) IsCollaborator

func (mc *GitHubMembershipContext) IsCollaborator(org, repo, user, desiredPerm string) (bool, error)

func (*GitHubMembershipContext) IsOrgMember

func (mc *GitHubMembershipContext) IsOrgMember(org, user string) (bool, error)

func (*GitHubMembershipContext) IsTeamMember

func (mc *GitHubMembershipContext) IsTeamMember(team, user string) (bool, error)

func (*GitHubMembershipContext) OrganizationMembers

func (mc *GitHubMembershipContext) OrganizationMembers(org string) ([]string, error)

func (*GitHubMembershipContext) TeamMembers

func (mc *GitHubMembershipContext) TeamMembers(team string) ([]string, error)

type Locator

type Locator struct {
	Owner  string
	Repo   string
	Number int

	Value *github.PullRequest
}

Locator identifies a pull request and optionally contains a full or partial pull request object.

func (Locator) IsComplete

func (loc Locator) IsComplete() bool

IsComplete returns true if the locator contains a pull request object with all required fields.

type MembershipContext

type MembershipContext interface {
	// IsTeamMember returns true if the user is a member of the given team.
	// Teams are specified as "org-name/team-name".
	IsTeamMember(team, user string) (bool, error)

	// IsOrgMember returns true if the user is a member of the given organzation.
	IsOrgMember(org, user string) (bool, error)

	// IsCollaborator returns true if the user meets the desiredPerm of the given organzation's repository.
	IsCollaborator(org, repo, user, desiredPerm string) (bool, error)

	// TeamMembers returns the list of usernames in the given organization's team.
	TeamMembers(team string) ([]string, error)

	// OrganizationMembers returns the list of org member usernames in the given organization.
	OrganizationMembers(org string) ([]string, error)
}

MembershipContext defines methods to get information about about user membership in Github organizations and teams.

type Review

type Review struct {
	CreatedAt time.Time
	Author    string
	State     ReviewState
	Body      string

	// ID is the GitHub node ID of the review, used to resolve dismissals
	ID string
}

type ReviewState

type ReviewState string
const (
	ReviewApproved         ReviewState = "approved"
	ReviewChangesRequested ReviewState = "changes_requested"
	ReviewCommented        ReviewState = "commented"
	ReviewDismissed        ReviewState = "dismissed"
	ReviewPending          ReviewState = "pending"
)

type Reviewer added in v1.20.0

type Reviewer struct {
	Type    ReviewerType
	Name    string
	Removed bool
}

type ReviewerType added in v1.20.0

type ReviewerType string
const (
	ReviewerUser ReviewerType = "user"
	ReviewerTeam ReviewerType = "team"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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