command

package
v0.0.0-...-a196a74 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const RunCommentPrefix = "/run"

RunCommentPrefix is used as a command prefix to trigger plugin with it's name

Variables

View Source
var (
	// Anybody allows to any user
	Anybody = func(evaluate bool) (*PermissionStatus, error) {
		return &PermissionStatus{UserIsApproved: true, ApprovedRoles: []string{Anyone}}, nil
	}

	// AnyOf checks if any of the given permission checks is fulfilled
	AnyOf = func(permissionChecks ...PermissionCheck) PermissionCheck {
		return of(true, permissionChecks...)
	}

	// AllOf checks if all of the given permission checks are fulfilled
	AllOf = func(permissionChecks ...PermissionCheck) PermissionCheck {
		return of(false, permissionChecks...)
	}
)
View Source
var (
	// Admin is a name of the admin role
	Admin = "admin"
	// RequestedReviewer is a name of the requested reviewer role
	RequestedReviewer = "requested reviewer"
	// PullRequestCreator is a name of the pull request creator role
	PullRequestCreator = "pull request creator"
	// PullRequestApprover is a name of a person who gave an approval to the PR
	PullRequestApprover = "pull request approver"
	// Unknown represents an unknown user
	Unknown = "unknown"
	// Anyone represents any user/role
	Anyone = "anyone"
)
View Source
var Deleted = commentAction{/* contains filtered or unexported fields */}

Deleted represents comment deletion

View Source
var Not = func(restriction PermissionCheck) PermissionCheck {
	return func(evaluate bool) (*PermissionStatus, error) {
		status, err := restriction(evaluate)
		reversedStatus := &PermissionStatus{User: status.User}
		reversedStatus.UserIsApproved = !status.UserIsApproved
		reversedStatus.RejectedRoles = status.ApprovedRoles
		reversedStatus.ApprovedRoles = status.RejectedRoles
		return reversedStatus, err
	}
}

Not reverses the given permission check

View Source
var Triggered = commentAction{/* contains filtered or unexported fields */}

Triggered represents comment editions and creation

Functions

This section is empty.

Types

type CmdExecutor

type CmdExecutor struct {
	Command string
	Quiet   bool
	// contains filtered or unexported fields
}

CmdExecutor takes care of executing a command triggered by IssueCommentEvent. The execution is set by specifying actions/events and with given restrictions the command should be triggered for.

func (*CmdExecutor) Execute

func (e *CmdExecutor) Execute(client ghclient.Client, logger log.Logger, comment *gogh.IssueCommentEvent) error

Execute triggers the given DoFunctions (when all checks are fulfilled) for the given pr comment

func (*CmdExecutor) When

func (e *CmdExecutor) When(actions ...commentAction) *RestrictionSetter

When takes list of actions the command should be triggered for

type CommentCmd

type CommentCmd interface {
	// Perform triggers the process of evaluating and performing of the command for the given comment
	Perform(client ghclient.Client, logger log.Logger, comment *gogh.IssueCommentEvent) error
	// Matches says if the content of the given comment matches the command
	Matches(comment *gogh.IssueCommentEvent) bool
}

CommentCmd is a abstraction of a command that is triggered by a comment

type CommentCmdHandler

type CommentCmdHandler struct {
	Client ghclient.Client
	// contains filtered or unexported fields
}

CommentCmdHandler keeps list of CommentCmd implementations to be handled when an IssueCommentEvent occurs

func (*CommentCmdHandler) Handle

func (s *CommentCmdHandler) Handle(logger log.Logger, comment *gogh.IssueCommentEvent) error

Handle triggers the process of evaluating and performing of all stored CommentCmd implementations for the given comment

func (*CommentCmdHandler) Register

func (s *CommentCmdHandler) Register(command CommentCmd)

Register adds the given CommentCmd implementation to the list of commands to be handled when an IssueCommentEvent occurs

type DoFunction

type DoFunction func() error

DoFunction is used for performing operations related to command actions

type DoFunctionProvider

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

DoFunctionProvider keeps all allowed actions and permission checks and opens an API to provide a DoFunction implementation

func (*DoFunctionProvider) Then

func (p *DoFunctionProvider) Then(doFunction DoFunction)

Then take a DoFunction that performs the required operations (when all checks are fulfilled)

type PermissionCheck

type PermissionCheck func(evaluate bool) (*PermissionStatus, error)

PermissionCheck represents any check of the user's permissions and returns PermissionStatus that contains the result

type PermissionService

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

PermissionService keeps user name and PR loader and provides information about the user's permissions

func NewPermissionService

func NewPermissionService(client ghclient.Client, user string, prLoader *ghservice.PullRequestLazyLoader) *PermissionService

NewPermissionService creates a new instance of PermissionService with the given client, user and pr loader

func (*PermissionService) Admin

func (s *PermissionService) Admin(evaluate bool) (*PermissionStatus, error)

Admin checks if the user is admin

func (*PermissionService) PRApprover

func (s *PermissionService) PRApprover(evaluate bool) (*PermissionStatus, error)

PRApprover checks if the user approved the pull request

func (*PermissionService) PRCreator

func (s *PermissionService) PRCreator(evaluate bool) (*PermissionStatus, error)

PRCreator checks if the user is pull request creator

func (*PermissionService) PRReviewer

func (s *PermissionService) PRReviewer(evaluate bool) (*PermissionStatus, error)

PRReviewer checks if the user is pull request reviewer

type PermissionStatus

type PermissionStatus struct {
	User           string
	UserIsApproved bool
	ApprovedRoles  []string
	RejectedRoles  []string
}

PermissionStatus keeps information about the user, his permissions and which roles are approved and which rejected

func Flatten

func Flatten(statuses []*PermissionStatus, anyOff bool) *PermissionStatus

Flatten takes a slice of permission statuses and returns one with the flattened values. anyOff parameter sets if the user should be approved in any of the given permission statuses or in all of them

func NewPermissionStatus

func NewPermissionStatus(user string, userIsApproved bool, approvedRoles, rejectedRoles []string) *PermissionStatus

NewPermissionStatus creates a new instance of PermissionStatus with the given values

type RestrictionSetter

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

RestrictionSetter keeps information about set actions the command should be triggered for and opens an API to provide permission restrictions

func (*RestrictionSetter) By

func (s *RestrictionSetter) By(permissionChecks ...PermissionCheck) *DoFunctionProvider

By takes a list of permission checks the command should be restricted by

type RunCmd

type RunCmd struct {
	PluginName            string
	UserPermissionService *PermissionService
	WhenAddedOrEdited     DoFunction
}

RunCmd represents a command that is triggered by "/run plugin-name" or "/run all"

func (*RunCmd) Matches

func (c *RunCmd) Matches(comment *gogh.IssueCommentEvent) bool

Matches returns true when the given IssueCommentEvent content prefix is "/run"

func (*RunCmd) Perform

func (c *RunCmd) Perform(client ghclient.Client, logger log.Logger, comment *gogh.IssueCommentEvent) error

Perform executes the set DoFunctions for the given IssueCommentEvent (when all conditions are fulfilled)

Jump to

Keyboard shortcuts

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