Skip to content

Commit afa0935

Browse files
authored
🍱 [minor] Publish merge request report to Gitlab (#119)
* feat: mr report to Gitlab (#118) * add gitlab token to samsahai cmd args * feat: add new crd and gitlab test publish * allow read gitlabToken from k8s secret * test: add util gitlab_test.go * test: add samsahai gitlab report reporter_test.go * update crd template * update crd example * format lint * make swag
1 parent f07b1ab commit afa0935

File tree

19 files changed

+936
-128
lines changed

19 files changed

+936
-128
lines changed

api/v1/config_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ type ConfigReporter struct {
207207
// +optional
208208
Github *ReporterGithub `json:"github,omitempty"`
209209
// +optional
210+
Gitlab *ReporterGitlab `json:"gitlab,omitempty"`
211+
// +optional
210212
Rest *ReporterRest `json:"rest,omitempty"`
211213
// +optional
212214
Shell *ReporterShell `json:"cmd,omitempty"`
@@ -307,6 +309,17 @@ type ReporterGithub struct {
307309
BaseURL string `json:"baseURL,omitempty"`
308310
}
309311

312+
// ReporterGitlab defines a configuration of gitlab reporter
313+
// supports pull request queue reporter type only
314+
type ReporterGitlab struct {
315+
// Enabled represents an enabled flag
316+
// +optional
317+
Enabled bool `json:"enabled"`
318+
// BaseURL represents a gitlab base url e.g., https://gitlab.com
319+
// +optional
320+
BaseURL string `json:"baseURL,omitempty"`
321+
}
322+
310323
// ReporterRest defines a configuration of http rest
311324
type ReporterRest struct {
312325
// +optional

api/v1/team_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ type Credential struct {
7272
// Github
7373
// +optional
7474
Github *TokenCredential `json:"github,omitempty"`
75+
76+
// Gitlab
77+
// +optional
78+
Gitlab *TokenCredential `json:"gitlab,omitempty"`
7579
}
7680

7781
type UsernamePasswordCredential struct {

cmd/samsahai/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func startCtrlCmd() *cobra.Command {
141141
// TODO: move to credential
142142
TeamcityURL: viper.GetString(s2h.VKTeamcityURL),
143143
GithubURL: viper.GetString(s2h.VKGithubURL),
144+
GitlabURL: viper.GetString(s2h.VKGitlabURL),
144145
SamsahaiURL: fmt.Sprintf("%s://%s.%s:%s",
145146
viper.GetString(s2h.VKS2HServiceScheme),
146147
viper.GetString(s2h.VKS2HServiceName),
@@ -262,6 +263,8 @@ func startCtrlCmd() *cobra.Command {
262263
cmd.Flags().String(s2h.VKS2HServiceName, "samsahai", "Service name for connecting to Samsahai.")
263264
cmd.Flags().String(s2h.VKS2HExternalURL, "http://localhost:8080", "External url for Samsahai.")
264265
cmd.Flags().String(s2h.VKGithubToken, "", "Github access token for publishing commit status into github.")
266+
cmd.Flags().String(s2h.VKGitlabToken, "", "Gitlab access token for publishing commit status into gitlab.")
267+
cmd.Flags().String(s2h.VKGitlabURL, "", "Gitlab base URL used for initializing Gitlab reporter.")
265268
cmd.Flags().String(s2h.VKGithubURL, "", "Github base URL used for initializing Github reporter.")
266269
cmd.Flags().String(s2h.VKTeamcityURL, "",
267270
"Teamcity base URL used for initializing Teamcity test runner.")

config/chart/samsahai/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fileConfigs:
2727
s2hImage: '{{ .Values.image.repository }}:{{ .Values.image.tag }}'
2828
clusterDomain: "cluster.local"
2929
githubURL: "https://github.com"
30+
gitlabURL: "https://gitlab.com"
3031

3132
# cpu/memory of cronjobs for sending new component webhook
3233
checkerResources:

config/crds/env.samsahai.io_configs.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,16 @@ spec:
519519
description: Enabled represents an enabled flag
520520
type: boolean
521521
type: object
522+
gitlab:
523+
description: ReporterGitlab defines a configuration of gitlab reporter supports pull request queue reporter type only
524+
properties:
525+
baseURL:
526+
description: BaseURL represents a gitlab base url e.g., https://gitlab.com
527+
type: string
528+
enabled:
529+
description: Enabled represents an enabled flag
530+
type: boolean
531+
type: object
522532
msTeams:
523533
description: ReporterMSTeams defines a configuration of Microsoft Teams
524534
properties:
@@ -1284,6 +1294,16 @@ spec:
12841294
description: Enabled represents an enabled flag
12851295
type: boolean
12861296
type: object
1297+
gitlab:
1298+
description: ReporterGitlab defines a configuration of gitlab reporter supports pull request queue reporter type only
1299+
properties:
1300+
baseURL:
1301+
description: BaseURL represents a gitlab base url e.g., https://gitlab.com
1302+
type: string
1303+
enabled:
1304+
description: Enabled represents an enabled flag
1305+
type: boolean
1306+
type: object
12871307
msTeams:
12881308
description: ReporterMSTeams defines a configuration of Microsoft Teams
12891309
properties:

config/crds/env.samsahai.io_teams.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ spec:
3535
credential:
3636
description: Credential
3737
properties:
38+
gitlab:
39+
description: Gitlab
40+
properties:
41+
token:
42+
description: SecretKeySelector selects a key of a Secret.
43+
properties:
44+
key:
45+
description: The key of the secret to select from. Must be a valid secret key.
46+
type: string
47+
name:
48+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
49+
type: string
50+
optional:
51+
description: Specify whether the Secret or its key must be defined
52+
type: boolean
53+
required:
54+
- key
55+
type: object
56+
required:
57+
- token
58+
type: object
3859
github:
3960
description: Github
4061
properties:
@@ -290,6 +311,27 @@ spec:
290311
credential:
291312
description: Credential
292313
properties:
314+
gitlab:
315+
description: Gitlab
316+
properties:
317+
token:
318+
description: SecretKeySelector selects a key of a Secret.
319+
properties:
320+
key:
321+
description: The key of the secret to select from. Must be a valid secret key.
322+
type: string
323+
name:
324+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
325+
type: string
326+
optional:
327+
description: Specify whether the Secret or its key must be defined
328+
type: boolean
329+
required:
330+
- key
331+
type: object
332+
required:
333+
- token
334+
type: object
293335
github:
294336
description: Github
295337
properties:

docs/docs.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
22
// This file was generated by swaggo/swag at
3-
// 2021-10-18 13:50:22.115873 +0700 +07 m=+0.245617719
3+
// 2021-11-09 15:17:03.538962 +0700 +07 m=+0.185377644
44

55
package docs
66

@@ -1315,6 +1315,11 @@ var doc = `{
13151315
"type": "object",
13161316
"$ref": "#/definitions/v1.ReporterGithub"
13171317
},
1318+
"gitlab": {
1319+
"description": "+optional",
1320+
"type": "object",
1321+
"$ref": "#/definitions/v1.ReporterGitlab"
1322+
},
13181323
"msTeams": {
13191324
"description": "+optional",
13201325
"type": "object",
@@ -1468,6 +1473,11 @@ var doc = `{
14681473
"type": "object",
14691474
"$ref": "#/definitions/v1.TokenCredential"
14701475
},
1476+
"gitlab": {
1477+
"description": "Gitlab\n+optional",
1478+
"type": "object",
1479+
"$ref": "#/definitions/v1.TokenCredential"
1480+
},
14711481
"secretName": {
14721482
"description": "SecretName",
14731483
"type": "string"
@@ -1873,7 +1883,7 @@ var doc = `{
18731883
"type": "object",
18741884
"properties": {
18751885
"criteria": {
1876-
"description": "Criteria tells how does the duration apply, default is ` + "`" + `both` + "`" + `.\n+optional",
1886+
"description": "Criteria tells how does the duration apply, default is ` + "`" + `failure` + "`" + `.\n+optional",
18771887
"type": "string"
18781888
},
18791889
"duration": {
@@ -2156,6 +2166,19 @@ var doc = `{
21562166
}
21572167
}
21582168
},
2169+
"v1.ReporterGitlab": {
2170+
"type": "object",
2171+
"properties": {
2172+
"baseURL": {
2173+
"description": "BaseURL represents a gitlab base url e.g., https://gitlab.com\n+optional",
2174+
"type": "string"
2175+
},
2176+
"enabled": {
2177+
"description": "Enabled represents an enabled flag\n+optional",
2178+
"type": "boolean"
2179+
}
2180+
}
2181+
},
21592182
"v1.ReporterMSTeams": {
21602183
"type": "object",
21612184
"properties": {

docs/swagger.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,11 @@
12941294
"type": "object",
12951295
"$ref": "#/definitions/v1.ReporterGithub"
12961296
},
1297+
"gitlab": {
1298+
"description": "+optional",
1299+
"type": "object",
1300+
"$ref": "#/definitions/v1.ReporterGitlab"
1301+
},
12971302
"msTeams": {
12981303
"description": "+optional",
12991304
"type": "object",
@@ -1447,6 +1452,11 @@
14471452
"type": "object",
14481453
"$ref": "#/definitions/v1.TokenCredential"
14491454
},
1455+
"gitlab": {
1456+
"description": "Gitlab\n+optional",
1457+
"type": "object",
1458+
"$ref": "#/definitions/v1.TokenCredential"
1459+
},
14501460
"secretName": {
14511461
"description": "SecretName",
14521462
"type": "string"
@@ -1852,7 +1862,7 @@
18521862
"type": "object",
18531863
"properties": {
18541864
"criteria": {
1855-
"description": "Criteria tells how does the duration apply, default is `both`.\n+optional",
1865+
"description": "Criteria tells how does the duration apply, default is `failure`.\n+optional",
18561866
"type": "string"
18571867
},
18581868
"duration": {
@@ -2135,6 +2145,19 @@
21352145
}
21362146
}
21372147
},
2148+
"v1.ReporterGitlab": {
2149+
"type": "object",
2150+
"properties": {
2151+
"baseURL": {
2152+
"description": "BaseURL represents a gitlab base url e.g., https://gitlab.com\n+optional",
2153+
"type": "string"
2154+
},
2155+
"enabled": {
2156+
"description": "Enabled represents an enabled flag\n+optional",
2157+
"type": "boolean"
2158+
}
2159+
}
2160+
},
21382161
"v1.ReporterMSTeams": {
21392162
"type": "object",
21402163
"properties": {

docs/swagger.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ definitions:
396396
$ref: '#/definitions/v1.ReporterGithub'
397397
description: +optional
398398
type: object
399+
gitlab:
400+
$ref: '#/definitions/v1.ReporterGitlab'
401+
description: +optional
402+
type: object
399403
msTeams:
400404
$ref: '#/definitions/v1.ReporterMSTeams'
401405
description: +optional
@@ -536,6 +540,12 @@ definitions:
536540
Github
537541
+optional
538542
type: object
543+
gitlab:
544+
$ref: '#/definitions/v1.TokenCredential'
545+
description: |-
546+
Gitlab
547+
+optional
548+
type: object
539549
secretName:
540550
description: SecretName
541551
type: string
@@ -893,7 +903,7 @@ definitions:
893903
properties:
894904
criteria:
895905
description: |-
896-
Criteria tells how does the duration apply, default is `both`.
906+
Criteria tells how does the duration apply, default is `failure`.
897907
+optional
898908
type: string
899909
duration:
@@ -1125,6 +1135,19 @@ definitions:
11251135
+optional
11261136
type: boolean
11271137
type: object
1138+
v1.ReporterGitlab:
1139+
properties:
1140+
baseURL:
1141+
description: |-
1142+
BaseURL represents a gitlab base url e.g., https://gitlab.com
1143+
+optional
1144+
type: string
1145+
enabled:
1146+
description: |-
1147+
Enabled represents an enabled flag
1148+
+optional
1149+
type: boolean
1150+
type: object
11281151
v1.ReporterMSTeams:
11291152
properties:
11301153
componentUpgrade:

examples/starter/crds/config.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,15 @@ spec:
376376
# github base url
377377
baseURL: https://github.com
378378

379+
# publishing commit status into Gitlab repository for a given commit SHA
380+
gitlab:
381+
# enabled flag of Gitlab reporter
382+
# commit status will not be published if enabled is false
383+
enabled: true
384+
385+
# gitlab base url
386+
baseURL: https://gitlab.com
387+
379388
# sending notification via slack
380389
slack:
381390
# if you would like to specify your channel
@@ -458,7 +467,7 @@ spec:
458467
# check supported value format from
459468
# https://raw.githubusercontent.com/agoda-com/samsahai/master/internal/reporter.go#ActivePromotionReporter
460469
activePromotion:
461-
command: ["/bin/sh", "-c"]
470+
command: [ "/bin/sh", "-c" ]
462471
args:
463472
- |
464473
echo "active promotion result: {{ .Result }} of {{ .TeamName }}"
@@ -467,7 +476,7 @@ spec:
467476
# check support values format from
468477
# https://raw.githubusercontent.com/agoda-com/samsahai/master/internal/reporter.go#ComponentUpgradeReporter
469478
componentUpgrade:
470-
command: ["/bin/sh", "-c"]
479+
command: [ "/bin/sh", "-c" ]
471480
args:
472481
- |
473482
echo "queue name: {{ .Name }} of {{ .TeamName }}"
@@ -476,7 +485,7 @@ spec:
476485
# check support values format from
477486
# https://raw.githubusercontent.com/agoda-com/samsahai/master/internal/reporter.go#ImageMissingReporter
478487
imageMissing:
479-
command: ["/bin/sh", "-c"]
488+
command: [ "/bin/sh", "-c" ]
480489
args:
481490
- |
482491
echo "image missing: {{ .Repository }}:{{ .Tag }}, component: {{ .ComponentName }}"
@@ -485,7 +494,7 @@ spec:
485494
# check support values format from
486495
# https://raw.githubusercontent.com/agoda-com/samsahai/master/internal/reporter.go#ComponentUpgradeReporter
487496
pullRequestQueue:
488-
command: ["/bin/sh", "-c"]
497+
command: [ "/bin/sh", "-c" ]
489498
args:
490499
- |
491500
echo "pr queue name: {{ .Name }} of {{ .TeamName }}"
@@ -494,7 +503,7 @@ spec:
494503
# check support values format from
495504
# https://raw.githubusercontent.com/agoda-com/samsahai/master/internal/reporter.go#PullRequestTriggerReporter
496505
pullRequestTrigger:
497-
command: ["/bin/sh", "-c"]
506+
command: [ "/bin/sh", "-c" ]
498507
args:
499508
- |
500509
"echo pull request trigger of {{ .PRNumber }}: {{ .Result }}"

0 commit comments

Comments
 (0)