|
1 |
| -package main |
| 1 | +package cmd |
2 | 2 |
|
3 | 3 | import (
|
4 | 4 | "context"
|
5 | 5 | "fmt"
|
6 |
| - "io" |
7 |
| - "log" |
8 | 6 | "net/http"
|
9 |
| - "os" |
10 | 7 |
|
11 |
| - "github.com/davecgh/go-spew/spew" |
12 | 8 | "github.com/jippi/gitlab-labeller/pkg/config"
|
13 | 9 | "github.com/jippi/gitlab-labeller/pkg/scm"
|
14 | 10 | "github.com/jippi/gitlab-labeller/pkg/scm/gitlab"
|
15 | 11 | "github.com/jippi/gitlab-labeller/pkg/state"
|
16 | 12 | "github.com/urfave/cli/v2"
|
17 | 13 | )
|
18 | 14 |
|
19 |
| -const ( |
20 |
| - FlagConfigFile = "config" |
21 |
| - FlagAPIToken = "api-token" |
22 |
| - FlagSCMProject = "project" |
23 |
| - FlagSCMBaseURL = "base-url" |
24 |
| - FlagMergeRequestID = "id" |
25 |
| -) |
26 |
| - |
27 |
| -func main() { |
28 |
| - spew.Config.DisableMethods = true |
29 |
| - |
30 |
| - app := &cli.App{ |
31 |
| - Name: "scm-engine", |
32 |
| - Usage: "GitHub/GitLab automation", |
33 |
| - Copyright: "Christian Winther", |
34 |
| - EnableBashCompletion: true, |
35 |
| - Suggest: true, |
36 |
| - Authors: []*cli.Author{ |
37 |
| - { |
38 |
| - Name: "Christian Winther", |
39 |
| - Email: "gitlab-engine@jippi.dev", |
40 |
| - }, |
41 |
| - }, |
42 |
| - Flags: []cli.Flag{ |
43 |
| - &cli.StringFlag{ |
44 |
| - Name: FlagConfigFile, |
45 |
| - Usage: "Path to the scm-engine config file", |
46 |
| - Value: ".scm-engine.yml", |
47 |
| - TakesFile: true, |
48 |
| - EnvVars: []string{ |
49 |
| - "SCM_ENGINE_CONFIG_FILE", |
50 |
| - }, |
51 |
| - }, |
52 |
| - &cli.StringFlag{ |
53 |
| - Name: FlagAPIToken, |
54 |
| - Usage: "GitHub/GitLab API token", |
55 |
| - Required: true, |
56 |
| - EnvVars: []string{ |
57 |
| - "GITLAB_TOKEN", |
58 |
| - "SCM_ENGINE_TOKEN", |
59 |
| - }, |
60 |
| - }, |
61 |
| - &cli.StringFlag{ |
62 |
| - Name: FlagSCMProject, |
63 |
| - Usage: "GitLab project (example: 'gitlab-org/gitlab')", |
64 |
| - Required: true, |
65 |
| - EnvVars: []string{ |
66 |
| - "GITLAB_PROJECT", |
67 |
| - "CI_PROJECT_PATH", |
68 |
| - }, |
69 |
| - }, |
70 |
| - &cli.StringFlag{ |
71 |
| - Name: FlagSCMBaseURL, |
72 |
| - Usage: "Base URL for the SCM instance", |
73 |
| - Value: "https://gitlab.com/", |
74 |
| - EnvVars: []string{ |
75 |
| - "GITLAB_BASEURL", |
76 |
| - "CI_SERVER_URL", |
77 |
| - }, |
78 |
| - }, |
79 |
| - }, |
80 |
| - Commands: []*cli.Command{ |
81 |
| - { |
82 |
| - Name: "evaluate", |
83 |
| - Usage: "Evaluate a Merge Request", |
84 |
| - Action: evaluateCmd, |
85 |
| - Flags: []cli.Flag{ |
86 |
| - &cli.StringFlag{ |
87 |
| - Name: FlagMergeRequestID, |
88 |
| - Usage: "The pull/merge to process, if not provided as a CLI flag", |
89 |
| - Aliases: []string{ |
90 |
| - "merge-request-id", // GitLab naming |
91 |
| - "pull-request-id", // GitHub naming |
92 |
| - }, |
93 |
| - EnvVars: []string{ |
94 |
| - "CI_MERGE_REQUEST_IID", // GitLab CI |
95 |
| - }, |
96 |
| - }, |
97 |
| - }, |
98 |
| - }, |
99 |
| - { |
100 |
| - Name: "server", |
101 |
| - Usage: "Start HTTP server for webhook event driven usage", |
102 |
| - Action: serverCmd, |
103 |
| - }, |
104 |
| - }, |
105 |
| - } |
106 |
| - |
107 |
| - origHelpPrinterCustom := cli.HelpPrinterCustom |
108 |
| - cli.HelpPrinterCustom = func(out io.Writer, templ string, data interface{}, customFuncs map[string]interface{}) { |
109 |
| - origHelpPrinterCustom(out, templ, data, customFuncs) |
110 |
| - |
111 |
| - if data != app { |
112 |
| - origHelpPrinterCustom(app.Writer, globalOptionsTemplate, app, nil) |
113 |
| - } |
114 |
| - } |
115 |
| - |
116 |
| - if err := app.Run(os.Args); err != nil { |
117 |
| - log.Fatal(err) |
118 |
| - } |
119 |
| -} |
120 |
| - |
121 | 15 | func ProcessMR(ctx context.Context, cCtx *cli.Context, mr string) error {
|
122 | 16 | ctx = state.ContextWithMergeRequestID(ctx, mr)
|
123 | 17 |
|
@@ -200,11 +94,8 @@ func apply(ctx context.Context, client scm.Client, remoteLabels []scm.Evaluation
|
200 | 94 | AddLabels: &add,
|
201 | 95 | RemoveLabels: &remove,
|
202 | 96 | })
|
203 |
| - if err != nil { |
204 |
| - return err |
205 |
| - } |
206 | 97 |
|
207 |
| - return nil |
| 98 | + return err |
208 | 99 | }
|
209 | 100 |
|
210 | 101 | func sync(ctx context.Context, client scm.Client, remote []*scm.Label, required []scm.EvaluationResult) error {
|
|
0 commit comments