Help us shape the future of Go! Take the 2026 Go Developer Survey

cmd

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagAPIToken                                        = "api-token"
	FlagBackstageURL                                    = "backstage-url"
	FlagBackstageToken                                  = "backstage-token"
	FlagCommitSHA                                       = "commit"
	FlagConfigFile                                      = "config"
	FlagDryRun                                          = "dry-run"
	FlagGlobalConfigFile                                = "global-config"
	FlagMergeRequestID                                  = "id"
	FlagSCMBaseURL                                      = "base-url"
	FlagSCMProject                                      = "project"
	FlagServerListenHost                                = "listen-host"
	FlagServerListenPort                                = "listen-port"
	FlagServerTimeout                                   = "timeout"
	FlagUpdatePipeline                                  = "update-pipeline"
	FlagUpdatePipelineURL                               = "update-pipeline-url"
	FlagPeriodicEvaluationInterval                      = "periodic-evaluation-interval"
	FlagPeriodicEvaluationIgnoreMergeRequestsWithLabel  = "periodic-evaluation-ignore-mr-labels"
	FlagPeriodicEvaluationRequireMergeRequestsWithLabel = "periodic-evaluation-require-mr-labels"
	FlagPeriodicEvaluationOnlyProjectsWithTopics        = "periodic-evaluation-project-topics"
	FlagPeriodicEvaluationOnlyProjectsWithMembership    = "periodic-evaluation-only-project-membership"
	FlagWebhookSecret                                   = "webhook-secret"
)

Variables

View Source
var (
	StringFlagBackstageURL = &cli.StringFlag{
		Name:  FlagBackstageURL,
		Usage: "The Backstage base URL",
		Sources: cli.EnvVars(
			"BACKSTAGE_URL",
		),
	}
	StringFlagBackstageToken = &cli.StringFlag{
		Name:  FlagBackstageToken,
		Usage: "The Backstage static token with access to the catalog plugin",
		Sources: cli.EnvVars(
			"BACKSTAGE_TOKEN",
		),
	}
)
View Source
var GitHub = &cli.Command{
	Name:  "github",
	Usage: "GitHub related commands",
	Before: func(ctx context.Context, cCtx *cli.Command) (context.Context, error) {
		return state.WithProvider(ctx, "github"), nil
	},
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:  FlagAPIToken,
			Usage: "GitHub API token",
			Sources: cli.EnvVars(
				"SCM_ENGINE_TOKEN",
			),
		},
		&cli.StringFlag{
			Name:  FlagSCMBaseURL,
			Usage: "Base URL for the SCM instance",
			Value: "https://api.github.com/",
			Sources: cli.EnvVars(
				"SCM_ENGINE_BASE_URL",
			),
		},
	},
	Commands: []*cli.Command{
		{
			Name:      "evaluate",
			Usage:     "Evaluate a Pull Request",
			ArgsUsage: " [pr_id, pr_id, ...]",
			Action:    Evaluate,
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:     FlagSCMProject,
					Usage:    "GitHub project (example: 'jippi/scm-engine')",
					Required: true,
					Sources: cli.EnvVars(
						"GITHUB_REPOSITORY",
					),
				},
				&cli.StringFlag{
					Name:  FlagMergeRequestID,
					Usage: "The Pull Request ID to process, if not provided as a CLI flag",
					Sources: cli.EnvVars(
						"SCM_ENGINE_PULL_REQUEST_ID",
					),
				},
				&cli.StringFlag{
					Name:  FlagCommitSHA,
					Usage: "The git commit sha",
					Sources: cli.EnvVars(
						"GITHUB_SHA",
					),
				},
			},
		},
	},
}
View Source
var GitLab = &cli.Command{
	Name:  "gitlab",
	Usage: "GitLab related commands",
	Before: func(ctx context.Context, cCtx *cli.Command) (context.Context, error) {
		ctx = state.WithBaseURL(ctx, cCtx.String(FlagSCMBaseURL))
		ctx = state.WithProvider(ctx, "gitlab")
		ctx = state.WithToken(ctx, cCtx.String(FlagAPIToken))
		ctx = state.WithGlobalConfigFilePath(ctx, cCtx.String(FlagGlobalConfigFile))

		return ctx, nil
	},
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:  FlagAPIToken,
			Usage: "GitLab API token",
			Sources: cli.EnvVars(
				"SCM_ENGINE_TOKEN",
			),
		},
		&cli.StringFlag{
			Name:  FlagSCMBaseURL,
			Usage: "Base URL for the SCM instance",
			Value: "https://gitlab.com/",
			Sources: cli.EnvVars(
				"SCM_ENGINE_BASE_URL",
				"CI_SERVER_URL",
			),
		},
		&cli.StringFlag{
			Name:    FlagGlobalConfigFile,
			Usage:   "Path to a global configuration file. Any repository specific configuration will be merged on top of the global configuration",
			Value:   "",
			Sources: cli.EnvVars("SCM_ENGINE_GLOBAL_CONFIG_FILE"),
		},
	},
	Commands: []*cli.Command{
		{
			Name:   "lint",
			Usage:  "lint a configuration file",
			Action: Lint,
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:  "schema",
					Usage: "Where to find the JSON Schema file. Can load the file from either the embedded version (default), http://, https://, or a file:// URI",
					Value: "embed://",
				},
			},
		},
		{
			Name:      "evaluate",
			Usage:     "Evaluate a Merge Request",
			ArgsUsage: " [mr_id, mr_id, ...]",
			Action:    Evaluate,
			Flags: []cli.Flag{
				&cli.BoolFlag{
					Name:    FlagUpdatePipeline,
					Usage:   "Update the CI pipeline status with progress",
					Value:   true,
					Sources: cli.EnvVars("SCM_ENGINE_UPDATE_PIPELINE"),
				},
				&cli.StringFlag{
					Name:    FlagUpdatePipelineURL,
					Usage:   "(Optional) URL to where logs can be found for the pipeline",
					Sources: cli.EnvVars("SCM_ENGINE_UPDATE_PIPELINE_URL"),
				},
				&cli.StringFlag{
					Name:  FlagSCMProject,
					Usage: "GitLab project (example: 'gitlab-org/gitlab')",
					Sources: cli.EnvVars(
						"GITLAB_PROJECT",
						"CI_PROJECT_PATH",
					),
				},
				&cli.StringFlag{
					Name:  FlagMergeRequestID,
					Usage: "The Merge Request ID to process, if not provided as a CLI flag",
					Sources: cli.EnvVars(
						"CI_MERGE_REQUEST_IID",
					),
				},
				&cli.StringFlag{
					Name:  FlagCommitSHA,
					Usage: "The git commit sha",
					Sources: cli.EnvVars(
						"CI_COMMIT_SHA",
					),
				},
				StringFlagBackstageURL,
				StringFlagBackstageToken,
			},
		},
		{
			Name:   "server",
			Usage:  "Start HTTP server for webhook event driven usage",
			Hidden: true,
			Action: Server,
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:    FlagWebhookSecret,
					Usage:   "Used to validate received payloads. Sent with the request in the X-Gitlab-Token HTTP header",
					Sources: cli.EnvVars("SCM_ENGINE_WEBHOOK_SECRET"),
				},
				&cli.StringFlag{
					Name:    FlagServerListenHost,
					Usage:   "IP that the HTTP server should listen on",
					Value:   "0.0.0.0",
					Sources: cli.EnvVars("SCM_ENGINE_LISTEN_ADDR"),
				},
				&cli.IntFlag{
					Name:  FlagServerListenPort,
					Usage: "Port that the HTTP server should listen on",
					Value: 3000,
					Sources: cli.EnvVars(
						"SCM_ENGINE_LISTEN_PORT",
						"PORT",
					),
				},
				&cli.DurationFlag{
					Name:    FlagServerTimeout,
					Usage:   "Timeout for webhook requests",
					Value:   5 * time.Second,
					Sources: cli.EnvVars("SCM_ENGINE_TIMEOUT"),
				},
				&cli.BoolFlag{
					Name:    FlagUpdatePipeline,
					Usage:   "Update the CI pipeline status with progress",
					Value:   true,
					Sources: cli.EnvVars("SCM_ENGINE_UPDATE_PIPELINE"),
				},
				&cli.StringFlag{
					Name:    FlagUpdatePipelineURL,
					Usage:   "(Optional) URL to where logs can be found for the pipeline",
					Sources: cli.EnvVars("SCM_ENGINE_UPDATE_PIPELINE_URL"),
				},
				&cli.DurationFlag{
					Name:    FlagPeriodicEvaluationInterval,
					Usage:   "(Optional) Frequency of which to evaluate all Merge Requests regardless of user activity",
					Sources: cli.EnvVars("SCM_ENGINE_PERIODIC_EVALUATION_INTERVAL"),
				},
				&cli.StringSliceFlag{
					Name:    FlagPeriodicEvaluationIgnoreMergeRequestsWithLabel,
					Usage:   "(Optional) Ignore MR with these labels",
					Sources: cli.EnvVars("SCM_ENGINE_PERIODIC_EVALUATION_IGNORE_MR_WITH_LABELS"),
				},
				&cli.StringSliceFlag{
					Name:    FlagPeriodicEvaluationRequireMergeRequestsWithLabel,
					Usage:   "(Optional) Only process MR with these labels",
					Sources: cli.EnvVars("SCM_ENGINE_PERIODIC_EVALUATION_REQUIRE_MR_WITH_LABELS"),
				},
				&cli.StringSliceFlag{
					Name:    FlagPeriodicEvaluationOnlyProjectsWithTopics,
					Usage:   "(Optional) Only evaluate projects with these topics",
					Sources: cli.EnvVars("SCM_ENGINE_PERIODIC_EVALUATION_REQUIRE_PROJECT_TOPICS"),
				},
				&cli.BoolFlag{
					Name:    FlagPeriodicEvaluationOnlyProjectsWithMembership,
					Usage:   "(Optional) Only evaluate projects with membership",
					Value:   true,
					Sources: cli.EnvVars("SCM_ENGINE_PERIODIC_EVALUATION_ONLY_PROJECTS_WITH_MEMBERSHIP"),
				},
				StringFlagBackstageURL,
				StringFlagBackstageToken,
			},
		},
	},
}

Functions

func Evaluate

func Evaluate(ctx context.Context, cCtx *cli.Command) error

func GitLabStatusHandler added in v0.11.0

func GitLabStatusHandler(w http.ResponseWriter, r *http.Request)

func GitLabWebhookHandler added in v0.11.0

func GitLabWebhookHandler(ctx context.Context, webhookSecret string) http.HandlerFunc

func Lint added in v0.18.0

func Lint(ctx context.Context, cCtx *cli.Command) error

func ProcessMR

func ProcessMR(ctx context.Context, client scm.Client, cfg *config.Config, event any) (err error)

func Server

func Server(ctx context.Context, cCtx *cli.Command) error

Types

type EmbedLoader added in v0.18.0

type EmbedLoader struct{}

func (*EmbedLoader) Load added in v0.18.0

func (l *EmbedLoader) Load(url string) (any, error)

type GitlabWebhookPayload added in v0.11.0

type GitlabWebhookPayload struct {
	EventType        string                            `json:"event_type"`
	Project          GitlabWebhookPayloadProject       `json:"project"`                     // "project" is sent for all events
	ObjectAttributes *GitlabWebhookPayloadMergeRequest `json:"object_attributes,omitempty"` // "object_attributes" is sent on "merge_request" events
	MergeRequest     *GitlabWebhookPayloadMergeRequest `json:"merge_request,omitempty"`     // "merge_request" is sent on "note" activity
}

type GitlabWebhookPayloadCommit added in v0.11.0

type GitlabWebhookPayloadCommit struct {
	ID string `json:"id"`
}

type GitlabWebhookPayloadMergeRequest added in v0.11.0

type GitlabWebhookPayloadMergeRequest struct {
	IID        int                        `json:"iid"`
	LastCommit GitlabWebhookPayloadCommit `json:"last_commit"`
}

type GitlabWebhookPayloadProject added in v0.11.0

type GitlabWebhookPayloadProject struct {
	PathWithNamespace string `json:"path_with_namespace"`
}

type HTTPURLLoader added in v0.18.0

type HTTPURLLoader http.Client

func (*HTTPURLLoader) Load added in v0.18.0

func (l *HTTPURLLoader) Load(url string) (any, error)

Jump to

Keyboard shortcuts

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