internal

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultToApproval = "default to approval"

Variables

View Source
var SkippedOrSuccess = predicate.AllowedConclusions{"skipped", "success"}

SkippedOrSuccess contains the conclusions we always look for in a workflow run's conclusion. We only look at workflow runs which happened at all (because of the path filters). But we don't know if there was an `if` condition on any/all of the jobs. If there was, that's fine, and we should allow the approval rule.

Functions

func MergeConfigs

func MergeConfigs(generated, mergeWith policy.Config) (policy.Config, error)

MergeConfigs combines a generated config with an existing config using deep merging. The existing config takes precedence over the generated config.

func RegexpsFromGlobs

func RegexpsFromGlobs(globs []string) ([]common.Regexp, error)

RegexpsFromGlobs converts a sequence of glob patterns into a sequence of regular expressions in `policy-bot`'s `common.Regexp` wrapper type. If any of the glob patterns are invalid, it returns an error containing the invalid globs.

func WriteYamlToWriter

func WriteYamlToWriter(w io.Writer, data interface{}) error

Types

type ErrInvalidPolicyBotConfig

type ErrInvalidPolicyBotConfig struct {
	Err error
}

ErrInvalidPolicyBotConfig is returned when a policy bot config cannot be unmarshaled.

func (ErrInvalidPolicyBotConfig) Error

func (ErrInvalidPolicyBotConfig) Is

func (e ErrInvalidPolicyBotConfig) Is(target error) bool

Is implements the errors.Is interface. The default implementaion of `Is` compares by value, which is not that useful for us. It would only return `true` when the wrapped error is exactly the same.

func (ErrInvalidPolicyBotConfig) Unwrap

func (e ErrInvalidPolicyBotConfig) Unwrap() error

type ErrInvalidWorkflow

type ErrInvalidWorkflow struct {
	Path string
	Err  error
}

ErrInvalidWorkflow is returned when a workflow file cannot be parsed or is invalid. It will usually wrap an ErrWorkflowParse or ErrUnexpectedType.

func (ErrInvalidWorkflow) Error

func (e ErrInvalidWorkflow) Error() string

func (ErrInvalidWorkflow) Unwrap

func (e ErrInvalidWorkflow) Unwrap() error

type ErrNoWorkflows

type ErrNoWorkflows struct {
}

ErrNoWorkflows is returned when no workflows are found in the specified directory.

func (ErrNoWorkflows) Error

func (e ErrNoWorkflows) Error() string

type GitHubWorkflow

type GitHubWorkflow struct {
	On githubWorkflowHeader
}

GitHubWorkflow represents a GitHub Actions workflow file.

func (GitHubWorkflow) IsPullRequestWorkflow

func (wf GitHubWorkflow) IsPullRequestWorkflow() bool

IsPullRequestWorkflow checks if the workflow is triggered by pull requests.

func (GitHubWorkflow) RunsOnSynchronize

func (wf GitHubWorkflow) RunsOnSynchronize() bool

type GitHubWorkflowCollection

type GitHubWorkflowCollection map[string]GitHubWorkflow

GitHubWorkflowCollection represents a collection of GitHub Actions workflows. It is a map where the key is the workflow's path.

func (GitHubWorkflowCollection) PolicyBotConfig

func (workflows GitHubWorkflowCollection) PolicyBotConfig() policy.Config

type NopRenamerRemover

type NopRenamerRemover struct {
	io.WriteCloser
}

NopRenamerRemover is a writeCloserRenamerRemover that does nothing. It is used when the destination is standard output, which does not need to be renamed or removed.

func (NopRenamerRemover) Remove

func (NopRenamerRemover) Remove() error

func (NopRenamerRemover) RenameTo

func (NopRenamerRemover) RenameTo(dest string) error

type RenamingWriter

type RenamingWriter struct {
	WriteCloserRenamerRemover
	// contains filtered or unexported fields
}

RenamingWriter writes to a temporary file, and then renames it to the final destination on close. This is to avoid writing a partial file in case of an error. Any type can be used here, as long as it is an io.WriteCloser which implements renaming and removing the temporary file, corresponding to our `Close()` and `Abort()` methods. This means a fake implementation can be used in tests.

func (*RenamingWriter) Abort

func (rw *RenamingWriter) Abort() error

Abort closes the writer and removes the temporary file. It is used when exiting with an error.

func (*RenamingWriter) Close

func (rw *RenamingWriter) Close() error

Close closes the writer and renames the temporary file to the destination. It is used when exiting successfully.

func (*RenamingWriter) UnmarshalFlag

func (rw *RenamingWriter) UnmarshalFlag(value string) error

UnmarshalFlag implements the flag.Value interface for renamingWriter, used when parsing the destination from a commandline flag. If the value is "-", the writer writes to standard output. Otherwise, it writes to a temporary file, which is renamed to the final destination on success and removed on error.

type WriteCloserRenamerRemover

type WriteCloserRenamerRemover interface {
	io.WriteCloser
	RenameTo(dest string) error
	Remove() error
}

Jump to

Keyboard shortcuts

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