migration

package module
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: MIT Imports: 16 Imported by: 0

README

Migration

Go module for Estafette Builds and Releases migration from one SCM source to other

API

API specification for migration is defined in migration.openapi.yaml

Client

Follow below steps to use go client

  • Install migration client

    go get github.com/estafette/migration
    
  • Create clientID and secret in Estafette UI

  • Use client to queue migration task

    Example:

    package main
    
    import "github.com/estafette/migration"
    
    func main()  {
        client := migration.NewClient("https://api.estafette.io", "<Client-ID>", "<Client-Secret>")
        callbackURL := "https://your-callback-url"
        req := migration.TaskRequest{
            ID:          "existing-id", // optional if creating a new migration task
            FromSource:  "bitbucket.com",
            FromOwner:   "owner1",
            FromName:    "repo1",
            ToSource:    "github.com",
            ToOwner:     "owner1",
            ToName:      "repo1",
            CallbackURL: &callbackURL, // optional
            Restart:     migration.BuildLogsStage, // optional, default is LastStage (handled by the server)
        }
        task, err := client.QueueMigration(req)
        if err != nil {
            panic(err)
        }
        fmt.Sprintf("Migration task %v queued", task.ID)
    }
    
  • Use client to get status of migration task

    Example:

    package main
    
    import "github.com/estafette/migration"
    
    func main()  {
        client := migration.NewClient("https://api.estafette.io", "<Client-ID>", "<Client-Secret>")
        callbackURL := "https://your-callback-url"
        req := migration.TaskRequest{
            ID:          "existing-id", // optional if creating a new migration task
            FromSource:  "bitbucket.com",
            FromOwner:   "owner1",
            FromName:    "repo1",
            ToSource:    "github.com",
            ToOwner:     "owner1",
            ToName:      "repo1",
            CallbackURL: &callbackURL, // optional
            Restart:     migration.BuildLogsStage, // optional, default is LastStage (handled by the server)
        }
        task, err := client.QueueMigration(req)
        if err != nil {
            panic(err)
        }
        fmt.Sprintf("Migration task %v queued", task.ID)
    }
    

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthFailed = fmt.Errorf("authentication failed")
)

Functions

func CallbackExecutor added in v0.4.0

func CallbackExecutor(_ context.Context, task *Task) error

CallbackExecutor calls the callback URL if it's set.

func CompletedExecutor added in v0.4.0

func CompletedExecutor(_ context.Context, task *Task) error

CompletedExecutor set Task.Status to StatusCompleted.

Types

type Change

type Change struct {
	FromID int64
	ToID   int64
}

type Changes added in v0.6.0

type Changes struct {
	Releases      int `json:"releases,omitempty"`
	ReleaseLogs   int `json:"releaseLogs,omitempty"`
	Builds        int `json:"builds,omitempty"`
	BuildLogs     int `json:"buildLogs,omitempty"`
	BuildVersions int `json:"buildVersions,omitempty"`
}

type Client

type Client interface {
	// Queue task in estafette. If the ID of the task is not provided,
	// it will be generated in Estafette server else existing task is updated
	Queue(request Request) (*Task, error)
	// GetMigrationByID of migration task using task ID
	GetMigrationByID(taskID string) (*Task, error)
	// RollbackMigration task in estafette.
	RollbackMigration(taskID string) (*Changes, error)
	// GetMigrations returns all migration tasks
	GetMigrations() ([]*Task, error)
	// GetMigrationByFromRepo of migration task using task ID
	GetMigrationByFromRepo(source, owner, name string) (*Task, error)
	GetPipelineBuildStatus(source, owner, name, branch, revisionID string) (string, error)
	// UnArchivePipeline un-archives the pipeline
	UnArchivePipeline(source, owner, repo string) error
	// ArchivePipeline archives the pipeline
	ArchivePipeline(source, owner, repo string) error
}

Client for the estafette-ci-api migration API

func NewClient

func NewClient(serverURL, clientID, clientSecret string) Client

NewClient returns a new migration API Client for estafette-ci-api

type Executor

type Executor func(ctx context.Context, task *Task) error

Executor is a function that executes a migration task and returns any changes and if it succeeded.

type LogType

type LogType string
const (
	BuildLog   LogType = "builds"
	ReleaseLog LogType = "releases"
)

type PagedBuildsResponse added in v0.8.4

type PagedBuildsResponse struct {
	Items      []*contracts.Build   `json:"items"`
	Pagination contracts.Pagination `json:"pagination"`
}

type Request added in v0.4.6

type Request struct {
	ID          string    `json:"id,omitempty"`
	FromSource  string    `json:"fromSource"`
	FromOwner   string    `json:"fromOwner"`
	FromName    string    `json:"fromName"`
	ToSource    string    `json:"toSource"`
	ToOwner     string    `json:"toOwner"`
	ToName      string    `json:"toName"`
	CallbackURL *string   `json:"callbackURL,omitempty"`
	Restart     StageName `json:"restart,omitempty"`
}

type Stage

type Stage interface {
	Name() StageName
	Success() Step
	Failure() Step
	Execute(ctx context.Context, task *Task) bool
}

type StageName

type StageName string
const (
	// LastStage used when restarting build
	LastStage              StageName = "last_stage"
	ReleasesStage          StageName = "releases"
	ReleaseLogsStage       StageName = "release_logs"
	ReleaseLogObjectsStage StageName = "release_log_objects"
	BuildsStage            StageName = "builds"
	BuildLogsStage         StageName = "build_logs"
	BuildLogObjectsStage   StageName = "build_log_objects"
	BuildVersionsStage     StageName = "build_versions"
	ComputedTablesStage    StageName = "computed_tables"
	ArchiveStage           StageName = "archive"
	CallbackStage          StageName = "callback"
	CompletedStage         StageName = "completed"
)

func (StageName) FailedStep added in v0.4.0

func (sn StageName) FailedStep() Step

FailedStep for this stage name

func (StageName) SuccessStep added in v0.4.0

func (sn StageName) SuccessStep() Step

SuccessStep for this stage name

type Stages added in v0.4.0

type Stages interface {
	Current() Stage
	ExecuteNext(ctx context.Context) bool
	HasNext() bool
	Len() int
	Set(name StageName, executor Executor) Stages
}

func NewStages added in v0.4.0

func NewStages(updater Updater, task *Task) Stages

NewStages creates a new Stages instance which uses the given Updater to update the status of tasks.

type Status

type Status int
const (
	StatusQueued Status = iota
	StatusInProgress
	StatusFailed
	StatusCompleted
	StatusCanceled
)
const StatusUnset Status = -1

func StatusFrom

func StatusFrom(str string) Status

func (*Status) MarshalJSON

func (s *Status) MarshalJSON() ([]byte, error)

func (*Status) Scan added in v0.3.0

func (s *Status) Scan(src any) error

func (*Status) String

func (s *Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(data []byte) error

func (*Status) Value added in v0.3.0

func (s *Status) Value() (driver.Value, error)

type Step

type Step int
const (
	StepWaiting                 Step = 0
	StepReleasesFailed          Step = 11
	StepReleasesDone            Step = 12
	StepReleaseLogsFailed       Step = 21
	StepReleaseLogsDone         Step = 22
	StepReleaseLogObjectsFailed Step = 31
	StepReleaseLogObjectsDone   Step = 32
	StepBuildsFailed            Step = 41
	StepBuildsDone              Step = 42
	StepBuildLogsFailed         Step = 51
	StepBuildLogsDone           Step = 52
	StepBuildLogObjectsFailed   Step = 61
	StepBuildLogObjectsDone     Step = 62
	StepBuildVersionsFailed     Step = 71
	StepBuildVersionsDone       Step = 72
	StepComputedTablesFailed    Step = 81
	StepComputedTablesDone      Step = 82
	StepArchiveFailed           Step = 89
	StepArchiveDone             Step = 90
	StepCallbackFailed          Step = 91
	StepCallbackDone            Step = 92
	StepCompletionFailed        Step = 991
	StepCompletionDone          Step = 992
)

func StepFrom

func StepFrom(str string) Step

func (*Step) MarshalJSON

func (s *Step) MarshalJSON() ([]byte, error)

func (*Step) Scan added in v0.3.0

func (s *Step) Scan(src any) error

func (*Step) String

func (s *Step) String() string

func (*Step) UnmarshalJSON

func (s *Step) UnmarshalJSON(data []byte) error

func (*Step) Value added in v0.3.0

func (s *Step) Value() (driver.Value, error)

type Task

type Task struct {
	Request       `json:",inline"`
	Status        Status        `json:"status"`
	LastStep      Step          `json:"lastStep"`
	Builds        int           `json:"builds"`
	Releases      int           `json:"releases"`
	TotalDuration time.Duration `json:"totalDuration"`
	ErrorDetails  *string       `json:"errorDetails,omitempty"`
	QueuedAt      time.Time     `json:"queuedAt,omitempty"`
	UpdatedAt     time.Time     `json:"updatedAt,omitempty"`
}

func (*Task) FromFQN

func (t *Task) FromFQN() string

func (*Task) SqlArgs added in v0.2.0

func (t *Task) SqlArgs() []sql.NamedArg

func (*Task) ToFQN

func (t *Task) ToFQN() string

type Updater added in v0.4.0

type Updater func(ctx context.Context, task *Task) error

Jump to

Keyboard shortcuts

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