atlasaction

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Versioned workflow Commands
	CmdMigratePush       = "migrate/push"
	CmdMigrateLint       = "migrate/lint"
	CmdMigrateApply      = "migrate/apply"
	CmdMigrateDown       = "migrate/down"
	CmdMigrateTest       = "migrate/test"
	CmdMigrateAutoRebase = "migrate/autorebase"
	CmdMigrateHash       = "migrate/hash"
	CmdMigrateDiff       = "migrate/diff"
	// Declarative workflow Commands
	CmdSchemaPush        = "schema/push"
	CmdSchemaLint        = "schema/lint"
	CmdSchemaTest        = "schema/test"
	CmdSchemaPlan        = "schema/plan"
	CmdSchemaPlanApprove = "schema/plan/approve"
	CmdSchemaApply       = "schema/apply"
	// Monitoring Commands
	CmdMonitorSchema = "monitor/schema"
	// Copilot Commands
	CmdCopilot = "copilot"
)
View Source
const (
	StatePending  = "PENDING_USER"
	StateApproved = "APPROVED"
	StateAborted  = "ABORTED"
	StateApplied  = "APPLIED"
)

Variables

View Source
var (
	CommentsTmpl = template.Must(
		template.New("comments").
			Funcs(template.FuncMap{
				"execTime":     execTime,
				"appliedStmts": appliedStmts,
				"filterIssues": filterIssues,
				"stepIsError":  stepIsError,
				"repoLink": func(planLink string) string {

					if i := strings.LastIndex(planLink, "/plans/"); i != -1 {
						return planLink[:i]
					}
					return planLink
				},
				"stmtsDetected": func(plan *atlasexec.SchemaPlanFile) string {
					switch l := len(plan.Stmts); {
					case l == 0:
						return "No statements detected"
					case l == 1:
						return "1 new statement detected"
					default:
						return fmt.Sprintf("%d new statements detected", l)
					}
				},
				"filesDetected": func(files []*atlasexec.FileReport) string {
					switch l := len(files); {
					case l == 0:
						return "No migration files detected"
					case l == 1:
						return "1 new migration file detected"
					default:
						return fmt.Sprintf("%d new migration files detected", l)
					}
				},
				"fileNames": func(files []*atlasexec.FileReport) []string {
					names := make([]string, len(files))
					for i, f := range files {
						names[i] = f.Name
					}
					return names
				},
				"stepSummary": func(s *atlasexec.StepReport) string {
					if s.Text == "" {
						return s.Name
					}
					return s.Name + "\n" + s.Text
				},
				"stepDetails": func(s *atlasexec.StepReport) string {
					if s.Result == nil {
						return s.Error
					}
					var details []string
					for _, r := range s.Result.Reports {
						if t := r.Text; t != "" {
							details = append(details, fmt.Sprintf("**%s%s**", strings.ToUpper(t[:1]), t[1:]))
						}
						for _, d := range r.Diagnostics {
							if d.Code == "" {
								details = append(details, d.Text)
							} else {
								details = append(details, fmt.Sprintf("%[1]s [(%[2]s)](https://atlasgo.io/lint/analyzers#%[2]s)", d.Text, d.Code))
							}
						}
					}
					return strings.Join(details, "\n")
				},
				"firstUpper": func(s string) string {
					if s == "" {
						return ""
					}
					return strings.ToUpper(s[:1]) + s[1:]
				},
				"assetsImage": func(s string) (string, error) {
					u, err := url.Parse("https://release.ariga.io/images/assets")
					if err != nil {
						return "", err
					}
					u = u.JoinPath(s)
					u.RawQuery = "v=1"
					return u.String(), nil
				},
				"join": strings.Join,
				"codeblock": func(lang, code string) string {
					return fmt.Sprintf("\n\n```%s\n%s\n```\n\n", lang, strings.Trim(code, "\n"))
				},
				"details": func(label, details string) string {
					return fmt.Sprintf("<details><summary>%s</summary>%s</details>", label, details)
				},
				"link": func(text, href string) string {
					return fmt.Sprintf(`<a href=%q target="_blank">%s</a>`, href, text)
				},
				"image": func(args ...any) (string, error) {
					var attrs string
					var src any
					switch len(args) {
					case 1:
						src, attrs = args[0], fmt.Sprintf("src=%q", args...)
					case 2:
						src, attrs = args[1], fmt.Sprintf("width=%[1]q height=%[1]q src=%[2]q", args...)
					case 3:
						src, attrs = args[2], fmt.Sprintf("width=%q height=%q src=%q", args...)
					case 4:
						src, attrs = args[3], fmt.Sprintf("width=%q height=%q alt=%q src=%q", args...)
					default:
						return "", fmt.Errorf("invalid number of arguments %d", len(args))
					}

					return fmt.Sprintf(`<picture><source media="(prefers-color-scheme: light)" srcset=%q><img %s/></picture>`, src, attrs), nil
				},
				"nl2br": func(s string) string { return strings.ReplaceAll(s, "\n", "<br/>") },
				"nl2sp": func(s string) string { return strings.ReplaceAll(s, "\n", " ") },
			}).
			ParseFS(comments, "comments/*"),
	)
)
View Source
var ErrApprovalTimeout = errors.New("approval process timed out")

ErrApprovalTimeout is returned when the timeout is exceeded in the approval process.

Functions

func LintReport added in v1.4.0

func LintReport(commit string, r *atlasexec.SummaryReport) (*bitbucket.CommitReport, error)

LintReport generates a commit report for the given commit ID

func OldAgentHash added in v1.3.9

func OldAgentHash(src string) string

OldAgentHash computes a hash of the input. Used by the agent to determine if a new snapshot is needed.

Only here for backwards compatability as for new snapshots the Atlas CLI computed hash is used.

func RenderTemplate added in v1.3.0

func RenderTemplate(name string, data any) (string, error)

RenderTemplate renders the given template with the data.

Types

type Action added in v1.1.0

type Action interface {
	Logger
	// GetType returns the type of atlasexec trigger Type. e.g. "GITHUB_ACTION"
	// The value is used to identify the type on CI-Run page in Atlas Cloud.
	GetType() atlasexec.TriggerType
	// Getenv returns the value of the environment variable with the given name.
	Getenv(string) string
	// GetInput returns the value of the input with the given name.
	GetInput(string) string
	// SetOutput sets the value of the output with the given name.
	SetOutput(string, string)
	// GetTriggerContext returns the context of the trigger event.
	GetTriggerContext(context.Context) (*TriggerContext, error)
}

Action interface for Atlas.

type Actions added in v1.2.0

type Actions struct {
	Action
	Version     string
	Atlas       AtlasExec
	CmdExecutor func(ctx context.Context, name string, args ...string) *exec.Cmd
	CloudClient func(string, string, *atlasexec.Version) CloudClient
}

Actions holds the runtime for the actions to run. This helps to inject the runtime dependencies. Like the SCM client, Atlas client, etc.

func New added in v1.3.0

func New(opts ...Option) (*Actions, error)

New creates a new Actions based on the environment.

func (*Actions) Copilot added in v1.10.0

func (a *Actions) Copilot(ctx context.Context) error

Copilot runs the GitHub Action for "ariga/atlas-action/copilot".

func (*Actions) DeployRunContext added in v1.2.0

func (a *Actions) DeployRunContext() *atlasexec.DeployRunContext

DeployRunContext returns the run context for the `migrate/apply`, and `migrate/down` actions.

func (*Actions) GetArrayInput added in v1.3.0

func (a *Actions) GetArrayInput(name string) []string

GetArrayInput returns the array input with the given name. The input should be a string with new line separated values. Example: ```yaml

input: |-
  value1
  value2

```

func (*Actions) GetAtlasURLInput added in v1.3.0

func (a *Actions) GetAtlasURLInput(name string, paramsName ...string) string

GetAtlasURLInput returns the atlas URL input with the given name. paramsName is List of input names to be added as query parameters.

func (*Actions) GetBoolInput added in v1.2.0

func (a *Actions) GetBoolInput(name string) bool

GetBoolInput returns the boolean input with the given name. The input should be a string representation of boolean. (e.g. "true" or "false")

func (*Actions) GetDurationInput added in v1.2.0

func (a *Actions) GetDurationInput(name string) time.Duration

GetDurationInput returns the duration input with the given name. The input should be a string representation of time.Duration. (e.g. "1s")

func (*Actions) GetInputDefault added in v1.6.1

func (a *Actions) GetInputDefault(name, def string) string

GetInputDefault returns the input with the given name. If the input is empty, it returns the default value.

func (*Actions) GetURLInput added in v1.3.9

func (a *Actions) GetURLInput(name string) (*url.URL, error)

GetURLInput tries to parse the input as URL. In case of a parsing error, this function ensures the error does not leak any sensitive information.

func (*Actions) GetUin64Input added in v1.2.0

func (a *Actions) GetUin64Input(name string) uint64

GetUin64Input returns the uint64 input with the given name. The input should be a string representation of uint64. (e.g. "123")

func (*Actions) GetVarsInput added in v1.2.0

func (a *Actions) GetVarsInput(name string) atlasexec.VarArgs

GetVarsInput returns the vars input with the given name. The input should be a JSON string. Example: ```yaml

input: |-
  {
    "key1": "value1",
    "key2": "value2"
  }

```

func (*Actions) MigrateApply added in v1.2.0

func (a *Actions) MigrateApply(ctx context.Context) error

MigrateApply runs the GitHub Action for "ariga/atlas-action/migrate/apply".

func (*Actions) MigrateAutoRebase added in v1.5.1

func (a *Actions) MigrateAutoRebase(ctx context.Context) error

MigrateAutoRebase runs the Action for "ariga/atlas-action/migrate/autorebase"

func (*Actions) MigrateDiff added in v1.9.0

func (a *Actions) MigrateDiff(ctx context.Context) error

MigrateDiff runs the GitHub Action for "ariga/atlas-action/migrate/diff"

func (*Actions) MigrateDown added in v1.2.0

func (a *Actions) MigrateDown(ctx context.Context) (err error)

MigrateDown runs the GitHub Action for "ariga/atlas-action/migrate/down".

func (*Actions) MigrateHash added in v1.12.0

func (a *Actions) MigrateHash(ctx context.Context) error

func (*Actions) MigrateLint added in v1.2.0

func (a *Actions) MigrateLint(ctx context.Context) error

MigrateLint runs the GitHub Action for "ariga/atlas-action/migrate/lint"

func (*Actions) MigratePush added in v1.2.0

func (a *Actions) MigratePush(ctx context.Context) error

MigratePush runs the GitHub Action for "ariga/atlas-action/migrate/push"

func (*Actions) MigrateTest added in v1.2.0

func (a *Actions) MigrateTest(ctx context.Context) error

MigrateTest runs the GitHub Action for "ariga/atlas-action/migrate/test"

func (*Actions) MonitorSchema added in v1.3.9

func (a *Actions) MonitorSchema(ctx context.Context) error

MonitorSchema runs the Action for "ariga/atlas-action/monitor/schema"

func (*Actions) RequiredInputs added in v1.3.0

func (a *Actions) RequiredInputs(input ...string) error

RequiredInputs returns an error if any of the given inputs are missing.

func (*Actions) Run added in v1.3.0

func (a *Actions) Run(ctx context.Context, act string) error

Run runs the action based on the command name.

func (*Actions) SchemaApply added in v1.3.0

func (a *Actions) SchemaApply(ctx context.Context) (err error)

SchemaApply runs the GitHub Action for "ariga/atlas-action/schema/apply"

func (*Actions) SchemaLint added in v1.7.0

func (a *Actions) SchemaLint(ctx context.Context) error

SchemaLint runs the GitHub Action for "ariga/atlas-action/schema/lint"

func (*Actions) SchemaPlan added in v1.3.0

func (a *Actions) SchemaPlan(ctx context.Context) error

SchemaPlan runs the GitHub Action for "ariga/atlas-action/schema/plan"

func (*Actions) SchemaPlanApprove added in v1.3.0

func (a *Actions) SchemaPlanApprove(ctx context.Context) error

SchemaPlanApprove runs the GitHub Action for "ariga/atlas-action/schema/plan/approve"

func (*Actions) SchemaPush added in v1.3.0

func (a *Actions) SchemaPush(ctx context.Context) error

SchemaPush runs the GitHub Action for "ariga/atlas-action/schema/push"

func (*Actions) SchemaTest added in v1.2.0

func (a *Actions) SchemaTest(ctx context.Context) error

SchemaTest runs the GitHub Action for "ariga/atlas-action/schema/test"

func (*Actions) WorkingDir added in v1.2.0

func (a *Actions) WorkingDir() string

WorkingDir returns the working directory for the action.

type Actor added in v1.0.10

type Actor struct {
	Name string // Username of the actor.
	ID   string // ID of the actor on the SCM.
}

Actor holds the actor information.

type AtlasExec added in v1.2.0

type AtlasExec interface {
	// Version returns the version of the atlas binary.
	Version(ctx context.Context) (*atlasexec.Version, error)
	// Login runs the `login` command.
	Login(ctx context.Context, params *atlasexec.LoginParams) error
	// CopilotStream runs the 'copilot' command in one-shot mode, streaming the messages.
	CopilotStream(context.Context, *atlasexec.CopilotParams) (atlasexec.Stream[*atlasexec.CopilotMessage], error)
	// MigrateStatus runs the `migrate status` command.
	MigrateStatus(context.Context, *atlasexec.MigrateStatusParams) (*atlasexec.MigrateStatus, error)
	// MigrateHash runs the `migrate hash` command.
	MigrateHash(context.Context, *atlasexec.MigrateHashParams) error
	// MigrateDiff runs the `migrate diff --dry-run` command.
	MigrateDiff(ctx context.Context, params *atlasexec.MigrateDiffParams) (*atlasexec.MigrateDiff, error)
	// MigrateRebase runs the `migrate rebase` command.
	MigrateRebase(context.Context, *atlasexec.MigrateRebaseParams) error
	// MigrateApplySlice runs the `migrate apply` command and returns the successful runs.
	MigrateApplySlice(context.Context, *atlasexec.MigrateApplyParams) ([]*atlasexec.MigrateApply, error)
	// MigrateDown runs the `migrate down` command.
	MigrateDown(context.Context, *atlasexec.MigrateDownParams) (*atlasexec.MigrateDown, error)
	// MigrateLintError runs the `migrate lint` command and fails if there are lint errors.
	MigrateLintError(context.Context, *atlasexec.MigrateLintParams) error
	// MigratePush runs the `migrate push` command.
	MigratePush(context.Context, *atlasexec.MigratePushParams) (string, error)
	// MigrateTest runs the `migrate test` command.
	MigrateTest(context.Context, *atlasexec.MigrateTestParams) (string, error)
	// SchemaInspect runs the `schema inspect` command.
	SchemaInspect(ctx context.Context, params *atlasexec.SchemaInspectParams) (string, error)
	// SchemaPush runs the `schema push` command.
	SchemaPush(context.Context, *atlasexec.SchemaPushParams) (*atlasexec.SchemaPush, error)
	// SchemaTest runs the `schema test` command.
	SchemaTest(context.Context, *atlasexec.SchemaTestParams) (string, error)
	// SchemaPlan runs the `schema plan` command.
	SchemaPlan(context.Context, *atlasexec.SchemaPlanParams) (*atlasexec.SchemaPlan, error)
	// SchemaLint runs the `schema lint` command.
	SchemaLint(context.Context, *atlasexec.SchemaLintParams) (*atlasexec.SchemaLintReport, error)
	// SchemaPlanList runs the `schema plan list` command.
	SchemaPlanList(context.Context, *atlasexec.SchemaPlanListParams) ([]atlasexec.SchemaPlanFile, error)
	// SchemaPlanLint runs the `schema plan lint` command.
	SchemaPlanLint(context.Context, *atlasexec.SchemaPlanLintParams) (*atlasexec.SchemaPlan, error)
	// SchemaPlanApprove runs the `schema plan approve` command.
	SchemaPlanApprove(context.Context, *atlasexec.SchemaPlanApproveParams) (*atlasexec.SchemaPlanApprove, error)
	// SchemaApplySlice runs the `schema apply` command.
	SchemaApplySlice(context.Context, *atlasexec.SchemaApplyParams) ([]*atlasexec.SchemaApply, error)
	// WhoAmI runs the `whoami` command.
	WhoAmI(context.Context, *atlasexec.WhoAmIParams) (*atlasexec.WhoAmI, error)
	// SetStderr sets the standard error output for the client.
	SetStderr(io.Writer)
}

AtlasExec is the interface for the atlas exec client.

type Azure added in v1.10.2

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

func NewAzure added in v1.10.2

func NewAzure(getenv func(string) string, w io.Writer) *Azure

NewAzure returns a new Action for Azure DevOps.

func (*Azure) Errorf added in v1.10.2

func (l *Azure) Errorf(msg string, args ...any)

Errorf implements the Logger interface.

func (*Azure) Fatalf added in v1.10.2

func (l *Azure) Fatalf(msg string, args ...any)

Fatalf implements the Logger interface.

func (*Azure) GetInput added in v1.10.2

func (a *Azure) GetInput(name string) string

GetInput implements the Action interface.

func (*Azure) GetTriggerContext added in v1.10.2

func (a *Azure) GetTriggerContext(context.Context) (_ *TriggerContext, err error)

GetTriggerContext implements Action.

It build the TriggerContext from the Azure DevOps environment variables. For full list of available variables, see: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables

func (*Azure) GetType added in v1.10.2

func (*Azure) GetType() atlasexec.TriggerType

GetType implements the Action interface.

func (*Azure) Getenv added in v1.10.2

func (a *Azure) Getenv(key string) string

Getenv implements Action.

func (*Azure) Infof added in v1.10.2

func (l *Azure) Infof(msg string, args ...any)

Infof implements the Logger interface.

func (*Azure) SetOutput added in v1.10.2

func (a *Azure) SetOutput(key, value string)

SetOutput implements Action.

It writes a task.setvariable logging command to set an output variable in Azure DevOps. https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash#set-variable-properties

func (*Azure) Warningf added in v1.10.2

func (l *Azure) Warningf(msg string, args ...any)

Warningf implements the Logger interface.

type Bitbucket added in v1.10.0

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

func NewBitBucket added in v1.10.0

func NewBitBucket(getenv func(string) string, w io.Writer) *Bitbucket

NewBitBucket returns a new Action for Bitbucket.

func (Bitbucket) Errorf added in v1.10.0

func (l Bitbucket) Errorf(msg string, args ...any)

Errorf implements the Logger interface.

func (Bitbucket) Fatalf added in v1.10.0

func (l Bitbucket) Fatalf(msg string, args ...any)

Fatalf implements the Logger interface.

func (*Bitbucket) GetInput added in v1.10.0

func (a *Bitbucket) GetInput(name string) string

GetInput implements the Action interface.

func (*Bitbucket) GetTriggerContext added in v1.10.0

func (a *Bitbucket) GetTriggerContext(context.Context) (*TriggerContext, error)

GetTriggerContext implements Action.

func (*Bitbucket) GetType added in v1.10.0

func (*Bitbucket) GetType() atlasexec.TriggerType

GetType implements Action.

func (*Bitbucket) Getenv added in v1.10.0

func (a *Bitbucket) Getenv(key string) string

Getenv implements Action.

func (Bitbucket) Infof added in v1.10.0

func (l Bitbucket) Infof(msg string, args ...any)

Infof implements the Logger interface.

func (*Bitbucket) MigrateApply added in v1.10.0

func (a *Bitbucket) MigrateApply(context.Context, *atlasexec.MigrateApply)

MigrateApply implements Reporter.

func (*Bitbucket) MigrateLint added in v1.10.0

func (a *Bitbucket) MigrateLint(ctx context.Context, r *atlasexec.SummaryReport)

MigrateLint implements Reporter.

func (*Bitbucket) SchemaApply added in v1.10.0

func (a *Bitbucket) SchemaApply(context.Context, *atlasexec.SchemaApply)

SchemaApply implements Reporter.

func (*Bitbucket) SchemaLint added in v1.10.0

func (a *Bitbucket) SchemaLint(context.Context, *SchemaLintReport)

SchemaLint implements Reporter.

func (*Bitbucket) SchemaPlan added in v1.10.0

func (a *Bitbucket) SchemaPlan(ctx context.Context, r *atlasexec.SchemaPlan)

SchemaPlan implements Reporter.

func (*Bitbucket) SetOutput added in v1.10.0

func (a *Bitbucket) SetOutput(name, value string)

SetOutput implements Action.

func (Bitbucket) Warningf added in v1.10.0

func (l Bitbucket) Warningf(msg string, args ...any)

Warningf implements the Logger interface.

type BitbucketClient added in v1.4.0

type BitbucketClient struct {
	*bitbucket.Client
}

func NewBitbucketClient added in v1.10.0

func NewBitbucketClient(workspace, repoSlug, token string) (*BitbucketClient, error)

NewBitbucketClient returns a new Bitbucket client that implements SCMClient.

func (*BitbucketClient) CommentCopilot added in v1.10.0

func (c *BitbucketClient) CommentCopilot(context.Context, int, *Copilot) error

CommentCopilot implements SCMClient.

func (*BitbucketClient) CommentLint added in v1.10.0

CommentLint implements SCMClient.

func (*BitbucketClient) CommentPlan added in v1.10.0

CommentPlan implements SCMClient.

func (*BitbucketClient) CommentSchemaLint added in v1.10.0

CommentSchemaLint implements SCMClient.

func (*BitbucketClient) CopilotSession added in v1.11.9

func (c *BitbucketClient) CopilotSession(context.Context, *TriggerContext) (string, error)

CopilotSession implements SCMClient.

func (*BitbucketClient) CreatePullRequest added in v1.11.9

func (c *BitbucketClient) CreatePullRequest(_ context.Context, _, _, _, _ string) (*PullRequest, error)

CreatePullRequest implements SCMClient.

func (*BitbucketClient) PullRequest added in v1.11.9

func (c *BitbucketClient) PullRequest(context.Context, int) (*PullRequest, error)

PullRequest implements SCMClient.

type CircleCI added in v1.10.0

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

CircleCI is an implementation of the Action interface for CircleCI.

func NewCircleCI added in v1.10.0

func NewCircleCI(getenv func(string) string, w io.Writer) *CircleCI

NewCircleCI returns a new CircleCI.

func (CircleCI) Errorf added in v1.10.0

func (l CircleCI) Errorf(msg string, args ...any)

Errorf implements the Logger interface.

func (CircleCI) Fatalf added in v1.10.0

func (l CircleCI) Fatalf(msg string, args ...any)

Fatalf implements the Logger interface.

func (*CircleCI) GetInput added in v1.10.0

func (a *CircleCI) GetInput(name string) string

GetInput implements the Action interface.

func (*CircleCI) GetTriggerContext added in v1.10.0

func (a *CircleCI) GetTriggerContext(ctx context.Context) (*TriggerContext, error)

GetTriggerContext implements the Action interface. https://circleci.com/docs/variables/#built-in-environment-variables

func (*CircleCI) GetType added in v1.10.0

func (a *CircleCI) GetType() atlasexec.TriggerType

GetType implements the Action interface.

func (*CircleCI) Getenv added in v1.10.0

func (a *CircleCI) Getenv(key string) string

Getenv implements Action.

func (CircleCI) Infof added in v1.10.0

func (l CircleCI) Infof(msg string, args ...any)

Infof implements the Logger interface.

func (*CircleCI) SetOutput added in v1.10.0

func (a *CircleCI) SetOutput(name, value string)

SetOutput implements the Action interface.

func (CircleCI) Warningf added in v1.10.0

func (l CircleCI) Warningf(msg string, args ...any)

Warningf implements the Logger interface.

type CloudClient added in v1.3.9

type CloudClient interface {
	// SnapshotHash returns the latest snapshot hash for a monitored schema.
	SnapshotHash(context.Context, *cloud.SnapshotHashInput) (string, error)
	// PushSnapshot pushes a new snapshot version of a monitored schema to the cloud.
	PushSnapshot(context.Context, *cloud.PushSnapshotInput) (string, error)
}

CloudClient lets an action talk to Atlas Cloud.

type Comment added in v1.10.0

type Comment struct {
	Number int    // Pull Request Number
	URL    string // URL of the comment, e.g "https://github.com/ariga/atlas-action/pull/1#issuecomment-1234567890"
	Body   string // Body (description) of the comment
}

Comment holds the comment information.

type Copilot added in v1.10.0

type Copilot struct {
	Session, Prompt, Response string
}

Copilot contains both the prompt and the response from Atlas Copilot.

type GitHub added in v1.10.0

type GitHub struct {
	*githubactions.Action
}

GitHub is an implementation of the Action interface for GitHub Actions.

func NewGitHub added in v1.10.0

func NewGitHub(getenv func(string) string, w io.Writer) *GitHub

NewGitHub returns a new Action for GitHub Actions.

func (*GitHub) GetTriggerContext added in v1.10.0

func (a *GitHub) GetTriggerContext(context.Context) (*TriggerContext, error)

GetTriggerContext returns the context of the action.

func (*GitHub) GetType added in v1.10.0

func (*GitHub) GetType() atlasexec.TriggerType

GetType implements the Action interface.

func (*GitHub) MigrateApply added in v1.10.0

func (a *GitHub) MigrateApply(_ context.Context, r *atlasexec.MigrateApply)

MigrateApply implements Reporter.

func (*GitHub) MigrateLint added in v1.10.0

func (a *GitHub) MigrateLint(_ context.Context, r *atlasexec.SummaryReport)

MigrateLint implements Reporter.

func (*GitHub) SchemaApply added in v1.10.0

func (a *GitHub) SchemaApply(_ context.Context, r *atlasexec.SchemaApply)

SchemaApply implements Reporter.

func (*GitHub) SchemaLint added in v1.10.0

func (a *GitHub) SchemaLint(_ context.Context, r *SchemaLintReport)

SchemaLint implements Reporter.

func (*GitHub) SchemaPlan added in v1.10.0

func (a *GitHub) SchemaPlan(_ context.Context, r *atlasexec.SchemaPlan)

SchemaPlan implements Reporter.

type GitHubClient added in v1.4.0

type GitHubClient struct {
	*github.Client
}

func NewGitHubClient added in v1.10.0

func NewGitHubClient(repo, baseURL, token string) (*GitHubClient, error)

func (*GitHubClient) CommentCopilot added in v1.10.0

func (c *GitHubClient) CommentCopilot(ctx context.Context, pr int, cp *Copilot) error

CommentCopilot implements SCMClient.

func (*GitHubClient) CommentLint added in v1.10.0

CommentLint implements SCMClient.

func (*GitHubClient) CommentPlan added in v1.10.0

func (c *GitHubClient) CommentPlan(ctx context.Context, tc *TriggerContext, p *atlasexec.SchemaPlan) error

CommentPlan implements SCMClient.

func (*GitHubClient) CommentSchemaLint added in v1.10.0

func (c *GitHubClient) CommentSchemaLint(ctx context.Context, tc *TriggerContext, r *SchemaLintReport) error

CommentSchemaLint implements SCMClient.

func (*GitHubClient) CopilotSession added in v1.11.9

func (c *GitHubClient) CopilotSession(ctx context.Context, tc *TriggerContext) (string, error)

CopilotSession implements SCMClient.

func (*GitHubClient) CreatePullRequest added in v1.11.9

func (c *GitHubClient) CreatePullRequest(ctx context.Context, head, base, title, body string) (*PullRequest, error)

CreatePullRequest implements SCMClient.

func (*GitHubClient) PullRequest added in v1.11.9

func (c *GitHubClient) PullRequest(ctx context.Context, number int) (*PullRequest, error)

PullRequest implements SCMClient.

type GitLab added in v1.10.0

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

GitLab is an implementation of the Action interface for Gitlab CI.

func NewGitlab added in v1.10.0

func NewGitlab(getenv func(string) string, w io.Writer) *GitLab

NewGitlab returns a new Action for Gitlab CI.

func (GitLab) Errorf added in v1.10.0

func (l GitLab) Errorf(msg string, args ...any)

Errorf implements the Logger interface.

func (GitLab) Fatalf added in v1.10.0

func (l GitLab) Fatalf(msg string, args ...any)

Fatalf implements the Logger interface.

func (*GitLab) GetInput added in v1.10.0

func (a *GitLab) GetInput(name string) string

GetInput implements the Action interface.

func (*GitLab) GetTriggerContext added in v1.10.0

func (a *GitLab) GetTriggerContext(context.Context) (*TriggerContext, error)

GetTriggerContext implements the Action interface.

func (*GitLab) GetType added in v1.10.0

func (*GitLab) GetType() atlasexec.TriggerType

GetType implements the Action interface.

func (*GitLab) Getenv added in v1.10.0

func (a *GitLab) Getenv(key string) string

Getenv implements Action.

func (GitLab) Infof added in v1.10.0

func (l GitLab) Infof(msg string, args ...any)

Infof implements the Logger interface.

func (*GitLab) SetOutput added in v1.10.0

func (a *GitLab) SetOutput(name, value string)

SetOutput implements the Action interface.

func (GitLab) Warningf added in v1.10.0

func (l GitLab) Warningf(msg string, args ...any)

Warningf implements the Logger interface.

type GitLabClient added in v1.4.0

type GitLabClient struct {
	*gitlab.Client
}

func NewGitLabClient added in v1.10.0

func NewGitLabClient(project, baseURL, token string) (*GitLabClient, error)

func (*GitLabClient) CommentCopilot added in v1.10.0

func (c *GitLabClient) CommentCopilot(context.Context, int, *Copilot) error

CommentCopilot implements SCMClient.

func (*GitLabClient) CommentLint added in v1.10.0

CommentLint implements SCMClient.

func (*GitLabClient) CommentPlan added in v1.10.0

func (c *GitLabClient) CommentPlan(ctx context.Context, tc *TriggerContext, p *atlasexec.SchemaPlan) error

CommentPlan implements SCMClient.

func (*GitLabClient) CommentSchemaLint added in v1.10.0

CommentSchemaLint implements SCMClient.

func (*GitLabClient) CopilotSession added in v1.11.9

func (c *GitLabClient) CopilotSession(context.Context, *TriggerContext) (string, error)

CopilotSession implements SCMClient.

func (*GitLabClient) CreatePullRequest added in v1.11.9

func (c *GitLabClient) CreatePullRequest(_ context.Context, _, _, _, _ string) (*PullRequest, error)

CreatePullRequest implements SCMClient.

func (*GitLabClient) PullRequest added in v1.11.9

func (c *GitLabClient) PullRequest(context.Context, int) (*PullRequest, error)

PullRequest implements SCMClient.

type Logger added in v1.1.0

type Logger interface {
	// Infof logs an info message.
	Infof(string, ...interface{})
	// Warningf logs a warning message.
	Warningf(string, ...interface{})
	// Errorf logs an error message.
	Errorf(string, ...interface{})
	// Fatalf logs a fatal error message and exits the action.
	Fatalf(string, ...interface{})
}

type Option added in v1.3.9

type Option func(*config)

func WithAction added in v1.3.9

func WithAction(a Action) Option

WithAction sets the Action to use.

func WithAtlas added in v1.3.9

func WithAtlas(a AtlasExec) Option

WithAtlas sets the AtlasExec to use.

func WithAtlasPath added in v1.3.10

func WithAtlasPath(bin string) Option

WithAtlasPath sets the path to the atlas binary.

func WithCloudClient added in v1.3.9

func WithCloudClient[T CloudClient](cc func(token, version, cliVersion string) T) Option

WithCloudClient specifies how to obtain a CloudClient given the name of the token input variable.

func WithCmdExecutor added in v1.5.1

func WithCmdExecutor(exec func(ctx context.Context, name string, args ...string) *exec.Cmd) Option

WithCmdExecutor specifies how to execute commands.

func WithGetenv added in v1.3.9

func WithGetenv(getenv func(string) string) Option

WithGetenv specifies how to obtain environment variables.

func WithOut added in v1.3.9

func WithOut(out io.Writer) Option

WithOut specifies where to print to.

func WithRuntimeAction added in v1.3.10

func WithRuntimeAction() Option

WithRuntimeAction detects the action based on the environment.

func WithVersion added in v1.3.9

func WithVersion(v string) Option

WithVersion specifies the version of the Actions.

type PullRequest added in v1.1.0

type PullRequest struct {
	Number int    // Pull Request Number
	URL    string // URL of the pull request. e.g "https://github.com/ariga/atlas-action/pull/1"
	Body   string // Body (description) of the pull request.
	Commit string // Latest commit SHA.
	Ref    string
}

PullRequest holds the pull request information.

func (*PullRequest) AtlasDirectives added in v1.3.5

func (p *PullRequest) AtlasDirectives() (ds []string)

AtlasDirectives returns any directives that are present in the pull request body. For example:

/atlas:nolint destructive

type Reporter added in v1.4.0

type Reporter interface {
	MigrateApply(context.Context, *atlasexec.MigrateApply)
	MigrateLint(context.Context, *atlasexec.SummaryReport)
	SchemaPlan(context.Context, *atlasexec.SchemaPlan)
	SchemaApply(context.Context, *atlasexec.SchemaApply)
	SchemaLint(context.Context, *SchemaLintReport)
}

Reporter is an interface for reporting the status of the actions.

type SCMClient added in v1.3.5

type SCMClient interface {
	// PullRequest returns information about a pull request.
	PullRequest(context.Context, int) (*PullRequest, error)
	// CreatePullRequest creates a pull request with the given title and body into the given base branch.
	CreatePullRequest(_ context.Context, head, base, title, body string) (*PullRequest, error)
	// CopilotSession returns the Copilot session for the current pull request, if there already is one.
	CopilotSession(context.Context, *TriggerContext) (string, error)
	// CommentCopilot comments on the pull request with the copilot response.
	CommentCopilot(_ context.Context, pr int, _ *Copilot) error
	// CommentLint comments on the pull request with the lint report.
	CommentLint(context.Context, *TriggerContext, *atlasexec.SummaryReport) error
	// CommentPlan comments on the pull request with the schema plan.
	CommentPlan(context.Context, *TriggerContext, *atlasexec.SchemaPlan) error
	// CommentSchemaLint comments on the pull request with the schema lint report.
	CommentSchemaLint(context.Context, *TriggerContext, *SchemaLintReport) error
}

SCMClient contains methods for interacting with SCM platforms (GitHub, Gitlab etc...).

type SchemaLintReport added in v1.7.0

type SchemaLintReport struct {
	URL []string `json:"URL,omitempty"` // Redacted schema URLs
	*atlasexec.SchemaLintReport
}

type Suggestion added in v1.2.0

type Suggestion struct {
	ID        string // Suggestion ID.
	Path      string // File path.
	StartLine int    // Start line numbers for the suggestion.
	Line      int    // End line number for the suggestion.
	Comment   string // Comment body.
}

type TriggerContext added in v1.1.0

type TriggerContext struct {
	Act           Action                    // Act is the action that is running.
	SCMType       atlasexec.SCMType         // Type of the SCM, e.g. "GITHUB" / "GITLAB" / "BITBUCKET".
	SCMClient     func() (SCMClient, error) // SCMClient returns a SCMClient for the current action.
	Repo          string                    // Repo is the repository name. e.g. "ariga/atlas-action".
	RepoURL       string                    // RepoURL is full URL of the repository. e.g. "https://github.com/ariga/atlas-action".
	DefaultBranch string                    // DefaultBranch is the default branch of the repository.
	Branch        string                    // Current Branch name.
	Commit        string                    // Commit SHA.
	Actor         *Actor                    // Actor is the user who triggered the action.
	RerunCmd      string                    // RerunCmd is the command to rerun the action.

	PullRequest *PullRequest // PullRequest will be available if the event is "pull_request".
	Comment     *Comment     // Comment will be available if the event is "issue_comment".
}

TriggerContext holds the context of the environment the action is running in.

func (*TriggerContext) GetRunContext added in v1.4.0

func (tc *TriggerContext) GetRunContext() *atlasexec.RunContext

GetRunContext returns the run context for the action.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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