Documentation
¶
Index ¶
- Variables
- func UserCacheDir() (string, error)
- type CampaignSpec
- type CampaignSpecID
- type ChangesetSpec
- type ChangesetSpecID
- type ChangesetTemplate
- type ChangesetTemplateContext
- type CreatedChangeset
- type ExecutionCache
- type ExecutionCacheKey
- type ExecutionDiskCache
- type ExecutionNoOpCache
- func (ExecutionNoOpCache) Clear(ctx context.Context, key ExecutionCacheKey) error
- func (ExecutionNoOpCache) Get(ctx context.Context, key ExecutionCacheKey) (result ExecutionResult, found bool, err error)
- func (ExecutionNoOpCache) Set(ctx context.Context, key ExecutionCacheKey, result ExecutionResult) error
- type ExecutionResult
- type Executor
- type ExecutorOpts
- type ExpandedGitCommitDescription
- type ExternalChangeset
- type GitCommitAuthor
- type GitCommitDescription
- type Group
- type ImportChangeset
- type LogManager
- type OnQueryOrRepository
- type Output
- type Outputs
- type RepoFetcher
- type RepoZip
- type Service
- func (svc *Service) ApplyCampaign(ctx context.Context, spec CampaignSpecID) (*graphql.Campaign, error)
- func (svc *Service) CreateCampaignSpec(ctx context.Context, namespace, spec string, ids []ChangesetSpecID) (CampaignSpecID, string, error)
- func (svc *Service) CreateChangesetSpec(ctx context.Context, spec *ChangesetSpec) (ChangesetSpecID, error)
- func (svc *Service) DetermineFeatureFlags(ctx context.Context) error
- func (svc *Service) ExecuteCampaignSpec(ctx context.Context, repos []*graphql.Repository, x Executor, ...) ([]*ChangesetSpec, error)
- func (svc *Service) NewExecutionCache(dir string) ExecutionCache
- func (svc *Service) NewExecutor(opts ExecutorOpts) Executor
- func (svc *Service) NewRepoFetcher(dir string, cleanArchives bool) RepoFetcher
- func (svc *Service) NewWorkspaceCreator(ctx context.Context, cacheDir, tempDir string, steps []Step) WorkspaceCreator
- func (svc *Service) ParseCampaignSpec(in io.Reader) (*CampaignSpec, string, error)
- func (svc *Service) ResolveNamespace(ctx context.Context, namespace string) (string, error)
- func (svc *Service) ResolveRepositories(ctx context.Context, spec *CampaignSpec) ([]*graphql.Repository, error)
- func (svc *Service) ResolveRepositoriesOn(ctx context.Context, on *OnQueryOrRepository) ([]*graphql.Repository, error)
- func (svc *Service) SetDockerImages(ctx context.Context, spec *CampaignSpec, progress func(perc float64)) error
- type ServiceOpts
- type Step
- type StepChanges
- type StepContext
- type StepResult
- type Task
- type TaskExecutionErr
- type TaskLogger
- type TaskStatus
- type TransformChanges
- type UnsupportedRepoSet
- type Workspace
- type WorkspaceCreator
Constants ¶
This section is empty.
Variables ¶
var (
ErrMalformedOnQueryOrRepository = errors.New("malformed 'on' field; missing either a repository name or a query")
)
Functions ¶
func UserCacheDir ¶
Types ¶
type CampaignSpec ¶
type CampaignSpec struct {
Name string `json:"name,omitempty" yaml:"name"`
Description string `json:"description,omitempty" yaml:"description"`
On []OnQueryOrRepository `json:"on,omitempty" yaml:"on"`
Steps []Step `json:"steps,omitempty" yaml:"steps"`
TransformChanges *TransformChanges `json:"transformChanges,omitempty" yaml:"transformChanges,omitempty"`
ImportChangesets []ImportChangeset `json:"importChangesets,omitempty" yaml:"importChangesets"`
ChangesetTemplate *ChangesetTemplate `json:"changesetTemplate,omitempty" yaml:"changesetTemplate"`
}
func ParseCampaignSpec ¶
func ParseCampaignSpec(data []byte, features featureFlags) (*CampaignSpec, error)
type CampaignSpecID ¶
type CampaignSpecID string
type ChangesetSpec ¶
type ChangesetSpec struct {
BaseRepository string `json:"baseRepository"`
*ExternalChangeset
*CreatedChangeset
}
type ChangesetSpecID ¶
type ChangesetSpecID string
type ChangesetTemplate ¶
type ChangesetTemplate struct {
Title string `json:"title,omitempty" yaml:"title"`
Body string `json:"body,omitempty" yaml:"body"`
Branch string `json:"branch,omitempty" yaml:"branch"`
Commit ExpandedGitCommitDescription `json:"commit,omitempty" yaml:"commit"`
Published overridable.BoolOrString `json:"published" yaml:"published"`
}
type ChangesetTemplateContext ¶
type ChangesetTemplateContext struct {
// Steps are the changes made by all steps that were executed.
Steps *StepChanges
// Outputs are the outputs defined and initialized by the steps.
Outputs map[string]interface{}
// Repository is the repository in which the steps were executed.
Repository graphql.Repository
}
ChangesetTemplateContext represents the contextual information available when rendering a field of the ChangesetTemplate as a template.
func (*ChangesetTemplateContext) ToFuncMap ¶
func (tmplCtx *ChangesetTemplateContext) ToFuncMap() template.FuncMap
ToFuncMap returns a template.FuncMap to access fields on the StepContext in a text/template.
type CreatedChangeset ¶
type CreatedChangeset struct {
BaseRef string `json:"baseRef"`
BaseRev string `json:"baseRev"`
HeadRepository string `json:"headRepository"`
HeadRef string `json:"headRef"`
Title string `json:"title"`
Body string `json:"body"`
Commits []GitCommitDescription `json:"commits"`
Published interface{} `json:"published"`
}
type ExecutionCache ¶
type ExecutionCache interface {
Get(ctx context.Context, key ExecutionCacheKey) (result ExecutionResult, found bool, err error)
Set(ctx context.Context, key ExecutionCacheKey, result ExecutionResult) error
Clear(ctx context.Context, key ExecutionCacheKey) error
}
type ExecutionCacheKey ¶
type ExecutionCacheKey struct {
*Task
}
func (ExecutionCacheKey) Key ¶
func (key ExecutionCacheKey) Key() (string, error)
Key converts the key into a string form that can be used to uniquely identify the cache key in a more concise form than the entire Task.
type ExecutionDiskCache ¶
type ExecutionDiskCache struct {
Dir string
}
func (ExecutionDiskCache) Clear ¶
func (c ExecutionDiskCache) Clear(ctx context.Context, key ExecutionCacheKey) error
func (ExecutionDiskCache) Get ¶
func (c ExecutionDiskCache) Get(ctx context.Context, key ExecutionCacheKey) (ExecutionResult, bool, error)
func (ExecutionDiskCache) Set ¶
func (c ExecutionDiskCache) Set(ctx context.Context, key ExecutionCacheKey, result ExecutionResult) error
type ExecutionNoOpCache ¶
type ExecutionNoOpCache struct{}
ExecutionNoOpCache is an implementation of actionExecutionCache that does not store or retrieve cache entries.
func (ExecutionNoOpCache) Clear ¶
func (ExecutionNoOpCache) Clear(ctx context.Context, key ExecutionCacheKey) error
func (ExecutionNoOpCache) Get ¶
func (ExecutionNoOpCache) Get(ctx context.Context, key ExecutionCacheKey) (result ExecutionResult, found bool, err error)
func (ExecutionNoOpCache) Set ¶
func (ExecutionNoOpCache) Set(ctx context.Context, key ExecutionCacheKey, result ExecutionResult) error
type ExecutionResult ¶
type ExecutionResult struct {
// Diff is the produced by executing all steps.
Diff string `json:"diff"`
// ChangedFiles are files that have been changed by all steps.
ChangedFiles *StepChanges `json:"changedFiles"`
// Outputs are the outputs produced by all steps.
Outputs map[string]interface{} `json:"outputs"`
}
type Executor ¶
type Executor interface {
AddTask(repo *graphql.Repository, steps []Step, transform *TransformChanges, template *ChangesetTemplate)
LogFiles() []string
Start(ctx context.Context)
Wait() ([]*ChangesetSpec, error)
// LockedTaskStatuses calls the given function with the current state of
// the task statuses. Before calling the function, the statuses are locked
// to provide a consistent view of all statuses, but that also means the
// callback should be as fast as possible.
LockedTaskStatuses(func([]*TaskStatus))
}
type ExecutorOpts ¶
type ExecutorOpts struct {
Cache ExecutionCache
Creator WorkspaceCreator
Parallelism int
RepoFetcher RepoFetcher
Timeout time.Duration
ClearCache bool
KeepLogs bool
TempDir string
CacheDir string
}
type ExpandedGitCommitDescription ¶
type ExpandedGitCommitDescription struct {
Message string `json:"message,omitempty" yaml:"message"`
Author *GitCommitAuthor `json:"author,omitempty" yaml:"author"`
}
type ExternalChangeset ¶
type ExternalChangeset struct {
ExternalID string `json:"externalID"`
}
type GitCommitAuthor ¶
type GitCommitDescription ¶
type ImportChangeset ¶
type ImportChangeset struct {
Repository string `json:"repository" yaml:"repository"`
ExternalIDs []interface{} `json:"externalIDs" yaml:"externalIDs"`
}
type LogManager ¶
type LogManager struct {
// contains filtered or unexported fields
}
func NewLogManager ¶
func NewLogManager(dir string, keepLogs bool) *LogManager
func (*LogManager) AddTask ¶
func (lm *LogManager) AddTask(task *Task) (*TaskLogger, error)
func (*LogManager) Close ¶
func (lm *LogManager) Close() error
func (*LogManager) LogFiles ¶
func (lm *LogManager) LogFiles() []string
type OnQueryOrRepository ¶
type OnQueryOrRepository struct {
RepositoriesMatchingQuery string `json:"repositoriesMatchingQuery,omitempty" yaml:"repositoriesMatchingQuery"`
Repository string `json:"repository,omitempty" yaml:"repository"`
Branch string `json:"branch,omitempty" yaml:"branch"`
}
func (*OnQueryOrRepository) String ¶
func (on *OnQueryOrRepository) String() string
type RepoFetcher ¶
type RepoFetcher interface {
// Fetch must retrieve the given repository and return it as a RepoZip.
// This will generally imply that the file should be written to a temporary
// location on the filesystem.
Fetch(context.Context, *graphql.Repository) (RepoZip, error)
}
RepoFetcher abstracts the process of retrieving an archive for the given repository.
type RepoZip ¶
type RepoZip interface {
// Close must finalise the downloaded archive. If one or more temporary
// files were created, they should be deleted here.
Close() error
// Path must return the path to the archive on the filesystem.
Path() string
}
RepoZip implementations represent a downloaded repository archive.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(opts *ServiceOpts) *Service
func (*Service) ApplyCampaign ¶
func (*Service) CreateCampaignSpec ¶
func (svc *Service) CreateCampaignSpec(ctx context.Context, namespace, spec string, ids []ChangesetSpecID) (CampaignSpecID, string, error)
func (*Service) CreateChangesetSpec ¶
func (svc *Service) CreateChangesetSpec(ctx context.Context, spec *ChangesetSpec) (ChangesetSpecID, error)
func (*Service) DetermineFeatureFlags ¶
DetermineFeatureFlags fetches the version of the configured Sourcegraph instance and then sets flags on the Service itself to use features available in that version, e.g. gzip compression.
func (*Service) ExecuteCampaignSpec ¶
func (svc *Service) ExecuteCampaignSpec(ctx context.Context, repos []*graphql.Repository, x Executor, spec *CampaignSpec, progress func([]*TaskStatus), skipErrors bool) ([]*ChangesetSpec, error)
func (*Service) NewExecutionCache ¶
func (svc *Service) NewExecutionCache(dir string) ExecutionCache
func (*Service) NewExecutor ¶
func (svc *Service) NewExecutor(opts ExecutorOpts) Executor
func (*Service) NewRepoFetcher ¶
func (svc *Service) NewRepoFetcher(dir string, cleanArchives bool) RepoFetcher
func (*Service) NewWorkspaceCreator ¶
func (*Service) ParseCampaignSpec ¶
func (*Service) ResolveNamespace ¶
func (*Service) ResolveRepositories ¶
func (svc *Service) ResolveRepositories(ctx context.Context, spec *CampaignSpec) ([]*graphql.Repository, error)
func (*Service) ResolveRepositoriesOn ¶
func (svc *Service) ResolveRepositoriesOn(ctx context.Context, on *OnQueryOrRepository) ([]*graphql.Repository, error)
func (*Service) SetDockerImages ¶
func (svc *Service) SetDockerImages(ctx context.Context, spec *CampaignSpec, progress func(perc float64)) error
SetDockerImages updates the steps within the campaign spec to include the exact content digest to be used when running each step, and ensures that all Docker images are available, including any required by the service itself.
Progress information is reported back to the given progress function: perc will be a value between 0.0 and 1.0, inclusive.
type ServiceOpts ¶
type Step ¶
type Step struct {
Run string `json:"run,omitempty" yaml:"run"`
Container string `json:"container,omitempty" yaml:"container"`
Env env.Environment `json:"env,omitempty" yaml:"env"`
Files map[string]string `json:"files,omitempty" yaml:"files,omitempty"`
Outputs Outputs `json:"outputs,omitempty" yaml:"outputs,omitempty"`
// contains filtered or unexported fields
}
type StepChanges ¶
type StepChanges struct {
Modified []string `json:"modified"`
Added []string `json:"added"`
Deleted []string `json:"deleted"`
Renamed []string `json:"renamed"`
}
StepChanges are the changes made to files by a previous step in a repository.
type StepContext ¶
type StepContext struct {
// Outputs are the outputs set by the current and all previous steps.
Outputs map[string]interface{}
// Step is the result of the current step. Empty when evaluating the "run" field
// but filled when evaluating the "outputs" field.
Step StepResult
// PreviousStep is the result of the previous step. Empty when there is no
// previous step.
PreviousStep StepResult
// Repository is the Sourcegraph repository in which the steps are executed.
Repository graphql.Repository
}
StepContext represents the contextual information available when rendering a step's fields, such as "run" or "outputs", as templates.
func (*StepContext) ToFuncMap ¶
func (stepCtx *StepContext) ToFuncMap() template.FuncMap
ToFuncMap returns a template.FuncMap to access fields on the StepContext in a text/template.
type StepResult ¶
type StepResult struct {
// Stdout is the output produced by the step on standard out.
Stdout *bytes.Buffer
// Stderr is the output produced by the step on standard error.
Stderr *bytes.Buffer
// contains filtered or unexported fields
}
StepResult represents the result of a previously executed step.
func (StepResult) AddedFiles ¶
func (r StepResult) AddedFiles() []string
AddedFiles returns the files added by a step.
func (StepResult) DeletedFiles ¶
func (r StepResult) DeletedFiles() []string
DeletedFiles returns the files deleted by a step.
func (StepResult) ModifiedFiles ¶
func (r StepResult) ModifiedFiles() []string
ModifiedFiles returns the files modified by a step.
func (StepResult) RenamedFiles ¶
func (r StepResult) RenamedFiles() []string
RenamedFiles returns the new name of files that have been renamed by a step.
type Task ¶
type Task struct {
Repository *graphql.Repository
Steps []Step
Outputs map[string]interface{}
Template *ChangesetTemplate `json:"-"`
TransformChanges *TransformChanges `json:"-"`
}
type TaskExecutionErr ¶
func (TaskExecutionErr) Cause ¶
func (e TaskExecutionErr) Cause() error
func (TaskExecutionErr) Error ¶
func (e TaskExecutionErr) Error() string
func (TaskExecutionErr) StatusText ¶
func (e TaskExecutionErr) StatusText() string
type TaskLogger ¶
type TaskLogger struct {
// contains filtered or unexported fields
}
func (*TaskLogger) Close ¶
func (tl *TaskLogger) Close() error
func (*TaskLogger) Log ¶
func (tl *TaskLogger) Log(s string)
func (*TaskLogger) Logf ¶
func (tl *TaskLogger) Logf(format string, a ...interface{})
func (*TaskLogger) MarkErrored ¶
func (tl *TaskLogger) MarkErrored()
func (*TaskLogger) Path ¶
func (tl *TaskLogger) Path() string
func (*TaskLogger) PrefixWriter ¶
func (tl *TaskLogger) PrefixWriter(prefix string) io.Writer
type TaskStatus ¶
type TaskStatus struct {
RepoName string
Cached bool
LogFile string
EnqueuedAt time.Time
StartedAt time.Time
FinishedAt time.Time
// TODO: add current step and progress fields.
CurrentlyExecuting string
// ChangesetSpecs are the specs produced by executing the Task in a
// repository. With the introduction of `transformChanges` to the campaign
// spec, one Task can produce multiple ChangesetSpecs.
ChangesetSpecs []*ChangesetSpec
// Err is set if executing the Task lead to an error.
Err error
// contains filtered or unexported fields
}
func (*TaskStatus) Clone ¶
func (ts *TaskStatus) Clone() *TaskStatus
func (*TaskStatus) ExecutionTime ¶
func (ts *TaskStatus) ExecutionTime() time.Duration
func (*TaskStatus) FileDiffs ¶
func (ts *TaskStatus) FileDiffs() ([]*diff.FileDiff, bool, error)
FileDiffs returns the file diffs produced by the Task in the given repository. If no file diffs were produced, the task resulted in an error, or the task hasn't finished execution yet, the second return value is false.
func (*TaskStatus) IsCompleted ¶
func (ts *TaskStatus) IsCompleted() bool
func (*TaskStatus) IsRunning ¶
func (ts *TaskStatus) IsRunning() bool
type TransformChanges ¶
type TransformChanges struct {
Group []Group `json:"group,omitempty" yaml:"group"`
}
type UnsupportedRepoSet ¶
type UnsupportedRepoSet map[*graphql.Repository]struct{}
UnsupportedRepoSet provides a set to manage repositories that are on unsupported code hosts. This type implements error to allow it to be returned directly as an error value if needed.
func (UnsupportedRepoSet) Error ¶
func (e UnsupportedRepoSet) Error() string
type Workspace ¶
type Workspace interface {
// DockerRunOpts provides the options that should be given to `docker run`
// in order to use this workspace. Generally, this will be a set of mount
// options.
DockerRunOpts(ctx context.Context, target string) ([]string, error)
// WorkDir allows workspaces to specify the working directory that should be
// used when running Docker. If no specific working directory is needed,
// then the function should return nil.
WorkDir() *string
// Close is called once, after all steps have been executed and the diff has
// been calculated and stored outside the workspace. Implementations should
// delete the workspace when Close is called.
Close(ctx context.Context) error
// Changes is called after each step is executed, and should return the
// cumulative file changes that have occurred since Prepare was called.
Changes(ctx context.Context) (*StepChanges, error)
// Diff should return the total diff for the workspace. This may be called
// multiple times in the life of a workspace.
Diff(ctx context.Context) ([]byte, error)
}
Workspace implementations manage per-changeset storage when executing campaign step.
type WorkspaceCreator ¶
type WorkspaceCreator interface {
// Create creates a new workspace for the given repository and ZIP file.
Create(ctx context.Context, repo *graphql.Repository, zip string) (Workspace, error)
}
WorkspaceCreator implementations are used to create workspaces, which manage per-changeset persistent storage when executing campaign steps and are responsible for ultimately generating a diff.