db

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: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analysis

type Analysis struct {
	ID             int            `db:"id"`
	InstallationID int            `db:"installation_id"`
	RepositoryID   int            `db:"repository_id"`
	CommitFrom     string         `db:"commit_from"`
	CommitTo       string         `db:"commit_to"`
	RequestNumber  int            `db:"request_number"`
	Status         AnalysisStatus `db:"status"`
	CreatedAt      time.Time      `db:"created_at"`

	// When an analysis is finished
	CloneDuration Duration `db:"clone_duration"` // CloneDuration is the wall clock time taken to run clone.
	DepsDuration  Duration `db:"deps_duration"`  // DepsDuration is the wall clock time taken to fetch dependencies.
	TotalDuration Duration `db:"total_duration"` // TotalDuration is the wall clock time taken for the entire analysis.
	Tools         map[ToolID]AnalysisTool
}

Analysis represents a single analysis of a repository at a point in time.

func NewAnalysis

func NewAnalysis() *Analysis

NewAnalysis returns a ready to use analysis.

func (*Analysis) HTMLURL

func (a *Analysis) HTMLURL(prefix string) string

HTMLURL returns the URL to view the analysis.

func (*Analysis) IsPush

func (a *Analysis) IsPush() bool

IsPush returns true if the analysis was triggered by a push, or false if it was triggered by pull/merge request.

func (*Analysis) Issues

func (a *Analysis) Issues() []Issue

Issues returns all the issues by each tool as a slice.

type AnalysisStatus

type AnalysisStatus string

AnalysisStatus represents a status in the analysis table.

const (
	AnalysisStatusPending AnalysisStatus = "Pending" // Analysis is pending/started (not finished/completed).
	AnalysisStatusFailure AnalysisStatus = "Failure" // Analysis is marked as failed.
	AnalysisStatusSuccess AnalysisStatus = "Success" // Analysis is marked as successful.
	AnalysisStatusError   AnalysisStatus = "Error"   // Analysis failed due to an internal error.
)

AnalysisStatus type/enum mappings to the analysis table.

func (*AnalysisStatus) Scan

func (s *AnalysisStatus) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

type AnalysisTool

type AnalysisTool struct {
	Tool     *Tool    // Tool is the tool.
	ToolID   ToolID   // ToolID is the ID of the tool.
	Duration Duration // Duration is the wall clock time taken to run the tool.
	Issues   []Issue  // Issues maybe nil if no issues found.
}

AnalysisTool contains the timing and result of an individual tool's analysis.

type DB

type DB interface {
	// AddGHInstallation records a new installation.
	AddGHInstallation(installationID, accountID, senderID int) error
	// RemoveGHInstallation removes an installation.
	RemoveGHInstallation(installationID int) error
	// GetGHInstallation returns an installation for a given installationID, returns
	// nil if no installation was found, or an error occurs.
	GetGHInstallation(installationID int) (*GHInstallation, error)
	// ListTools returns all tools. Returns nil if no tools were found, error will
	// be non-nil if an error occurs.
	ListTools() ([]Tool, error)
	// StartAnalysis records a new analysis. RequestNumber is a GitHub Pull Request
	// ID (or Merge Request) and may be 0 for none, if 0 commitTo must be set,
	// but commitFrom may be blank if this is the first push.
	StartAnalysis(ghInstallationID, repositoryID int, commitFrom, commitTo string, requestNumber int) (*Analysis, error)
	// FinishAnalysis marks a status as finished.
	FinishAnalysis(analysisID int, status AnalysisStatus, analysis *Analysis) error
	// GetAnalysis returns an analysis for a given analysisID, returns nil if no
	// analysis was found, or an error occurs.
	GetAnalysis(analysisID int) (*Analysis, error)
	// AnalysisOutputs returns the ordered output from the database.
	AnalysisOutputs(analysisID int) ([]Output, error)
	// ExecRecorder records the analysis in the database by wrapping the executer.
	ExecRecorder(analysisID int, exec Executer) Executer
}

DB interface provides access to a persistent database.

type Duration

type Duration int64

Duration is similar to a time.Duration but with extra methods to better handle mysql DB type TIME(3).

func (*Duration) Scan

func (d *Duration) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (Duration) String

func (d Duration) String() string

String implements the fmt.Stringer interface.

func (Duration) Value

func (d Duration) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Executer

type Executer interface {
	Execute(context.Context, []string) ([]byte, error)
	Stop(context.Context) error
}

Executer is the same interface as analyser.Executer, but due to import cycles must be redefined here.

type GHInstallation

type GHInstallation struct {
	ID             int
	InstallationID int
	AccountID      int
	SenderID       int
	// contains filtered or unexported fields
}

GHInstallation represents a row from the gh_installations table.

func (GHInstallation) IsEnabled

func (i GHInstallation) IsEnabled() bool

IsEnabled returns true if the installation is enabled.

type Issue

type Issue struct {
	// ID is an internal issue ID
	ID int
	// Path is the relative path name of the file.
	Path string
	// Line is the line number of the file.
	Line int
	// HunkPos is the position relative to the files first hunk.
	HunkPos int
	// Issue is the issue.
	Issue string // maybe this should be issue
}

Issue contains file, position and string describing a single issue.

type MockDB

type MockDB struct {
	Tools []Tool
	// contains filtered or unexported fields
}

MockDB is an in-memory database repository implementing the DB interface used for testing

func NewMockDB

func NewMockDB() *MockDB

NewMockDB returns an MockDB

func (*MockDB) AddGHInstallation

func (db *MockDB) AddGHInstallation(installationID, accountID, senderID int) error

AddGHInstallation implements DB interface

func (*MockDB) AnalysisOutputs

func (db *MockDB) AnalysisOutputs(analysisID int) ([]Output, error)

AnalysisOutputs implements the DB interface.

func (*MockDB) EnableGHInstallation

func (db *MockDB) EnableGHInstallation(installationID int) error

EnableGHInstallation enables a gh installation

func (*MockDB) ExecRecorder

func (db *MockDB) ExecRecorder(analysisID int, executer Executer) Executer

ExecRecorder implements the DB interface.

func (*MockDB) FinishAnalysis

func (db *MockDB) FinishAnalysis(analysisID int, status AnalysisStatus, analysis *Analysis) error

FinishAnalysis implements the DB interface.

func (*MockDB) ForceError

func (db *MockDB) ForceError(err error)

ForceError forces MockDB to return err on all methods that return an error.

func (*MockDB) GetAnalysis

func (db *MockDB) GetAnalysis(analysisID int) (*Analysis, error)

GetAnalysis implements the DB interface.

func (*MockDB) GetGHInstallation

func (db *MockDB) GetGHInstallation(installationID int) (*GHInstallation, error)

GetGHInstallation implements DB interface

func (*MockDB) ListTools

func (db *MockDB) ListTools() ([]Tool, error)

ListTools implements DB interface

func (*MockDB) RemoveGHInstallation

func (db *MockDB) RemoveGHInstallation(installationID int) error

RemoveGHInstallation implements DB interface

func (*MockDB) StartAnalysis

func (db *MockDB) StartAnalysis(ghInstallationID, repositoryID int, commitFrom, commitTo string, requestNumber int) (*Analysis, error)

StartAnalysis implements the DB interface.

type Output

type Output struct {
	ID         int      `db:"id"`
	AnalysisID int      `db:"analysis_id"`
	Arguments  string   `db:"arguments"`
	Duration   Duration `db:"duration"` // Duration is the wall clock time taken to run.
	Output     string   `db:"output"`
}

Output represents a row in the outputs table.

type SQLDB

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

SQLDB is a sql database repository implementing the DB interface.

func NewSQLDB

func NewSQLDB(sqlDB *sql.DB, driverName string) (*SQLDB, error)

NewSQLDB returns an SQLDB.

func (*SQLDB) AddGHInstallation

func (db *SQLDB) AddGHInstallation(installationID, accountID, senderID int) error

AddGHInstallation implements the DB interface.

func (*SQLDB) AnalysisOutputs

func (db *SQLDB) AnalysisOutputs(analysisID int) ([]Output, error)

AnalysisOutputs implements the DB interface.

func (*SQLDB) Cleanup

func (db *SQLDB) Cleanup(ctx context.Context, logger logger.Logger)

Cleanup runs background cleanup tasks, such as purging old records.

func (*SQLDB) ExecRecorder

func (db *SQLDB) ExecRecorder(analysisID int, executer Executer) Executer

ExecRecorder implements the DB interface.

func (*SQLDB) FinishAnalysis

func (db *SQLDB) FinishAnalysis(analysisID int, status AnalysisStatus, analysis *Analysis) error

FinishAnalysis implements the DB interface.

func (*SQLDB) GetAnalysis

func (db *SQLDB) GetAnalysis(analysisID int) (*Analysis, error)

GetAnalysis implements the DB interface.

func (*SQLDB) GetGHInstallation

func (db *SQLDB) GetGHInstallation(installationID int) (*GHInstallation, error)

GetGHInstallation implements the DB interface.

func (*SQLDB) ListTools

func (db *SQLDB) ListTools() ([]Tool, error)

ListTools implements the DB interface.

func (*SQLDB) RemoveGHInstallation

func (db *SQLDB) RemoveGHInstallation(installationID int) error

RemoveGHInstallation implements the DB interface.

func (*SQLDB) StartAnalysis

func (db *SQLDB) StartAnalysis(ghInstallationID, repositoryID int, commitFrom, commitTo string, requestNumber int) (*Analysis, error)

StartAnalysis implements the DB interface.

func (*SQLDB) WriteExecution

func (db *SQLDB) WriteExecution(analysisID int, args []string, d time.Duration, output []byte) error

WriteExecution writes the results of an execution to the database.

type SQLExecuteWriter

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

SQLExecuteWriter wraps an Executer and writes the results of execution to db.

func (*SQLExecuteWriter) Execute

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

Execute implements the Execute interface by running the wrapped executer and storing the results in an SQL database.

func (*SQLExecuteWriter) Stop

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

Stop implements the Execute interface.

type Tool

type Tool struct {
	ID     ToolID `db:"id"`
	Name   string `db:"name"`
	URL    string `db:"url"`
	Path   string `db:"path"`
	Args   string `db:"args"`
	Regexp string `db:"regexp"`
}

Tool represents a single tool in the tools table.

type ToolID

type ToolID int

ToolID is the primary key on the tools table.

Jump to

Keyboard shortcuts

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