policy

package
v0.0.0-...-8c39811 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	// Labels identifies which labels to add to an issue
	Labels Labels `yaml:",inline"`
	// RemoveLabels defines what labels to remove
	RemoveLabels []string `yaml:"removeLabels,omitempty"`
	// Status sets the status of the issue
	Status ActionStatus `yaml:"status"`
	// Mention allows the bot to mention certain users
	Mention []string `yaml:"mention,omitempty"`
	// Comment will leave a comment on said issue
	Comment string `yaml:"comment,omitempty"`
}

Action struct houses how an eligible webhook event should be responded to

type ActionStatus

type ActionStatus string

ActionStatus is a string backed status

type Command

type Command string

Command is a string backed type for a given command to respond to

type Condition

type Condition struct {
	// Date is a struct to manage date related entries
	//Date *Date `yaml:"date,omitempty"`
	// State is the expected state of the webhook event
	State *State `yaml:",inline"`
	// Milestone is the milestone of the issue
	Milestone *Milestone `yaml:",inline"`
	// Labels provides an array of required labels for the condition to be met
	Labels Labels `yaml:",inline"`
	// ForbiddenLabels is an array of labels that need to all be missing to
	ForbiddenLabels ForbiddenLabels `yaml:",inline"`
	// Discussion provides a struct to manage whether certain discussion properties meet the given condition
	//Discussion *Discussion `yaml:"discussion,omitempty"` @todo
	// Note is the contents of a given note/comment on various different events like commit, mr, issue, code snippet
	Note *Note `yaml:"note"`
}

Condition declares what properties and states are required by the webhook to have an action performed on it

type Date

type Date struct {
	// Attribute can be `created_at` or `updated_at`
	Attribute DateAttribute `yaml:"attribute"`
	// Condition can be `older_than` or `newer_than`
	Condition DateCondition `yaml:"condition"`
	// IntervalType can be `days`, `weeks`, `months`, `years`
	IntervalType DateIntervalType `yaml:"intervalType"`
	// Interval is a numeric representation of the `IntervalType`
	Interval int `yaml:"interval"`
}

Date is possible condition that can be used to allow or disallow the behaviour of the Bot see `config.yaml`

type DateAttribute

type DateAttribute string

DateAttribute is the updated or created property

type DateCondition

type DateCondition string

DateCondition is the greater than or less than [date] filter

type DateIntervalType

type DateIntervalType string

DateIntervalType is the type of available interval

type Executor

type Executor interface {
	// contains filtered or unexported methods
}

Executor is how the updates to GitLab are done on a per-type basis

type FieldValidator

type FieldValidator interface {
	// contains filtered or unexported methods
}

FieldValidator ensures that a field has valid user specified input

type ForbiddenLabeler

type ForbiddenLabeler interface {
	// contains filtered or unexported methods
}

ForbiddenLabeler provides a list of labels that must be absent

type ForbiddenLabels

type ForbiddenLabels struct {
	ForbiddenLabels []string `yaml:"forbiddenLabels"`
}

ForbiddenLabels is a list of labels that are missing from an issue and will trigger an action

type GitLabAdaptor

type GitLabAdaptor interface {
	Executor
	Stater
	Labeler
	Milestoner
}

GitLabAdaptor wraps the incoming hook so additional methods can be added

type GitLabUpdateResult

type GitLabUpdateResult struct {
	Action Action `json:"action"`
	// here we collect the Endpoint being called from the client to help provide
	// more info, without using reflection on a func to get the func name
	Endpoint string `json:"endpoint"`
	Error    string `json:"error"`
}

GitLabUpdateResult reports back to the caller the series of events taken by the bot to update Gitlab

type Labeler

type Labeler interface {
	// contains filtered or unexported methods
}

Labeler returns the labels for a Policy

type Labels

type Labels struct {
	Labels []string `yaml:"labels"`
}

Labels represents an array of labels

type Matcher

type Matcher interface {
	Stater
	Resourcer
	Labeler
	Milestoner
	ForbiddenLabeler
}

Matcher ensures that a Policy provides the required functionality to enable comparing a Webhook to a Policy

type Mentions

type Mentions []string

Mentions is an array of users mentioned in a comment

type MergeEventAdaptor

type MergeEventAdaptor struct {
	gitlab.MergeEvent
}

MergeEventAdaptor wraps the gitlab.MergeEvent

type Milestone

type Milestone struct {
	Milestone int `yaml:"milestone"`
}

Milestone represents the id of the milestone from GitLab

type Milestoner

type Milestoner interface {
	// contains filtered or unexported methods
}

Milestoner provides the milestone ID

type Note

type Note struct {
	// Type is the NoteType of the note from GitLab. If you need to narrow down
	// the type of note then use this, if left blank, then it will apply to all note types
	Type *NoteType `yaml:"noteType"`
	// Mentions looks for user's mentioned in the note
	Mentions Mentions `yaml:"mentions"`
	// Command is the specified string to look for if needed.
	Command Command `yaml:"command"`
}

Note represents a GitLab Note, which is essentially a comment on a series of different scenarios and event types

type NoteType

type NoteType string

NoteType is the type of note: Commit, MergeRequest, Issue, Snippet

const (
	// NoteCommit are comments on Commits
	NoteCommit NoteType = "Commit"
	// NoteMergeRequest are comments on MergeRequests
	NoteMergeRequest NoteType = "MergeRequest"
	// NoteIssue are comments on Issues
	NoteIssue NoteType = "Issue"
	// NoteSnippet are comments on Snippets
	NoteSnippet NoteType = "Snippet"
)

type Policies

type Policies struct {
	Policies []Policy `yaml:"policies"`
}

Policies contains a slice of `Policy`s

type Policy

type Policy struct {
	Name       string    `yaml:"name"`
	Resource   Resource  `yaml:",inline"`
	Conditions Condition `yaml:"conditions,omitempty"`
	//Limit      *Limit    `yaml:"limit,omitempty"` @todo
	Actions Action `yaml:"actions,omitempty"`
}

Policy is a containing struct that identifies the required policy for a certain webhook

func (Policy) Validate

func (p Policy) Validate() error

Validate validates a Policy's correctness

type Preparer

type Preparer interface {
	// contains filtered or unexported methods
}

Preparer provides functionality that the GitLabAdaptor needs to determine what functionality is available to that type

type Resource

type Resource struct {
	EventType gitlab.EventType `yaml:"resource"`
}

Resource embeds a gitlab.EventType

type Resourcer

type Resourcer interface {
	// contains filtered or unexported methods
}

Resourcer provides the resource type from a Policy

type State

type State struct {
	State []string `yaml:"state"`
}

State represents the webhook state, this is only available on certain events

type Stater

type Stater interface {
	// contains filtered or unexported methods
}

Stater provides a method to get the state from an object

type Validator

type Validator interface {
	Validate() error
}

Validator allows the Policies to be checked for invalid or incompatible instructions

type Webhook

type Webhook struct {
	// EventType is the type of webhook, taken from the X-GitLab-Header
	EventType gitlab.EventType
	// Event is the payload of the webhook
	Event interface{}
}

Webhook is a wrapper around the incoming webhook

func (*Webhook) FilterEvent

func (w *Webhook) FilterEvent(in <-chan Policy, client *gitlab.Client) <-chan WebhookResult

FilterEvent takes a channel of Policy to check against the incoming Webhook If a Policy has conditions that are met by the Webhook, the Policy Action(s) are triggered, which normally results in the gitlab.Client making updates to GitLab

type WebhookResult

type WebhookResult struct {
	Policy  Policy               `json:"policy"`
	Actions []GitLabUpdateResult `json:"actions"`
}

WebhookResult returns the Policy that was matched against the Webhook along with an array of actions that the bot tried to take.

Jump to

Keyboard shortcuts

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