pull

package
v1.34.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 12 Imported by: 2

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 Body added in v1.27.0

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

type Collaborator added in v1.22.0

type Collaborator struct {
	Name        string
	Permissions []CollaboratorPermission
}

type CollaboratorPermission added in v1.22.0

type CollaboratorPermission struct {
	Permission Permission

	// True if Permission is granted by a direct or team association with the
	// repository. If false, the permission is granted by the organization.
	ViaRepo bool
}

type Comment

type Comment struct {
	CreatedAt    time.Time
	LastEditedAt 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

	// Signature is the signature and details that was extracted from the commit.
	// It is nil if the commit has no signature
	Signature *Signature
}

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

	// EvaluationTimestamp returns the time at the start of the pull request
	// evaluation, usually the creation time of the context. All calls on the
	// same context should return the same value.
	EvaluationTimestamp() time.Time

	// 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

	// Title returns the title of the pull request
	Title() string

	// Body returns a struct that includes LastEditedAt for the pull request body
	Body() (*Body, error)

	// 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

	// IsOpen returns true when the state of the pull request is "open"
	IsOpen() bool

	// IsClosed returns true when the state of the pull request is "closed"
	IsClosed() bool

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

	// PushedAt returns the time at which the commit with sha was pushed. The
	// returned time may be after the actual push time, but must not be before.
	PushedAt(sha string) (time.Time, 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 returns the repository collaborators.
	RepositoryCollaborators() ([]*Collaborator, error)

	// CollaboratorPermission returns the permission level of user on the repository.
	CollaboratorPermission(user string) (Permission, error)

	// Teams lists the set of team collaborators, along with their respective
	// permission on a repo.
	Teams() (map[string]Permission, 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,
	globalCache GlobalCache,
	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) Body added in v1.27.0

func (ghc *GitHubContext) Body() (*Body, error)

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) CollaboratorPermission added in v1.22.0

func (ghc *GitHubContext) CollaboratorPermission(user string) (Permission, 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) EvaluationTimestamp added in v1.31.0

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

func (*GitHubContext) HeadSHA

func (ghc *GitHubContext) HeadSHA() string

func (*GitHubContext) IsClosed added in v1.21.3

func (ghc *GitHubContext) IsClosed() bool

func (*GitHubContext) IsDraft

func (ghc *GitHubContext) IsDraft() bool

func (*GitHubContext) IsOpen added in v1.21.3

func (ghc *GitHubContext) IsOpen() 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) PushedAt added in v1.31.0

func (ghc *GitHubContext) PushedAt(sha string) (time.Time, error)

func (*GitHubContext) RepositoryCollaborators

func (ghc *GitHubContext) RepositoryCollaborators() ([]*Collaborator, 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]Permission, error)

func (*GitHubContext) Title added in v1.21.0

func (ghc *GitHubContext) Title() string

type GitHubMembershipContext

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

func NewGitHubMembershipContext

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

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 GlobalCache added in v1.31.0

type GlobalCache interface {
	GetPushedAt(repoID int64, sha string) (time.Time, bool)
	SetPushedAt(repoID int64, sha string, t time.Time)
}

GlobalCache implementations provide a way to cache values that are safe to cache at the application level. Values in the global cache should not become stale due to external changes and should only expire to prevent the cache from becoming infinitely large.

type LRUGlobalCache added in v1.31.0

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

LRUGlobalCache is a GlobalCache where each data type is stored in a separate LRU cache. This prevents frequently used data of one type from evicting less frequently used data of a different type.

func NewLRUGlobalCache added in v1.31.0

func NewLRUGlobalCache(pushedAtSize int) (*LRUGlobalCache, error)

func (*LRUGlobalCache) GetPushedAt added in v1.31.0

func (c *LRUGlobalCache) GetPushedAt(repoID int64, sha string) (time.Time, bool)

func (*LRUGlobalCache) SetPushedAt added in v1.31.0

func (c *LRUGlobalCache) SetPushedAt(repoID int64, sha string, t time.Time)

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)

	// 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 Permission added in v1.22.0

type Permission uint8
const (
	PermissionNone Permission = iota
	PermissionRead
	PermissionTriage
	PermissionWrite
	PermissionMaintain
	PermissionAdmin
)

func ParsePermission added in v1.22.0

func ParsePermission(s string) (Permission, error)

func ParsePermissionMap added in v1.22.0

func ParsePermissionMap(m map[string]bool) Permission

func (Permission) MarshalText added in v1.22.0

func (p Permission) MarshalText() ([]byte, error)

func (Permission) String added in v1.22.0

func (p Permission) String() string

func (*Permission) UnmarshalText added in v1.22.0

func (p *Permission) UnmarshalText(text []byte) error

type Review

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

	Teams []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"
)

type Signature added in v1.22.0

type Signature struct {
	Type           SignatureType
	IsValid        bool
	KeyID          string
	KeyFingerprint string
	Signer         string
	State          string
}

type SignatureType added in v1.22.0

type SignatureType string
const (
	SignatureGpg   SignatureType = "GpgSignature"
	SignatureSmime SignatureType = "SmimeSignature"
	SignatureSSH   SignatureType = "SshSignature"
)

type TemporaryError added in v1.21.2

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

func (*TemporaryError) Error added in v1.21.2

func (te *TemporaryError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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