plugsupport

package
v0.0.0-...-9994f1b Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 31 Imported by: 0

Documentation

Overview

Package plugsupport provides implementations for loading migrator plugins.

Users of the `migrator` tool should not import or use this package (just the base "go.chromium.org/infra/tools/migrator" package).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpReports

func DumpReports(ctx context.Context) *migrator.ReportDump

DumpReports returns all collected Report information within `ctx`.

func ExecuteCommit

func ExecuteCommit(ctx context.Context, projectDir ProjectDir) (*migrator.ReportDump, error)

ExecuteCommit implements "commit" subcommand.

func ExecuteRebase

func ExecuteRebase(ctx context.Context, projectDir ProjectDir) (*migrator.ReportDump, error)

ExecuteRebase implements "rebase" subcommand.

func ExecuteStatusCheck

func ExecuteStatusCheck(ctx context.Context, projectDir ProjectDir) (*migrator.ReportDump, error)

ExecuteStatusCheck implements "status" subcommand.

func ExecuteUpload

func ExecuteUpload(ctx context.Context, projectDir ProjectDir, force bool) (*migrator.ReportDump, error)

ExecuteUpload implements "upload" subcommand.

func Handle

func Handle(factory migrator.InstantiateAPI, cmd Command) int

Handle is called from within the plugin process to execute the command.

The return value becomes the process exit code.

func HasActionableReports

func HasActionableReports(ctx context.Context) (actionable bool)

HasActionableReports returns `true` if `ctx` contains any Reports where Actionable is true.

func InitReportSink

func InitReportSink(ctx context.Context) context.Context

InitReportSink adds a new empty ReportSink to context and returns the new context.

If there's an existing ReportSink, it will be hidden by this.

func Invoke

func Invoke(ctx context.Context, projectDir ProjectDir, pluginBin string, command Command) error

Invoke launches the plugin subprocess passing it the given command.

This eventually results in Handle call from within the plugin binary.

Blocks until the plugin subprocess exits and returns its error (if any).

func RemoteProject

func RemoteProject(ctx context.Context, projID string) migrator.Project

RemoteProject returns a new migrator.Project object for `projID`.

func RootContext

func RootContext(ctx context.Context) context.Context

RootContext constructs the root process context.

`ctx` is usually context.Background(). Must be called at most once, since it registers signal handlers.

Types

type Command

type Command struct {
	Action        string        // what action to perform, e.g. "scan"
	ProjectDir    ProjectDir    // an absolute path to the project directory
	ContextConfig ContextConfig // "instructions" how to setup the root context
	ScanConfig    ScanConfig    // parameters specific to the "scan" action
}

Command is passed to the plugin subprocess in a JSON-serialized form.

type ContextConfig

type ContextConfig struct {
	Logging           logging.Config
	Auth              auth.Options
	ConfigServiceHost string
}

ContextConfig contains serializable parameters for setting up a base context.

They are passed across processes to (presumably) get similar contexts across them.

We assume auth.Options are JSON-serializable. This is not guaranteed and stuff may break in the future. If this happens, a more advanced approach would be to use the `authctx` package to setup an authentication context in the `migrator` binary, and use it in the plugin subprocess.

func (*ContextConfig) Apply

func (r *ContextConfig) Apply(ctx context.Context) (context.Context, error)

Apply applies the config to the root context.

Always returns a non-nil context, even on errors.

type Filter

type Filter func(projectID string) bool

Filter reports true if we should visit the given project.

func NewFilter

func NewFilter(regexps []string) (Filter, error)

NewFilter constructs a filter from a list of regexps.

If the list is empty, returns a filter that rejects all projects.

func (Filter) Apply

func (f Filter) Apply(projs []*configpb.Project) []*configpb.Project

Apply returns projects that passed the filter.

type ProjectDir

type ProjectDir string

ProjectDir is an absolute path to a migrator project directory.

func FindProjectRoot

func FindProjectRoot(abspath string) (ProjectDir, error)

FindProjectRoot finds a migrator ProjectDir starting from `abspath` and working up towards the filesystem root.

func (ProjectDir) CheckoutDir

func (p ProjectDir) CheckoutDir(checkoutID string) string

CheckoutDir returns the path for a git checkout.

func (ProjectDir) CheckoutTemp

func (p ProjectDir) CheckoutTemp(checkoutID string) string

CheckoutTemp returns a temporary checkout directory.

During repo creation, the initial git repo is cloned here and then moved to its CheckoutDir() path on success.

func (ProjectDir) CleanTrash

func (p ProjectDir) CleanTrash() error

CleanTrash removes TrashDir().

func (ProjectDir) CommitMessageFile

func (p ProjectDir) CommitMessageFile() string

CommitMessageFile is the absolute path to the file with the commit message to use in `upload` subcommand.

func (ProjectDir) CommitReportPath

func (p ProjectDir) CommitReportPath() string

CommitReportPath returns the absolute path of the migrator project's CSV commit report file.

func (ProjectDir) ConfigDir

func (p ProjectDir) ConfigDir() string

ConfigDir returns the absolute path of the migrator project's config directory.

func (ProjectDir) ConfigFile

func (p ProjectDir) ConfigFile() string

ConfigFile returns the absolute path of the migrator project's main config file.

The existence of this file is used to determine if a folder is a migrator project.

func (ProjectDir) LoadConfigFile

func (p ProjectDir) LoadConfigFile() (*migratorpb.Config, error)

LoadConfigFile loads the migration project config.

func (ProjectDir) LoadProjectFilter

func (p ProjectDir) LoadProjectFilter() (Filter, error)

LoadProjectFilter loads the config and parses `projects_re` field there.

func (ProjectDir) MkTempDir

func (p ProjectDir) MkTempDir() (string, error)

MkTempDir generates a new temporary directory within TrashDir().

func (ProjectDir) PluginDir

func (p ProjectDir) PluginDir() string

PluginDir returns the absolute path of the migrator project's plugin code directory.

func (ProjectDir) ProjectLog

func (p ProjectDir) ProjectLog(projectID string) string

ProjectLog returns the absolute path of the scan log for a given LUCI project within this migrator project.

func (ProjectDir) RebaseReportPath

func (p ProjectDir) RebaseReportPath() string

RebaseReportPath returns the absolute path of the migrator project's CSV rebase report file.

func (ProjectDir) ScanReportPath

func (p ProjectDir) ScanReportPath() string

ScanReportPath returns the absolute path of the migrator project's CSV scan report file.

func (ProjectDir) StatusReportPath

func (p ProjectDir) StatusReportPath() string

StatusReportPath returns the absolute path of the migrator project's CSV status report file.

func (ProjectDir) TrashDir

func (p ProjectDir) TrashDir() string

TrashDir returns the absolute path of the migrator project's trash directory.

The trash directory is used to compile the plugin; New runs of migrator will make best-effort attempts to clean up this directory using CleanTrash().

func (ProjectDir) UploadReportPath

func (p ProjectDir) UploadReportPath() string

UploadReportPath returns the absolute path of the migrator project's CSV upload report file.

type ProjectTweaks

type ProjectTweaks struct {
	Reviewers []string // reviewer emails to send CLs to
	CC        []string // emails to CC CLs to
}

ProjectTweaks is config tweaks to apply to a particular LUCI project.

type ScanConfig

type ScanConfig struct {
	Squeaky bool
	Clean   bool
	Reapply bool
}

ScanConfig is passed from the main migrator binary to the plugin process.

type Tweaks

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

Tweaks represents loaded `tweaks` section of the migrator config file.

func LoadTweaks

func LoadTweaks(projectDir ProjectDir) (*Tweaks, error)

LoadTweaks parses `tweaks` section of the migrator config file.

func (*Tweaks) ProjectTweaks

func (t *Tweaks) ProjectTweaks(projectID string) *ProjectTweaks

ProjectTweaks returns config tweaks to apply to a particular LUCI project.

Directories

Path Synopsis
Package templates contains embedded plugin template content.
Package templates contains embedded plugin template content.

Jump to

Keyboard shortcuts

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