Skip to content

Commit 11a081e

Browse files
committed
feat: reorgnize commands into github/gitlab specific commands
1 parent 95c0df2 commit 11a081e

13 files changed

+233
-100
lines changed

.github/workflows/docs.yml

+3
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ jobs:
3131
- name: setup
3232
run: task setup
3333

34+
- name: generate
35+
run: task docs:generate
36+
3437
- name: deploy
3538
run: task docs:deploy

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
/scm-engine.exe
1919
/docs/gitlab/script-attributes.md
2020
/docs/github/script-attributes.md
21+
/docs/github/_partials/cmd-*
22+
/docs/gitlab/_partials/cmd-*

Taskfile.yml

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ tasks:
3030
generates:
3131
- ./scm-engine
3232

33+
docs:generate:
34+
desc: "Generate docs"
35+
cmds:
36+
- mkdir -p docs/github/_partials
37+
- go run . -h > docs/github/_partials/cmd-root.md
38+
- go run . github -h > docs/github/_partials/cmd-github.md
39+
- go run . github evaluate -h > docs/github/_partials/cmd-github-evaluate.md
40+
41+
- mkdir -p docs/gitlab/_partials
42+
- go run . -h > docs/gitlab/_partials/cmd-root.md
43+
- go run . gitlab -h > docs/gitlab/_partials/cmd-gitlab.md
44+
- go run . gitlab evaluate -h > docs/gitlab/_partials/cmd-gitlab-evaluate.md
45+
- go run . gitlab server -h > docs/gitlab/_partials/cmd-gitlab-server.md
3346
docs:server:
3447
desc: Run Docs dev server with live preview
3548
cmds:

cmd/github.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cmd
2+
3+
import "github.com/urfave/cli/v2"
4+
5+
var GitHub = &cli.Command{
6+
Name: "github",
7+
Usage: "GitHub related commands",
8+
Flags: []cli.Flag{
9+
&cli.StringFlag{
10+
Name: FlagAPIToken,
11+
Usage: "GitHub API token",
12+
EnvVars: []string{
13+
"SCM_ENGINE_TOKEN", // SCM Engine Native
14+
},
15+
},
16+
&cli.StringFlag{
17+
Name: FlagSCMBaseURL,
18+
Usage: "Base URL for the SCM instance",
19+
Value: "https://api.github.com/",
20+
EnvVars: []string{
21+
"SCM_ENGINE_BASE_URL", // SCM Engine Native
22+
},
23+
},
24+
},
25+
Subcommands: []*cli.Command{
26+
{
27+
Name: "evaluate",
28+
Usage: "Evaluate a Pull Request",
29+
Args: true,
30+
ArgsUsage: " [pr_id, pr_id, ...]",
31+
Action: Evaluate,
32+
Flags: []cli.Flag{
33+
&cli.StringFlag{
34+
Name: FlagSCMProject,
35+
Usage: "GitHub project (example: 'jippi/scm-engine')",
36+
Required: true,
37+
EnvVars: []string{
38+
"GITHUB_REPOSITORY", // GitHub Actions CI
39+
},
40+
},
41+
&cli.StringFlag{
42+
Name: FlagMergeRequestID,
43+
Usage: "The Pull Request ID to process, if not provided as a CLI flag",
44+
EnvVars: []string{
45+
"SCM_ENGINE_PULL_REQUEST_ID", // SCM Engine native
46+
},
47+
},
48+
&cli.StringFlag{
49+
Name: FlagCommitSHA,
50+
Usage: "The git commit sha",
51+
EnvVars: []string{
52+
"GITHUB_SHA", // GitHub Actions
53+
},
54+
},
55+
},
56+
},
57+
},
58+
}

cmd/gitlab.go

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

docs/commands/evaluate.md

-32
This file was deleted.

docs/commands/server.md

-40
This file was deleted.

docs/github/commands.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Commands
2+
3+
## `scm-engine`
4+
5+
```plain
6+
--8<-- "docs/github/_partials/cmd-root.md"
7+
```
8+
9+
## `scm-engine github`
10+
11+
```plain
12+
--8<-- "docs/github/_partials/cmd-github.md"
13+
```
14+
15+
## `scm-engine github evaluate`
16+
17+
```plain
18+
--8<-- "docs/github/_partials/cmd-github-evaluate.md"
19+
```

docs/gitlab/commands.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Commands
2+
3+
## `scm-engine`
4+
5+
```plain
6+
--8<-- "docs/gitlab/_partials/cmd-root.md"
7+
```
8+
9+
## `scm-engine gitlab`
10+
11+
```plain
12+
--8<-- "docs/gitlab/_partials/cmd-gitlab.md"
13+
```
14+
15+
## `scm-engine gitlab evaluate`
16+
17+
```plain
18+
--8<-- "docs/gitlab/_partials/cmd-gitlab-evaluate.md"
19+
```
20+
21+
## `scm-engine gitlab server`
22+
23+
Point your GitLab webhook at the `/gitlab` endpoint.
24+
25+
Support the following events, and they will both trigger an Merge Request `evaluation`
26+
27+
- [`Comments`](https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#comment-events) - A comment is made or edited on an issue or merge request.
28+
- [`Merge request events`](https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#merge-request-events) - A merge request is created, updated, or merged.
29+
30+
!!! tip
31+
32+
You have access to the raw webhook event payload via `webhook_event.*` fields in Expr script fields when using `server` mode. See the [GitLab Webhook Events documentation](https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html) for available fields.
33+
34+
```plain
35+
--8<-- "docs/gitlab/_partials/cmd-gitlab-server.md"
36+
```

main.go

+4-27
Original file line numberDiff line numberDiff line change
@@ -52,43 +52,19 @@ func main() {
5252
"SCM_ENGINE_CONFIG_FILE",
5353
},
5454
},
55-
&cli.StringFlag{
56-
Name: cmd.FlagProvider,
57-
Usage: `SCM provider to use. Must be either "github" or "gitlab". SCM Engine will automatically detect "github" if "GITHUB_ACTIONS" environment variable is set (e.g., inside GitHub Actions) and detect "gitlab" if "GITLAB_CI" environment variable is set (e.g., inside GitLab CI).`,
58-
Value: detectProviderFromEnv(),
59-
EnvVars: []string{
60-
"SCM_ENGINE_PROVIDER",
61-
},
62-
},
63-
&cli.StringFlag{
64-
Name: cmd.FlagAPIToken,
65-
Usage: "GitHub/GitLab API token",
66-
Required: true,
67-
EnvVars: []string{
68-
"SCM_ENGINE_TOKEN", // SCM Engine Native
69-
"GITHUB_TOKEN", // GitHub Actions
70-
},
71-
},
72-
&cli.StringFlag{
73-
Name: cmd.FlagSCMBaseURL,
74-
Usage: "Base URL for the SCM instance",
75-
Value: "https://gitlab.com/",
76-
EnvVars: []string{
77-
"GITLAB_BASEURL",
78-
"CI_SERVER_URL", // GitLab CI
79-
"GITHUB_API_URL", // GitHub Actions
80-
},
81-
},
8255
&cli.BoolFlag{
8356
Name: cmd.FlagDryRun,
8457
Usage: "Dry run, don't actually _do_ actions, just print them",
8558
Value: false,
8659
},
8760
},
8861
Commands: []*cli.Command{
62+
cmd.GitLab,
63+
cmd.GitHub,
8964
{
9065
Name: "evaluate",
9166
Usage: "Evaluate a Merge Request",
67+
Hidden: true, // DEPRECATED
9268
Args: true,
9369
ArgsUsage: " [mr_id, mr_id, ...]",
9470
Action: cmd.Evaluate,
@@ -131,6 +107,7 @@ func main() {
131107
{
132108
Name: "server",
133109
Usage: "Start HTTP server for webhook event driven usage",
110+
Hidden: true, // DEPRECATED
134111
Action: cmd.Server,
135112
Flags: []cli.Flag{
136113
&cli.StringFlag{

mkdocs.yml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ nav:
1212
- index.md
1313
- install.md
1414
- configuration.md
15-
- ... | commands/*.md
1615
- ... | github/*.md
1716
- ... | gitlab/*.md
1817

0 commit comments

Comments
 (0)