Documentation
¶
Index ¶
- type Analysis
- type AnalysisStatus
- type AnalysisTool
- type DB
- type Duration
- type Executer
- type GHInstallation
- type Issue
- type MockDB
- func (db *MockDB) AddGHInstallation(installationID, accountID, senderID int) error
- func (db *MockDB) AnalysisOutputs(analysisID int) ([]Output, error)
- func (db *MockDB) EnableGHInstallation(installationID int) error
- func (db *MockDB) ExecRecorder(analysisID int, executer Executer) Executer
- func (db *MockDB) FinishAnalysis(analysisID int, status AnalysisStatus, analysis *Analysis) error
- func (db *MockDB) ForceError(err error)
- func (db *MockDB) GetAnalysis(analysisID int) (*Analysis, error)
- func (db *MockDB) GetGHInstallation(installationID int) (*GHInstallation, error)
- func (db *MockDB) ListTools() ([]Tool, error)
- func (db *MockDB) RemoveGHInstallation(installationID int) error
- func (db *MockDB) StartAnalysis(ghInstallationID, repositoryID int, commitFrom, commitTo string, ...) (*Analysis, error)
- type Output
- type SQLDB
- func (db *SQLDB) AddGHInstallation(installationID, accountID, senderID int) error
- func (db *SQLDB) AnalysisOutputs(analysisID int) ([]Output, error)
- func (db *SQLDB) Cleanup(ctx context.Context, logger logger.Logger)
- func (db *SQLDB) ExecRecorder(analysisID int, executer Executer) Executer
- func (db *SQLDB) FinishAnalysis(analysisID int, status AnalysisStatus, analysis *Analysis) error
- func (db *SQLDB) GetAnalysis(analysisID int) (*Analysis, error)
- func (db *SQLDB) GetGHInstallation(installationID int) (*GHInstallation, error)
- func (db *SQLDB) ListTools() ([]Tool, error)
- func (db *SQLDB) RemoveGHInstallation(installationID int) error
- func (db *SQLDB) StartAnalysis(ghInstallationID, repositoryID int, commitFrom, commitTo string, ...) (*Analysis, error)
- func (db *SQLDB) WriteExecution(analysisID int, args []string, d time.Duration, output []byte) error
- type SQLExecuteWriter
- type Tool
- type ToolID
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.
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).
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 (*MockDB) AddGHInstallation ¶
AddGHInstallation implements DB interface
func (*MockDB) AnalysisOutputs ¶
AnalysisOutputs implements the DB interface.
func (*MockDB) EnableGHInstallation ¶
EnableGHInstallation enables a gh installation
func (*MockDB) ExecRecorder ¶
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 ¶
ForceError forces MockDB to return err on all methods that return an error.
func (*MockDB) GetAnalysis ¶
GetAnalysis implements the DB interface.
func (*MockDB) GetGHInstallation ¶
func (db *MockDB) GetGHInstallation(installationID int) (*GHInstallation, error)
GetGHInstallation implements DB interface
func (*MockDB) RemoveGHInstallation ¶
RemoveGHInstallation implements 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 (*SQLDB) AddGHInstallation ¶
AddGHInstallation implements the DB interface.
func (*SQLDB) AnalysisOutputs ¶
AnalysisOutputs implements the DB interface.
func (*SQLDB) ExecRecorder ¶
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 ¶
GetAnalysis implements the DB interface.
func (*SQLDB) GetGHInstallation ¶
func (db *SQLDB) GetGHInstallation(installationID int) (*GHInstallation, error)
GetGHInstallation implements the DB interface.
func (*SQLDB) RemoveGHInstallation ¶
RemoveGHInstallation implements the DB interface.
type SQLExecuteWriter ¶
type SQLExecuteWriter struct {
// contains filtered or unexported fields
}
SQLExecuteWriter wraps an Executer and writes the results of execution to db.