|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/jippi/scm-engine/pkg/state" |
| 5 | + "github.com/urfave/cli/v2" |
| 6 | +) |
| 7 | + |
| 8 | +var GitLab = &cli.Command{ |
| 9 | + Name: "gitlab", |
| 10 | + Usage: "GitLab related commands", |
| 11 | + Before: func(cCtx *cli.Context) error { |
| 12 | + cCtx.Context = state.WithBaseURL(cCtx.Context, cCtx.String(FlagSCMBaseURL)) |
| 13 | + cCtx.Context = state.WithProvider(cCtx.Context, "gitlab") |
| 14 | + cCtx.Context = state.WithToken(cCtx.Context, cCtx.String(FlagAPIToken)) |
| 15 | + |
| 16 | + return nil |
| 17 | + }, |
| 18 | + Flags: []cli.Flag{ |
| 19 | + &cli.StringFlag{ |
| 20 | + Name: FlagAPIToken, |
| 21 | + Usage: "GitLab API token", |
| 22 | + EnvVars: []string{ |
| 23 | + "SCM_ENGINE_TOKEN", // SCM Engine Native |
| 24 | + }, |
| 25 | + }, |
| 26 | + &cli.StringFlag{ |
| 27 | + Name: FlagSCMBaseURL, |
| 28 | + Usage: "Base URL for the SCM instance", |
| 29 | + Value: "https://gitlab.com/", |
| 30 | + EnvVars: []string{ |
| 31 | + "SCM_ENGINE_BASE_URL", // SCM Engine Native |
| 32 | + "CI_SERVER_URL", // GitLab CI |
| 33 | + }, |
| 34 | + }, |
| 35 | + }, |
| 36 | + Subcommands: []*cli.Command{ |
| 37 | + { |
| 38 | + Name: "evaluate", |
| 39 | + Usage: "Evaluate a Merge Request", |
| 40 | + Args: true, |
| 41 | + ArgsUsage: " [mr_id, mr_id, ...]", |
| 42 | + Action: Evaluate, |
| 43 | + Flags: []cli.Flag{ |
| 44 | + &cli.BoolFlag{ |
| 45 | + Name: FlagUpdatePipeline, |
| 46 | + Usage: "Update the CI pipeline status with progress", |
| 47 | + Value: false, |
| 48 | + EnvVars: []string{ |
| 49 | + "SCM_ENGINE_UPDATE_PIPELINE", |
| 50 | + }, |
| 51 | + }, |
| 52 | + &cli.StringFlag{ |
| 53 | + Name: FlagSCMProject, |
| 54 | + Usage: "GitLab project (example: 'gitlab-org/gitlab')", |
| 55 | + EnvVars: []string{ |
| 56 | + "GITLAB_PROJECT", |
| 57 | + "CI_PROJECT_PATH", // GitLab CI |
| 58 | + }, |
| 59 | + }, |
| 60 | + &cli.StringFlag{ |
| 61 | + Name: FlagMergeRequestID, |
| 62 | + Usage: "The Merge Request ID to process, if not provided as a CLI flag", |
| 63 | + EnvVars: []string{ |
| 64 | + "CI_MERGE_REQUEST_IID", // GitLab CI |
| 65 | + }, |
| 66 | + }, |
| 67 | + &cli.StringFlag{ |
| 68 | + Name: FlagCommitSHA, |
| 69 | + Usage: "The git commit sha", |
| 70 | + EnvVars: []string{ |
| 71 | + "CI_COMMIT_SHA", // GitLab CI |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + { |
| 77 | + Name: "server", |
| 78 | + Usage: "Start HTTP server for webhook event driven usage", |
| 79 | + Hidden: true, // DEPRECATED |
| 80 | + Action: Server, |
| 81 | + Flags: []cli.Flag{ |
| 82 | + &cli.StringFlag{ |
| 83 | + Name: FlagWebhookSecret, |
| 84 | + Usage: "Used to validate received payloads. Sent with the request in the X-Gitlab-Token HTTP header", |
| 85 | + EnvVars: []string{ |
| 86 | + "SCM_ENGINE_WEBHOOK_SECRET", |
| 87 | + }, |
| 88 | + }, |
| 89 | + &cli.StringFlag{ |
| 90 | + Name: FlagServerListen, |
| 91 | + Usage: "IP + Port that the HTTP server should listen on", |
| 92 | + Value: "0.0.0.0:3000", |
| 93 | + EnvVars: []string{ |
| 94 | + "SCM_ENGINE_LISTEN", |
| 95 | + }, |
| 96 | + }, |
| 97 | + &cli.BoolFlag{ |
| 98 | + Name: FlagUpdatePipeline, |
| 99 | + Usage: "Update the CI pipeline status with progress", |
| 100 | + Value: true, |
| 101 | + EnvVars: []string{ |
| 102 | + "SCM_ENGINE_UPDATE_PIPELINE", |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + }, |
| 107 | + }, |
| 108 | +} |
0 commit comments