analyser

package
v0.0.0-...-0eb6aec Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2017 License: BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ArgBaseBranch replaces tool arg with the name of the base branch
	ArgBaseBranch = "%BASE_BRANCH%"
)
View Source
const (

	// DockerDefaultImage defines the default docker image that can be used
	// to run checks.
	DockerDefaultImage = "gopherci/gopherci-env:latest"
)
View Source
const MaxIssueComments = 10

MaxIssueComments is the maximum number of comments that will be written on a pull request by writeissues. a pr may have more comments written if writeissues is called multiple times, such is multiple syncronise events.

Variables

This section is empty.

Functions

func Analyse

func Analyse(ctx context.Context, logger logger.Logger, exec Executer, cloner Cloner, configReader ConfigReader, refReader RefReader, config Config, analysis *db.Analysis) error

Analyse downloads a repository set in config in an environment provided by exec, running the series of tools. Writes results to provided analysis, or an error. The repository is expected to contain at least one Go package.

func Suppress

func Suppress(issues []db.Issue, max int) (int, []db.Issue)

Suppress returns a maximum amount of issues, if any are suppressed the total number suppressed is also returned.

Types

type Analyser

type Analyser interface {
	// NewExecuter returns an Executer with the working directory set to
	// $GOPATH/src/<goSrcPath>.
	NewExecuter(ctx context.Context, goSrcPath string) (Executer, error)
}

An Analyser is builds an isolated execution environment to run checks in. It should provide isolation from other environments and support being called concurrently.

type Cloner

type Cloner interface {
	Clone(context.Context, Executer) error
}

A Cloner uses the executer to clone the root of a repository into the current working directory.

type Config

type Config struct {
	// HeadRef is the name of the reference containing changes.
	HeadRef string
}

Config hold configuration options for use in analyser. All options are required.

type ConfigReader

type ConfigReader interface {
	Read(context.Context, Executer) (RepoConfig, error)
}

A ConfigReader returns a repository's configuration.

type Docker

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

Docker is an Analyser that provides an Executer to build projects inside Docker containers.

func NewDocker

func NewDocker(logger logger.Logger, imageName string, memLimit int) (*Docker, error)

NewDocker returns a Docker which uses imageName as a container to build projects. If memLimit is > 0, limit the amount of memory (MiB) a process inside the container can use, this isn't a limit on the container itself.

func (*Docker) NewExecuter

func (d *Docker) NewExecuter(ctx context.Context, goSrcPath string) (Executer, error)

NewExecuter implements Analyser interface by creating and starting a docker container.

type DockerExecuter

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

DockerExecuter is an Executer that runs commands in a contained environment for a single project.

func (*DockerExecuter) Execute

func (e *DockerExecuter) Execute(ctx context.Context, args []string) ([]byte, error)

Execute implements the Executer interface and runs commands inside a docker container.

func (*DockerExecuter) Stop

func (e *DockerExecuter) Stop(ctx context.Context) error

Stop stops and removes a container ignoring any errors.

type Executer

type Executer interface {
	// Execute executes a command and returns the combined stdout and stderr,
	// along with an error if any. Must not be called after Stop(). If the
	// command returns a non-zero exit code, an error of type NonZeroError
	// is returned.
	Execute(context.Context, []string) ([]byte, error)
	// Stop stops the executer and allows it to cleanup, if applicable.
	Stop(context.Context) error
}

Executer executes a single command in a contained environment.

type FileSystem

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

FileSystem is an Analyser than provides an Executer to build contained environments on the file system.

FileSystem is safe to use concurrently, as all directories are created with random file names.

func NewFileSystem

func NewFileSystem(base string, memLimit int) (*FileSystem, error)

NewFileSystem returns an FileSystem which uses the path base to build contained environments on the file system. If memLimit is > 0, limit the amount of memory (MiB) a process can use.

func (*FileSystem) NewExecuter

func (fs *FileSystem) NewExecuter(_ context.Context, goSrcPath string) (Executer, error)

NewExecuter implements the Analyser interface

type FileSystemExecuter

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

FileSystemExecuter is an Executer that runs commands in a contained environment.

func (*FileSystemExecuter) Execute

func (e *FileSystemExecuter) Execute(ctx context.Context, args []string) ([]byte, error)

Execute implements the Executer interface

func (*FileSystemExecuter) Stop

Stop implements the Executer interface

type FixedRef

type FixedRef struct {
	BaseRef string
}

FixedRef is a RefReader for handling events where we know the base ref and can just return the string.

func (*FixedRef) Base

func (b *FixedRef) Base(ctx context.Context, exec Executer) (string, error)

Base implements the RefReader interface.

type MergeBase

type MergeBase struct{}

MergeBase is a RefReader for handling pull requests by using git's merge-base tool to find the common ancestor between HEAD and FETCH_HEAD. It expects head to already be checked out, and base to be fetched with full history.

func (*MergeBase) Base

func (b *MergeBase) Base(ctx context.Context, exec Executer) (string, error)

Base implements the RefReader interface.

type NonZeroError

type NonZeroError struct {
	ExitCode int // ExitCode is the non zero exit code
	// contains filtered or unexported fields
}

NonZeroError maybe returned by an Executer when the command executed returns with a non-zero exit status.

func (*NonZeroError) Error

func (e *NonZeroError) Error() string

Error implements the error interface.

type PullRequestCloner

type PullRequestCloner struct {
	HeadURL string
	HeadRef string
	BaseURL string
	BaseRef string
}

PullRequestCloner is a Cloner for handling cloning the HeadURL at HeadRef and also fetches BaseURL at BaseRef.

func (*PullRequestCloner) Clone

func (c *PullRequestCloner) Clone(ctx context.Context, exec Executer) error

Clone implements the Cloner interface.

type PushCloner

type PushCloner struct {
	HeadURL string
	HeadRef string
}

PushCloner is a Cloner for handling cloning of HeadURL and checking out HeadRef.

func (*PushCloner) Clone

func (c *PushCloner) Clone(ctx context.Context, exec Executer) error

Clone implements the Cloner interface.

type RefReader

type RefReader interface {
	Base(context.Context, Executer) (string, error)
}

RefReader returns the base reference of a repository.

type RepoConfig

type RepoConfig struct {
	APTPackages []string `yaml:"apt_packages"`
	Tools       []db.Tool
}

RepoConfig contains the analyser configuration for the repository.

type Reporter

type Reporter interface {
	Report(context.Context, []db.Issue) error
}

A Reporter reports the issues, and may be called with 0 or more issues.

type YAMLConfig

type YAMLConfig struct {
	Tools []db.Tool // Preset tools to use, before per repo config has been applied
}

YAMLConfig implements a ConfigReader by reading a yaml configuration file from the repositories root.

func (*YAMLConfig) Read

func (c *YAMLConfig) Read(ctx context.Context, exec Executer) (RepoConfig, error)

Read implements the ConfigReader interface.

Jump to

Keyboard shortcuts

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