diff --git a/cli/sfconfig/cmd/bootstrap-tenant-config-repo/bootstrap-tenant-config-repo.go b/cli/sfconfig/cmd/bootstrap-tenant-config-repo/bootstrap-tenant-config-repo.go index 2fa046a7..1401da9e 100644 --- a/cli/sfconfig/cmd/bootstrap-tenant-config-repo/bootstrap-tenant-config-repo.go +++ b/cli/sfconfig/cmd/bootstrap-tenant-config-repo/bootstrap-tenant-config-repo.go @@ -95,13 +95,14 @@ Note: If the directories does not exit they will be created `, Example: ` - ./tools/sfconfig bootstrap-tenant-config-repo --connection gerrit --outpath / - ./tools/sfconfig bootstrap-tenant-config-repo --connection github --outpath / + ./tools/sfconfig bootstrap-tenant-config-repo --connection gerrit-conn --driver gerrit --outpath / + ./tools/sfconfig bootstrap-tenant-config-repo --connection github-conn --driver github --outpath / `, Aliases: []string{"boot"}, Run: func(cmd *cobra.Command, args []string) { connection, _ := cmd.Flags().GetString("connection") + driver, _ := cmd.Flags().GetString("driver") outpath, _ := cmd.Flags().GetString("outpath") zuulrootdir = outpath @@ -110,74 +111,51 @@ Note: If the directories does not exit they will be created fmt.Println(err) } + // Check Pipeline + requireCheck, err := utils.GetRequireCheckByDriver(driver, connection) + if err != nil { + fmt.Println(err) + } + triggerCheck, err := utils.GetTriggerCheckByDriver(driver, connection) + if err != nil { + fmt.Println(err) + } + reportersCheck, err := utils.GetReportersCheckByDriver(driver, connection) + if err != nil { + fmt.Println(err) + } + // Gate Pipeline + requireGate, err := utils.GetRequireGateByDriver(driver, connection) + if err != nil { + fmt.Println(err) + } + triggerGate, err := utils.GetTriggerGateByDriver(driver, connection) + if err != nil { + fmt.Println(err) + } + reportersGate, err := utils.GetReportersGateByDriver(driver, connection) + if err != nil { + fmt.Println(err) + } + // Post Pipeline + triggerPost, err := utils.GetTriggerPostByDriver(driver, connection) + if err != nil { + fmt.Println(err) + } + zuulpipelinefilepath := filepath.Join(zuulrootdir, zuuldropindir, connection+"-pipeline.yaml") if err := createZuulPipelineFile(utils.PipelineConfig{ { Pipeline: utils.PipelineBody{ Name: "check", - Description: `Newly uploaded patchsets enter this + Description: `Newly uploaded patchsets enter this pipeline to receive an initial +/-1 Verified vote.`, Manager: utils.Independent, - Require: utils.PipelineRequire{ - connection: utils.PipelineRequireApproval{ - Open: true, - CurrentPatchset: true, - }, - }, - Trigger: utils.PipelineGenericTrigger{ - connection: utils.PipelineTriggerGitArray{ - { - Event: "patchset-created", - }, - { - Event: "change-restored", - }, - { - Event: "comment-added", - Comment: "(?i)^(Patch Set [0-9]+:)?( [\\w\\+-]*)*(\\n\\n)?\\s*(recheck|reverify)", - }, - { - Event: "comment-added", - Gerrit: utils.PipelineTriggerGitGerrit{ - Approval: []utils.PipelineRequireApproval{ - { - Username: "zuul", - Verified: []utils.GerritVotePoint{ - utils.GetZuulPipelineReporterVerified("-1"), - utils.GetZuulPipelineReporterVerified("-2"), - }, - }, - }, - }, - Approval: []utils.PipelineRequireGerritApproval{ - { - Workflow: utils.GetGerritWorkflowValue("1"), - }, - }, - }, - }, - }, - Start: utils.PipelineReporter{ - GerritReporter: utils.GerritReporterMap{ - connection: utils.PipelineGerritReporter{ - Verified: utils.GetZuulPipelineReporterVerified("0"), - }, - }, - }, - Success: utils.PipelineReporter{ - GerritReporter: utils.GerritReporterMap{ - connection: utils.PipelineGerritReporter{ - Verified: utils.GetZuulPipelineReporterVerified("1"), - }, - }, - }, - Failure: utils.PipelineReporter{ - GerritReporter: utils.GerritReporterMap{ - connection: utils.PipelineGerritReporter{ - Verified: utils.GetZuulPipelineReporterVerified("-1"), - }, - }, - }, + Require: requireCheck, + Trigger: triggerCheck, + Start: reportersCheck[0], + Success: reportersCheck[1], + Failure: reportersCheck[2], }, }, { @@ -190,60 +168,11 @@ pipeline to receive an initial +/-1 Verified vote.`, Supercedes: []string{"check"}, PostReview: true, Manager: utils.Dependent, - Require: utils.PipelineRequire{ - connection: utils.PipelineRequireApproval{ - Open: true, - CurrentPatchset: true, - GerritApproval: []utils.PipelineRequireGerritApproval{ - { - Workflow: utils.GetGerritWorkflowValue("1"), - }, - }, - }, - }, - Trigger: utils.PipelineGenericTrigger{ - connection: utils.PipelineTriggerGitArray{ - { - Event: "comment-added", - Approval: []utils.PipelineRequireGerritApproval{ - { - Workflow: utils.GetGerritWorkflowValue("1"), - }, - }, - }, - { - Event: "comment-added", - Approval: []utils.PipelineRequireGerritApproval{ - { - Verified: utils.GetZuulPipelineReporterVerified("1"), - }, - }, - Username: "zuul", - }, - }, - }, - Start: utils.PipelineReporter{ - GerritReporter: utils.GerritReporterMap{ - connection: utils.PipelineGerritReporter{ - Verified: utils.GetZuulPipelineReporterVerified("0"), - }, - }, - }, - Success: utils.PipelineReporter{ - GerritReporter: utils.GerritReporterMap{ - connection: utils.PipelineGerritReporter{ - Verified: utils.GetZuulPipelineReporterVerified("2"), - Submit: true, - }, - }, - }, - Failure: utils.PipelineReporter{ - GerritReporter: utils.GerritReporterMap{ - connection: utils.PipelineGerritReporter{ - Verified: utils.GetZuulPipelineReporterVerified("-2"), - }, - }, - }, + Require: requireGate, + Trigger: triggerGate, + Start: reportersGate[0], + Success: reportersGate[1], + Failure: reportersGate[2], }, }, { @@ -253,21 +182,7 @@ pipeline to receive an initial +/-1 Verified vote.`, Description: `This pipeline runs jobs that operate after each change is merged.`, Manager: utils.Supercedent, Precedence: utils.GetZuulPipelinePrecedence("low"), - Trigger: utils.PipelineGenericTrigger{ - "git-server": utils.PipelineTriggerGitArray{ - { - Event: "ref-updated", - }, - }, - connection: utils.PipelineTriggerGitArray{ - { - Event: "ref-updated", - Ref: []string{ - "^refs/heads/.*$", - }, - }, - }, - }, + Trigger: triggerPost, }, }, }, zuulpipelinefilepath); err != nil { @@ -349,6 +264,8 @@ pipeline to receive an initial +/-1 Verified vote.`, func init() { BootstrapTenantConfigRepoCmd.Flags().String("connection", "", "Name of the connection or a source") BootstrapTenantConfigRepoCmd.MarkFlagRequired("connection") + BootstrapTenantConfigRepoCmd.Flags().String("driver", "", "Driver type of the connection") + BootstrapTenantConfigRepoCmd.MarkFlagRequired("driver") BootstrapTenantConfigRepoCmd.Flags().String("outpath", "", "Path to create file structure") BootstrapTenantConfigRepoCmd.MarkFlagRequired("outpath") } diff --git a/controllers/git_server.go b/controllers/git_server.go index b2c8aa00..7d080382 100644 --- a/controllers/git_server.go +++ b/controllers/git_server.go @@ -127,12 +127,12 @@ func (r *SFController) MkPreInitScript() string { Manager: zuulcf.Supercedent, Precedence: zuulcf.Low, Trigger: zuulcf.PipelineGenericTrigger{ - "git-server": zuulcf.PipelineTriggerGitArray{ + "git-server": zuulcf.PipelineTriggerArray{ { Event: "ref-updated", }, }, - configRepoConnectionName: zuulcf.PipelineTriggerGitArray{ + configRepoConnectionName: zuulcf.PipelineTriggerArray{ { Event: "ref-updated", Ref: []string{ @@ -150,12 +150,14 @@ func (r *SFController) MkPreInitScript() string { Manager: zuulcf.Independent, Require: zuulcf.PipelineRequire{ configRepoConnectionName: zuulcf.PipelineRequireApproval{ - Open: true, - CurrentPatchset: true, + Open: true, + Gerrit: zuulcf.PipelineGerritRequirement{ + CurrentPatchset: true, + }, }, }, Trigger: zuulcf.PipelineGenericTrigger{ - configRepoConnectionName: zuulcf.PipelineTriggerGitArray{ + configRepoConnectionName: zuulcf.PipelineTriggerArray{ { Event: "patchset-created", }, @@ -168,43 +170,53 @@ func (r *SFController) MkPreInitScript() string { }, { Event: "comment-added", - Gerrit: zuulcf.PipelineTriggerGitGerrit{ - Approval: []zuulcf.PipelineRequireApproval{ - { - Verified: []zuulcf.GerritVotePoint{ - zuulcf.GerritVotePointMinusOne, - zuulcf.GerritVotePointMinusTwo, + GitTrigger: zuulcf.PipelineTriggerGit{ + Gerrit: zuulcf.PipelineTriggerGitGerrit{ + Approval: []zuulcf.PipelineRequireApproval{ + { + Gerrit: zuulcf.PipelineGerritRequirement{ + Verified: []zuulcf.GerritVotePoint{ + zuulcf.GerritVotePointMinusOne, + zuulcf.GerritVotePointMinusTwo, + }, + Username: "zuul", + }, }, - Username: "zuul", }, }, - }, - Approval: []zuulcf.PipelineRequireGerritApproval{ - { - Workflow: zuulcf.GetGerritWorkflowValue("1"), + Approval: []zuulcf.PipelineRequireGerritApproval{ + { + Workflow: zuulcf.GetGerritWorkflowValue("1"), + }, }, }, }, }, }, Start: zuulcf.PipelineReporter{ - GerritReporter: zuulcf.GerritReporterMap{ - configRepoConnectionName: zuulcf.PipelineGerritReporter{ - Verified: zuulcf.GerritVotePointZero, + Reporter: zuulcf.ReporterMap{ + configRepoConnectionName: zuulcf.PipelineDriverReporter{ + Gerrit: &zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointZero, + }, }, }, }, Success: zuulcf.PipelineReporter{ - GerritReporter: zuulcf.GerritReporterMap{ - configRepoConnectionName: zuulcf.PipelineGerritReporter{ - Verified: zuulcf.GerritVotePointOne, + Reporter: zuulcf.ReporterMap{ + configRepoConnectionName: zuulcf.PipelineDriverReporter{ + Gerrit: &zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointOne, + }, }, }, }, Failure: zuulcf.PipelineReporter{ - GerritReporter: zuulcf.GerritReporterMap{ - configRepoConnectionName: zuulcf.PipelineGerritReporter{ - Verified: zuulcf.GerritVotePointMinusOne, + Reporter: zuulcf.ReporterMap{ + configRepoConnectionName: zuulcf.PipelineDriverReporter{ + Gerrit: &zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointMinusOne, + }, }, }, }, @@ -224,55 +236,68 @@ func (r *SFController) MkPreInitScript() string { PostReview: true, Require: zuulcf.PipelineRequire{ configRepoConnectionName: zuulcf.PipelineRequireApproval{ - Open: true, - CurrentPatchset: true, - GerritApproval: []zuulcf.PipelineRequireGerritApproval{ - { - Workflow: zuulcf.GetGerritWorkflowValue("1"), + Open: true, + Gerrit: zuulcf.PipelineGerritRequirement{ + CurrentPatchset: true, + GerritApproval: []zuulcf.PipelineRequireGerritApproval{ + { + Workflow: zuulcf.GetGerritWorkflowValue("1"), + }, }, }, }, }, Trigger: zuulcf.PipelineGenericTrigger{ - configRepoConnectionName: zuulcf.PipelineTriggerGitArray{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineTriggerArray{ { Event: "comment-added", - Approval: []zuulcf.PipelineRequireGerritApproval{ - { - Workflow: zuulcf.GetGerritWorkflowValue("1"), + GitTrigger: zuulcf.PipelineTriggerGit{ + Approval: []zuulcf.PipelineRequireGerritApproval{ + { + Workflow: zuulcf.GetGerritWorkflowValue("1"), + }, }, + Username: "zuul", }, }, { Event: "comment-added", - Approval: []zuulcf.PipelineRequireGerritApproval{ - { - Verified: zuulcf.GerritVotePointOne, + GitTrigger: zuulcf.PipelineTriggerGit{ + Approval: []zuulcf.PipelineRequireGerritApproval{ + { + Verified: zuulcf.GerritVotePointOne, + }, }, + Username: "zuul", }, - Username: "zuul", }, }, }, Start: zuulcf.PipelineReporter{ - GerritReporter: zuulcf.GerritReporterMap{ - configRepoConnectionName: zuulcf.PipelineGerritReporter{ - Verified: zuulcf.GerritVotePointZero, + Reporter: zuulcf.ReporterMap{ + configRepoConnectionName: zuulcf.PipelineDriverReporter{ + Gerrit: &zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointZero, + }, }, }, }, Success: zuulcf.PipelineReporter{ - GerritReporter: zuulcf.GerritReporterMap{ - configRepoConnectionName: zuulcf.PipelineGerritReporter{ - Verified: zuulcf.GerritVotePointTwo, - Submit: true, + Reporter: zuulcf.ReporterMap{ + configRepoConnectionName: zuulcf.PipelineDriverReporter{ + Gerrit: &zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointTwo, + Submit: true, + }, }, }, }, Failure: zuulcf.PipelineReporter{ - GerritReporter: zuulcf.GerritReporterMap{ - configRepoConnectionName: zuulcf.PipelineGerritReporter{ - Verified: zuulcf.GerritVotePointMinusTwo, + Reporter: zuulcf.ReporterMap{ + configRepoConnectionName: zuulcf.PipelineDriverReporter{ + Gerrit: &zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointMinusTwo, + }, }, }, }, diff --git a/controllers/libs/zuulcf/zuulcf.go b/controllers/libs/zuulcf/zuulcf.go index 84e316ad..ffd21268 100644 --- a/controllers/libs/zuulcf/zuulcf.go +++ b/controllers/libs/zuulcf/zuulcf.go @@ -1,4 +1,7 @@ -// Package zuulcf provides a little library with utilities for Zuul Configurations +// Copyright (C) 2023 Red Hat +// SPDX-License-Identifier: Apache-2.0 + +// Package zuulcf contains a library to build Zuul configurations. package zuulcf import ( @@ -258,41 +261,93 @@ type PipelineRequireGerritApproval struct { CodeReview GerritCodeReview `yaml:"Code-Review,omitempty"` } -type PipelineRequireApproval struct { +type PipelineGerritRequirement struct { Username string `yaml:"username,omitempty"` - Open bool `yaml:"open,omitempty"` CurrentPatchset bool `yaml:"current-patchset,omitempty"` Verified []GerritVotePoint `yaml:"Verified,omitempty,flow"` GerritApproval []PipelineRequireGerritApproval `yaml:"approval,omitempty"` Workflow GerritWorkflow `yaml:"Workflow,omitempty"` } +type PipelineGitLabRequirement struct { + Merged bool `yaml:"merged,omitempty"` + Approved bool `yaml:"approved,omitempty"` + Labels []string `yaml:"labels,omitempty"` +} + +type PipelineRequireApproval struct { + Open bool `yaml:"open,omitempty"` + Gerrit PipelineGerritRequirement `yaml:",inline,omitempty"` + Gitlab PipelineGitLabRequirement `yaml:",inline,omitempty"` +} + type PipelineTriggerGitGerrit struct { Approval []PipelineRequireApproval `yaml:"approval,omitempty"` } +type GitGLMergeRequests string + +const ( + Opened GitGLMergeRequests = "opened" + Changed GitGLMergeRequests = "changed" + Merged GitGLMergeRequests = "merged" + Comment GitGLMergeRequests = "comment" + Approved GitGLMergeRequests = "approved" + Unapproved GitGLMergeRequests = "unapproved" + Labeled GitGLMergeRequests = "labeled" +) + +type PipelineTriggerGitLab struct { + Action []GitGLMergeRequests `yaml:"action,omitempty"` + Labels []string `yaml:"labels,omitempty"` + Unlabels []string `yaml:"unlabels,omitempty"` +} + type PipelineTriggerGit struct { - Event string `yaml:"event"` - Comment string `yaml:"comment,omitempty"` Gerrit PipelineTriggerGitGerrit `yaml:"require,omitempty"` - Ref []string `yaml:"ref,omitempty"` Approval []PipelineRequireGerritApproval `yaml:"approval,omitempty"` Username string `yaml:"username,omitempty"` } -type PipelineTriggerGitArray []PipelineTriggerGit +type PipelineTrigger struct { + Event string `yaml:"event"` + Comment string `yaml:"comment,omitempty"` + Ref []string `yaml:"ref,omitempty"` + GitTrigger PipelineTriggerGit `yaml:",inline"` + GitLabTrigger PipelineTriggerGitLab `yaml:",inline"` +} + +type PipelineTriggerArray []PipelineTrigger + +type PipelineGenericTrigger map[string]PipelineTriggerArray -type PipelineGenericTrigger map[string]PipelineTriggerGitArray +type PipelineGitLabReporter struct { + Comment bool `yaml:"comment"` + Approval bool `yaml:"approval"` + Merge bool `yaml:"merge,omitempty"` + Labels []string `yaml:"labels,omitempty"` + Unlabels []string `yaml:"unlabels,omitempty"` +} type PipelineGerritReporter struct { Submit bool `yaml:"submit,omitempty"` Verified GerritVotePoint `yaml:"Verified"` } +type PipelineDriverReporter struct { + Gitlab *PipelineGitLabReporter `yaml:",inline,omitempty"` + Gerrit *PipelineGerritReporter `yaml:",inline,omitempty"` +} + +type ReporterMap map[string]PipelineDriverReporter + +type GitLabReporterMap map[string]PipelineGitLabReporter + type GerritReporterMap map[string]PipelineGerritReporter + type PipelineReporter struct { - GerritReporter GerritReporterMap `yaml:",inline"` - SQLReporter []string `yaml:"sqlreporter,omitempty"` + Reporter ReporterMap `yaml:",inline"` + SQLReporter []string `yaml:"sqlreporter,omitempty"` } type PipelinePrecedence string @@ -382,3 +437,407 @@ type Semaphore struct { } type Semaphores []Semaphore + +func GetRequireCheckByDriver(driver string, connection string) (PipelineRequire, error) { + require := PipelineRequire{} + + switch driver { + case "gerrit": + require = PipelineRequire{ + connection: PipelineRequireApproval{ + Open: true, + Gerrit: PipelineGerritRequirement{ + CurrentPatchset: true, + }, + }, + } + case "gitlab": + require = PipelineRequire{ + connection: PipelineRequireApproval{ + Open: true, + }, + } + default: + return require, fmt.Errorf("Check Pipeline Require: Driver of type \"" + driver + "\" is not supported") + } + + return require, nil +} + +func GetRequireGateByDriver(driver string, connection string) (PipelineRequire, error) { + require := PipelineRequire{} + + switch driver { + case "gerrit": + require = PipelineRequire{ + connection: PipelineRequireApproval{ + Open: true, + Gerrit: PipelineGerritRequirement{ + CurrentPatchset: true, + GerritApproval: []PipelineRequireGerritApproval{ + { + Workflow: GetGerritWorkflowValue("1"), + }, + }, + }, + }, + } + case "gitlab": + require = PipelineRequire{ + connection: PipelineRequireApproval{ + Open: true, + Gitlab: PipelineGitLabRequirement{ + Approved: true, + Labels: []string{ + "gateit", + }, + }, + }, + } + default: + return require, fmt.Errorf("Gate Pipeline Require: Driver of type \"" + driver + "\" is not supported") + } + + return require, nil +} + +func GetTriggerCheckByDriver(driver string, connection string) (PipelineGenericTrigger, error) { + trigger := PipelineGenericTrigger{} + switch driver { + case "gerrit": + trigger = PipelineGenericTrigger{ + connection: PipelineTriggerArray{ + { + Event: "patchset-created", + }, + { + Event: "change-restored", + }, + { + Event: "comment-added", + Comment: "(?i)^(Patch Set [0-9]+:)?( [\\w\\+-]*)*(\\n\\n)?\\s*(recheck|reverify)", + }, + { + Event: "comment-added", + GitTrigger: PipelineTriggerGit{ + Gerrit: PipelineTriggerGitGerrit{ + Approval: []PipelineRequireApproval{ + { + Gerrit: PipelineGerritRequirement{ + Username: "zuul", + Verified: []GerritVotePoint{ + GetZuulPipelineReporterVerified("-1"), + GetZuulPipelineReporterVerified("-2"), + }, + }, + }, + }, + }, + Approval: []PipelineRequireGerritApproval{ + { + Workflow: GetGerritWorkflowValue("1"), + }, + }, + }, + }, + }, + } + case "gitlab": + trigger = PipelineGenericTrigger{ + connection: PipelineTriggerArray{ + { + Event: "gl_merge_request", + GitLabTrigger: PipelineTriggerGitLab{ + Action: []GitGLMergeRequests{ + GitGLMergeRequests(Comment), + }, + }, + Comment: "(?i)^\\s*recheck\\s*$", + }, + { + Event: "gl_merge_request", + GitLabTrigger: PipelineTriggerGitLab{ + Action: []GitGLMergeRequests{ + GitGLMergeRequests(Opened), + GitGLMergeRequests(Changed), + }, + }, + }, + }, + } + default: + return trigger, fmt.Errorf("Check Pipeline Trigger: Driver of type \"" + driver + "\" is not supported") + } + + return trigger, nil +} + +func GetTriggerGateByDriver(driver string, connection string) (PipelineGenericTrigger, error) { + trigger := PipelineGenericTrigger{} + switch driver { + case "gerrit": + trigger = PipelineGenericTrigger{ + connection: PipelineTriggerArray{ + { + Event: "comment-added", + GitTrigger: PipelineTriggerGit{ + Approval: []PipelineRequireGerritApproval{ + { + Workflow: GetGerritWorkflowValue("1"), + }, + }, + }, + }, + { + Event: "comment-added", + GitTrigger: PipelineTriggerGit{ + Approval: []PipelineRequireGerritApproval{ + { + Verified: GetZuulPipelineReporterVerified("1"), + }, + }, + Username: "zuul", + }, + }, + }, + } + case "gitlab": + trigger = PipelineGenericTrigger{ + connection: PipelineTriggerArray{ + { + Event: "gl_merge_request", + GitLabTrigger: PipelineTriggerGitLab{ + Action: []GitGLMergeRequests{ + GitGLMergeRequests(Approved), + }, + }, + }, + { + Event: "gl_merge_request", + GitLabTrigger: PipelineTriggerGitLab{ + Action: []GitGLMergeRequests{ + GitGLMergeRequests(Labeled), + }, + Labels: []string{ + "gateit", + }, + }, + }, + }, + } + default: + return trigger, fmt.Errorf("Gate Pipeline Trigger: Driver of type \"" + driver + "\" is not supported") + } + + return trigger, nil +} + +func GetTriggerPostByDriver(driver string, connection string) (PipelineGenericTrigger, error) { + trigger := PipelineGenericTrigger{ + "git-server": PipelineTriggerArray{ + { + Event: "ref-updated", + }, + }, + } + + switch driver { + case "gerrit": + trigger = PipelineGenericTrigger{ + connection: PipelineTriggerArray{ + { + Event: "ref-updated", + Ref: []string{ + "^refs/heads/.*$", + }, + }, + }, + } + case "gitlab": + trigger = PipelineGenericTrigger{ + connection: PipelineTriggerArray{ + { + Event: "gl_push", + Ref: []string{ + "^refs/heads/.*$", + }, + }, + }, + } + default: + return trigger, fmt.Errorf("Post Pipeline Trigger: Driver of type \"" + driver + "\" is not supported") + } + + return trigger, nil +} + +func GetReportersCheckByDriver(driver string, connection string) ([]PipelineReporter, error) { + reporters := []PipelineReporter{} + switch driver { + case "gerrit": + // Start + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gerrit: &PipelineGerritReporter{ + Verified: GetZuulPipelineReporterVerified("0"), + }, + }, + }, + }) + // Success + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gerrit: &PipelineGerritReporter{ + Verified: GetZuulPipelineReporterVerified("1"), + }, + }, + }, + }) + // Failure + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gerrit: &PipelineGerritReporter{ + Verified: GetZuulPipelineReporterVerified("-1"), + }, + }, + }, + }) + case "gitlab": + // Start + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gitlab: &PipelineGitLabReporter{ + Comment: true, + Approval: false, + }, + }, + }, + }) + // Success + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gitlab: &PipelineGitLabReporter{ + Comment: true, + Approval: true, + }, + }, + }, + }) + // Failure + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gitlab: &PipelineGitLabReporter{ + Comment: true, + Approval: false, + }, + }, + }, + }) + default: + reporters = append(reporters, PipelineReporter{}, + PipelineReporter{}, + PipelineReporter{}) + return reporters, fmt.Errorf("Check Pipeline Reporters: Driver of type \"" + driver + "\" is not supported") + + } + + return reporters, nil +} + +func GetReportersGateByDriver(driver string, connection string) ([]PipelineReporter, error) { + reporters := []PipelineReporter{} + switch driver { + case "gerrit": + // Start + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gerrit: &PipelineGerritReporter{ + Verified: GetZuulPipelineReporterVerified("0"), + }, + }, + }, + }) + // Success + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gerrit: &PipelineGerritReporter{ + Verified: GetZuulPipelineReporterVerified("2"), + Submit: true, + }, + }, + }, + }) + // Failure + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gerrit: &PipelineGerritReporter{ + Verified: GetZuulPipelineReporterVerified("-2"), + }, + }, + }, + }) + case "gitlab": + // Start + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gitlab: &PipelineGitLabReporter{ + Comment: true, + Approval: false, + }, + }, + }, + }) + // Success + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gitlab: &PipelineGitLabReporter{ + Comment: true, + Approval: true, + Merge: true, + }, + }, + }, + }) + // Failure + reporters = append(reporters, + PipelineReporter{ + Reporter: ReporterMap{ + connection: PipelineDriverReporter{ + Gitlab: &PipelineGitLabReporter{ + Comment: true, + Approval: false, + }, + }, + }, + }) + default: + reporters = append(reporters, PipelineReporter{}, + PipelineReporter{}, + PipelineReporter{}) + return reporters, fmt.Errorf("Gate Pipeline Reporters: Driver of type \"" + driver + "\" is not supported") + } + + return reporters, nil +}