plugins

package
v0.0.0-...-02c6b06 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const AboutThisBotWithoutCommands = "" /* 128-byte string literal not displayed */

Variables

This section is empty.

Functions

func FormatErrorResponse

func FormatErrorResponse(to, message, reason string) string

FormatErrorResponse formats a response that does not warrant additional explanation in the details section.

func FormatResponseWithReason

func FormatResponseWithReason(to, message, reason string) string

FormatResponseWithReason formats a response with additional explanation in the details section.

func FormatSimpleErrorResponse

func FormatSimpleErrorResponse(to, message string) string

FormatSimpleErrorResponse formats a response that does not warrant additional explanation in the details section.

func FormatSimpleResponse

func FormatSimpleResponse(to, message string) string

FormatSimpleResponse formats a response that does not warrant additional explanation in the details section.

func FormatUnauthorizedResponse

func FormatUnauthorizedResponse(to, name string) string

FormatUnauthorizedResponse returns the user not authorized response

func FormatUsageError

func FormatUsageError(name, description, example, usage string) string

FormatUsageError formats Usage of a command

func HandleRequest

func HandleRequest(client github.Client, event *github.GenericRequestEvent) error

HandleRequest parses a github event and executes the found Plugins

func ParseCommands

func ParseCommands(message string) ([][]string, error)

ParseCommands parses a message and returns a string of commands and arguments

func Register

func Register(plugin Plugin)

Register registers a plugin with its command to be executed on a event

func ResumePlugins

func ResumePlugins(ghMgr github.Manager) error

ResumePlugins resumes all states that can be found in the persistent storage

func Setup

func Setup(log logr.Logger, persistence Persistence)

Setup sets up the Plugins with a logger and a persistent storage

func UpdateState

func UpdateState(pl Plugin, runID string, customState string) error

Types

type Persistence

type Persistence interface {
	Save(map[string]map[string]*State) error
	Load() (map[string]map[string]*State, error)
}

Persistence describes the interface for persisting plugin states

func NewKubernetesPersistence

func NewKubernetesPersistence(k8sClient client.Client, name, namespace string) (Persistence, error)

type Plugin

type Plugin interface {
	// Command returns the unique matching command for the plugin
	Command() string

	// Authorization returns the authorization type of the plugin.
	// Defines who is allowed to call the plugin
	Authorization() github.AuthorizationType

	// Description returns a short description of the plugin
	Description() string

	// Example returns an example for the command
	Example() string

	// Config returns description for the default config that can be used in the repository
	Config() string

	// Flags return command line style flags for the command
	Flags() *pflag.FlagSet

	// Create a deep copy of the plugin
	New(runID string) Plugin

	// Run runs the command with the parsed flags (flag.Parse()) and the event that triggered the command
	Run(fs *pflag.FlagSet, client github.Client, event *github.GenericRequestEvent) error

	// resume the plugin execution from a persisted state
	ResumeFromState(client github.Client, event *github.GenericRequestEvent, state string) error
}

Plugin specifies a tm github bot plugin/command that can be triggered by a user

func Get

func Get(name string) (string, Plugin, error)

Get returns a specific plugin

func GetAll

func GetAll() []Plugin

GetAll returns all registered plugins

type Plugins

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

func New

func New(log logr.Logger, persistence Persistence) *Plugins

func (*Plugins) Error

func (p *Plugins) Error(client github.Client, event *github.GenericRequestEvent, plugin Plugin, err error) error

Error responds to the client if an error occurs

func (*Plugins) Get

func (p *Plugins) Get(name string) (string, Plugin, error)

func (*Plugins) HandleRequest

func (p *Plugins) HandleRequest(client github.Client, event *github.GenericRequestEvent) error

HandleRequest parses a github event and executes the found Plugins

func (*Plugins) Register

func (p *Plugins) Register(plugin Plugin)

Register registers a plugin with its command to be executed on a event

func (*Plugins) RemoveState

func (p *Plugins) RemoveState(pl Plugin, runID string)

RemoveState removes the state of a running plugin from the persistence

func (*Plugins) ResumePlugins

func (p *Plugins) ResumePlugins(ghMgr github.Manager) error

ResumePlugins resumes all states that can be found in the persistent storage

func (*Plugins) UpdateState

func (p *Plugins) UpdateState(pl Plugin, runID string, customState string) error

UpdateState updates the state of a running plugin and persists the changes

type State

type State struct {
	Event  *github.GenericRequestEvent
	Custom string
}

State describes the configuration of a running plugin that is can resume at any time

Directories

Path Synopsis
Package mock_plugins is a generated GoMock package.
Package mock_plugins is a generated GoMock package.

Jump to

Keyboard shortcuts

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