cmd

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagAPIToken                                        = "api-token"
	FlagCommitSHA                                       = "commit"
	FlagConfigFile                                      = "config"
	FlagDryRun                                          = "dry-run"
	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 GitHub = &cli.Command{
	Name:  "github",
	Usage: "GitHub related commands",
	Before: func(ctx *cli.Context) error {
		ctx.Context = state.WithProvider(ctx.Context, "github")

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

		return nil
	},
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:  FlagAPIToken,
			Usage: "GitLab API token",
			EnvVars: []string{
				"SCM_ENGINE_TOKEN",
			},
		},
		&cli.StringFlag{
			Name:  FlagSCMBaseURL,
			Usage: "Base URL for the SCM instance",
			Value: "https://gitlab.com/",
			EnvVars: []string{
				"SCM_ENGINE_BASE_URL",
				"CI_SERVER_URL",
			},
		},
	},
	Subcommands: []*cli.Command{
		{
			Name:      "evaluate",
			Usage:     "Evaluate a Merge Request",
			Args:      true,
			ArgsUsage: " [mr_id, mr_id, ...]",
			Action:    Evaluate,
			Flags: []cli.Flag{
				&cli.BoolFlag{
					Name:  FlagUpdatePipeline,
					Usage: "Update the CI pipeline status with progress",
					Value: true,
					EnvVars: []string{
						"SCM_ENGINE_UPDATE_PIPELINE",
					},
				},
				&cli.StringFlag{
					Name:  FlagUpdatePipelineURL,
					Usage: "(Optional) URL to where logs can be found for the pipeline",
					EnvVars: []string{
						"SCM_ENGINE_UPDATE_PIPELINE_URL",
					},
				},
				&cli.StringFlag{
					Name:  FlagSCMProject,
					Usage: "GitLab project (example: 'gitlab-org/gitlab')",
					EnvVars: []string{
						"GITLAB_PROJECT",
						"CI_PROJECT_PATH",
					},
				},
				&cli.StringFlag{
					Name:  FlagMergeRequestID,
					Usage: "The Merge Request ID to process, if not provided as a CLI flag",
					EnvVars: []string{
						"CI_MERGE_REQUEST_IID",
					},
				},
				&cli.StringFlag{
					Name:  FlagCommitSHA,
					Usage: "The git commit sha",
					EnvVars: []string{
						"CI_COMMIT_SHA",
					},
				},
			},
		},
		{
			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",
					EnvVars: []string{
						"SCM_ENGINE_WEBHOOK_SECRET",
					},
				},
				&cli.StringFlag{
					Name:  FlagServerListenHost,
					Usage: "IP that the HTTP server should listen on",
					Value: "0.0.0.0",
					EnvVars: []string{
						"SCM_ENGINE_LISTEN_ADDR",
					},
				},
				&cli.IntFlag{
					Name:  FlagServerListenPort,
					Usage: "Port that the HTTP server should listen on",
					Value: 3000,
					EnvVars: []string{
						"SCM_ENGINE_LISTEN_PORT",
						"PORT",
					},
				},
				&cli.DurationFlag{
					Name:  FlagServerTimeout,
					Usage: "Timeout for webhook requests",
					Value: 5 * time.Second,
					EnvVars: []string{
						"SCM_ENGINE_TIMEOUT",
					},
				},
				&cli.BoolFlag{
					Name:  FlagUpdatePipeline,
					Usage: "Update the CI pipeline status with progress",
					Value: true,
					EnvVars: []string{
						"SCM_ENGINE_UPDATE_PIPELINE",
					},
				},
				&cli.StringFlag{
					Name:  FlagUpdatePipelineURL,
					Usage: "(Optional) URL to where logs can be found for the pipeline",
					EnvVars: []string{
						"SCM_ENGINE_UPDATE_PIPELINE_URL",
					},
				},
				&cli.DurationFlag{
					Name:  FlagPeriodicEvaluationInterval,
					Usage: "(Optional) Frequency of which to evaluate all Merge Requests regardless of user activity",
					EnvVars: []string{
						"SCM_ENGINE_PERIODIC_EVALUATION_INTERVAL",
					},
				},
				&cli.StringSliceFlag{
					Name:  FlagPeriodicEvaluationIgnoreMergeRequestsWithLabel,
					Usage: "(Optional) Ignore MR with these labels",
					EnvVars: []string{
						"SCM_ENGINE_PERIODIC_EVALUATION_IGNORE_MR_WITH_LABELS",
					},
				},
				&cli.StringSliceFlag{
					Name:  FlagPeriodicEvaluationRequireMergeRequestsWithLabel,
					Usage: "(Optional) Only process MR with these labels",
					EnvVars: []string{
						"SCM_ENGINE_PERIODIC_EVALUATION_REQUIRE_MR_WITH_LABELS",
					},
				},
				&cli.StringSliceFlag{
					Name:  FlagPeriodicEvaluationOnlyProjectsWithTopics,
					Usage: "(Optional) Only evaluate projects with these topics",
					EnvVars: []string{
						"SCM_ENGINE_PERIODIC_EVALUATION_REQUIRE_PROJECT_TOPICS",
					},
				},
				&cli.BoolFlag{
					Name:  FlagPeriodicEvaluationOnlyProjectsWithMembership,
					Usage: "(Optional) Only evaluate projects with membership",
					Value: true,
					EnvVars: []string{
						"SCM_ENGINE_PERIODIC_EVALUATION_ONLY_PROJECTS_WITH_MEMBERSHIP",
					},
				},
			},
		},
	},
}
View Source
var GlobalOptionsTemplate = `` /* 133-byte string literal not displayed */

Functions

func Evaluate

func Evaluate(cCtx *cli.Context) 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 ProcessMR

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

func Server

func Server(cCtx *cli.Context) error

Types

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"`
}

Jump to

Keyboard shortcuts

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