common

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: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actors

type Actors struct {
	Users         []string `yaml:"users" json:"users"`
	Teams         []string `yaml:"teams" json:"teams"`
	Organizations []string `yaml:"organizations" json:"organizations"`

	// Deprecated: use Permissions with "admin" or "write"
	Admins             bool `yaml:"admins" json:"-"`
	WriteCollaborators bool `yaml:"write_collaborators" json:"-"`

	// A list of GitHub collaborator permissions that are allowed. Values may
	// be any of "admin", "maintain", "write", "triage", and "read".
	Permissions []pull.Permission `yaml:"permissions" json:"permissions"`
}

Actors specifies who may take certain actions based on their username or team and organization memberships. The set of allowed actors is the union of all conditions in this structure.

func (*Actors) GetPermissions added in v1.26.0

func (a *Actors) GetPermissions() []pull.Permission

GetPermissions returns unique permissions ordered from most to least permissive. It includes the permissions from the deprecated Admins and WriteCollaborators fields.

func (*Actors) IsActor

func (a *Actors) IsActor(ctx context.Context, prctx pull.Context, user string) (bool, error)

IsActor returns true if the given user satisfies at least one of the conditions in this structure.

func (*Actors) IsEmpty

func (a *Actors) IsEmpty() bool

IsEmpty returns true if no conditions for actors are defined.

type Candidate

type Candidate struct {
	Type         CandidateType
	ReviewID     string
	User         string
	CreatedAt    time.Time
	LastEditedAt time.Time
}

type CandidateType added in v1.27.0

type CandidateType string
const (
	ReviewCandidate  CandidateType = "review"
	CommentCandidate CandidateType = "comment"
)

type CandidatesByCreationTime

type CandidatesByCreationTime []*Candidate

func (CandidatesByCreationTime) Len

func (cs CandidatesByCreationTime) Len() int

func (CandidatesByCreationTime) Less

func (cs CandidatesByCreationTime) Less(i, j int) bool

func (CandidatesByCreationTime) Swap

func (cs CandidatesByCreationTime) Swap(i, j int)

type Dismissal added in v1.29.0

type Dismissal struct {
	Candidate *Candidate
	Reason    string
}

type EvaluationStatus

type EvaluationStatus int
const (
	StatusSkipped EvaluationStatus = iota // note: values used for ordering
	StatusPending
	StatusApproved
	StatusDisapproved
)

func (EvaluationStatus) String

func (s EvaluationStatus) String() string

type Evaluator

type Evaluator interface {
	Triggered

	Evaluate(ctx context.Context, prctx pull.Context) Result
}

type Methods

type Methods struct {
	Comments                    []string `yaml:"comments,omitempty"`
	CommentPatterns             []Regexp `yaml:"comment_patterns,omitempty"`
	GithubReview                *bool    `yaml:"github_review,omitempty"`
	GithubReviewCommentPatterns []Regexp `yaml:"github_review_comment_patterns,omitempty"`
	BodyPatterns                []Regexp `yaml:"body_patterns,omitempty"`

	// If GithubReview is true, GithubReviewState is the state a review must
	// have to be considered a candidated. It is currently excluded from
	// serialized forms and should be set by the application.
	GithubReviewState pull.ReviewState `yaml:"-" json:"-"`
}

func (*Methods) BodyMatches added in v1.27.0

func (m *Methods) BodyMatches(prBody string) bool

func (*Methods) Candidates

func (m *Methods) Candidates(ctx context.Context, prctx pull.Context) ([]*Candidate, error)

Candidates returns a list of user candidates based on the configured methods. A given user will appear at most once in the list. If that user has taken multiple actions that match the methods, only the most recent by event order is included. The order of the candidates is unspecified.

func (*Methods) CommentMatches

func (m *Methods) CommentMatches(commentBody string) bool

type PredicateResult added in v1.25.0

type PredicateResult struct {
	Satisfied bool

	Description string

	// Describes the values, used as "the $ValuesPhrase"; must be plural
	ValuePhrase string
	Values      []string

	// Describes the condition, used as "$ConditionPhrase" or "does not $ConditionPhrase"
	ConditionPhrase string
	// If non-empty, use the map, otherwise, use the regular list
	ConditionsMap   map[string][]string
	ConditionValues []string
}

type Regexp

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

Regexp is a regexp.Regexp that only supports matching and can be deserialized from a string.

func NewCompiledRegexp

func NewCompiledRegexp(r *regexp.Regexp) Regexp

func NewRegexp

func NewRegexp(pattern string) (Regexp, error)

func (Regexp) Matches

func (r Regexp) Matches(s string) bool

func (Regexp) String

func (r Regexp) String() string

func (*Regexp) UnmarshalJSON

func (r *Regexp) UnmarshalJSON(data []byte) (err error)

func (*Regexp) UnmarshalYAML

func (r *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) (err error)

type RequestMode

type RequestMode string
const (
	RequestModeAllUsers    RequestMode = "all-users"
	RequestModeRandomUsers RequestMode = "random-users"
	RequestModeTeams       RequestMode = "teams"
)

type Requires added in v1.27.1

type Requires struct {
	Count  int    `yaml:"count"`
	Actors Actors `yaml:",inline"`
}

type Result

type Result struct {
	Name              string
	Description       string
	StatusDescription string
	Status            EvaluationStatus
	Error             error
	PredicateResults  []*PredicateResult
	Requires          Requires
	Methods           *Methods

	// Approvers contains the candidates that satisfied the rule.
	Approvers []*Candidate

	// Dismissals contains candidates that should be discarded because they
	// cannot satisfy any future evaluations.
	Dismissals []*Dismissal

	ReviewRequestRule *ReviewRequestRule

	Children []*Result
}

type ReviewRequestRule

type ReviewRequestRule struct {
	Teams          []string
	Users          []string
	Organizations  []string
	Permissions    []pull.Permission
	RequiredCount  int
	RequestedCount int

	Mode RequestMode
}

type Trigger added in v1.20.0

type Trigger uint32

Trigger is a flag set that marks the types of GitHub events that could change the value of a predicate or evaluation. It is used to optimize evaluation by skipping unnecessary work.

const (
	TriggerCommit Trigger = 1 << iota
	TriggerComment
	TriggerReview
	TriggerLabel
	TriggerStatus
	TriggerPullRequest

	// TriggerStatic is a name for the empty trigger set and means the
	// computation never needs updating.
	TriggerStatic Trigger = 0

	// TriggerAll is a name for the full trigger set and means the computation
	// should update after any changes to the pull request.
	TriggerAll Trigger = TriggerCommit | TriggerComment | TriggerReview | TriggerLabel | TriggerStatus | TriggerPullRequest
)

func (Trigger) Matches added in v1.20.0

func (t Trigger) Matches(flags Trigger) bool

Matches returns true if flag contains any of the flags of this trigger.

func (Trigger) String added in v1.20.0

func (t Trigger) String() string

type Triggered added in v1.20.0

type Triggered interface {
	Trigger() Trigger
}

Triggered defines the Trigger method, which returns a set of conditions when the implementor should be updated or evaluated.

Jump to

Keyboard shortcuts

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