Skip to content

Commit

Permalink
chore: merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Oct 29, 2024
2 parents c014424 + f463fc9 commit 9f0faeb
Show file tree
Hide file tree
Showing 29 changed files with 219 additions and 158 deletions.
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ linters-settings:
- dot
- prefix(github.com/go-vela)

# https://golangci-lint.run/usage/linters/#tagalign
# ensure struct tags are aligned
# will auto fix with `make lintfix`
tagalign:
sort: false

# https://github.com/denis-tingaikin/go-header
goheader:
template: |-
Expand Down Expand Up @@ -100,6 +106,7 @@ linters:
- revive # linter for go
- staticcheck # applies static analysis checks, go vet on steroids
- stylecheck # replacement for golint
- tagalign # finds maligned struct tags
- tenv # analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- typecheck # parses and type-checks go code, like the front-end of a go compiler
- unconvert # remove unnecessary type conversions
Expand Down
28 changes: 20 additions & 8 deletions api/pipeline/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ func prepareRuleData(c *gin.Context) *pipeline.RuleData {
comment := c.Query("comment")
// capture the event type parameter
event := c.Query("event")
// capture the instance parameter
instance := c.Query("instance")
// capture the label parameter
labelSet := c.QueryArray("label")
// capture the repo parameter
ruleDataRepo := c.Query("repo")
// capture the sender parameter
sender := c.Query("sender")
// capture the status type parameter
status := c.Query("status")
// capture the tag parameter
Expand All @@ -134,20 +140,26 @@ func prepareRuleData(c *gin.Context) *pipeline.RuleData {
if len(branch) > 0 ||
len(comment) > 0 ||
len(event) > 0 ||
len(instance) > 0 ||
len(labelSet) > 0 ||
len(pathSet) > 0 ||
len(ruleDataRepo) > 0 ||
len(sender) > 0 ||
len(status) > 0 ||
len(tag) > 0 ||
len(target) > 0 {
return &pipeline.RuleData{
Branch: branch,
Comment: comment,
Event: event,
Path: pathSet,
Repo: ruleDataRepo,
Status: status,
Tag: tag,
Target: target,
Branch: branch,
Comment: comment,
Event: event,
Instance: instance,
Label: labelSet,
Path: pathSet,
Repo: ruleDataRepo,
Sender: sender,
Status: status,
Tag: tag,
Target: target,
}
}

Expand Down
38 changes: 22 additions & 16 deletions api/pipeline/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,30 @@ func TestPrepareRuleData(t *testing.T) {
{
name: "all params provided",
parameters: map[string]string{
"branch": "main",
"comment": "Test comment",
"event": "push",
"repo": "my-repo",
"status": "success",
"tag": "v1.0.0",
"target": "production",
"path": "README.md",
"branch": "main",
"comment": "Test comment",
"event": "push",
"instance": "vela-server",
"label": "bug",
"repo": "my-repo",
"sender": "octocat",
"status": "success",
"tag": "v1.0.0",
"target": "production",
"path": "README.md",
},
want: &pipeline.RuleData{
Branch: "main",
Comment: "Test comment",
Event: "push",
Repo: "my-repo",
Status: "success",
Tag: "v1.0.0",
Target: "production",
Path: []string{"README.md"},
Branch: "main",
Comment: "Test comment",
Event: "push",
Instance: "vela-server",
Label: []string{"bug"},
Repo: "my-repo",
Sender: "octocat",
Status: "success",
Tag: "v1.0.0",
Target: "production",
Path: []string{"README.md"},
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion api/types/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Secret struct {
Value *string `json:"value,omitempty"`
Type *string `json:"type,omitempty"`
Images *[]string `json:"images,omitempty"`
AllowEvents *Events `json:"allow_events,omitempty" yaml:"allow_events"`
AllowEvents *Events `json:"allow_events,omitempty" yaml:"allow_events"`
AllowCommand *bool `json:"allow_command,omitempty"`
AllowSubstitution *bool `json:"allow_substitution,omitempty"`
CreatedAt *int64 `json:"created_at,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions api/types/settings/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package settings
import "fmt"

type Compiler struct {
CloneImage *string `json:"clone_image,omitempty" yaml:"clone_image,omitempty"`
TemplateDepth *int `json:"template_depth,omitempty" yaml:"template_depth,omitempty"`
CloneImage *string `json:"clone_image,omitempty" yaml:"clone_image,omitempty"`
TemplateDepth *int `json:"template_depth,omitempty" yaml:"template_depth,omitempty"`
StarlarkExecLimit *uint64 `json:"starlark_exec_limit,omitempty" yaml:"starlark_exec_limit,omitempty"`
}

Expand Down
12 changes: 6 additions & 6 deletions api/types/settings/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
// swagger:model Platform
type Platform struct {
ID *int64 `json:"id"`
*Compiler `json:"compiler,omitempty" yaml:"compiler,omitempty"`
*Queue `json:"queue,omitempty" yaml:"queue,omitempty"`
RepoAllowlist *[]string `json:"repo_allowlist,omitempty" yaml:"repo_allowlist,omitempty"`
*Compiler `json:"compiler,omitempty" yaml:"compiler,omitempty"`
*Queue `json:"queue,omitempty" yaml:"queue,omitempty"`
RepoAllowlist *[]string `json:"repo_allowlist,omitempty" yaml:"repo_allowlist,omitempty"`
ScheduleAllowlist *[]string `json:"schedule_allowlist,omitempty" yaml:"schedule_allowlist,omitempty"`
CreatedAt *int64 `json:"created_at,omitempty" yaml:"created_at,omitempty"`
UpdatedAt *int64 `json:"updated_at,omitempty" yaml:"updated_at,omitempty"`
UpdatedBy *string `json:"updated_by,omitempty" yaml:"updated_by,omitempty"`
CreatedAt *int64 `json:"created_at,omitempty" yaml:"created_at,omitempty"`
UpdatedAt *int64 `json:"updated_at,omitempty" yaml:"updated_at,omitempty"`
UpdatedBy *string `json:"updated_by,omitempty" yaml:"updated_by,omitempty"`
}

// FromCLIContext returns a new Platform record from a cli context.
Expand Down
1 change: 1 addition & 0 deletions compiler/native/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (c *client) Compile(ctx context.Context, v interface{}) (*pipeline.Build, *
Event: event,
Path: c.files,
Repo: c.repo.GetFullName(),
Sender: c.build.GetSender(),
Tag: strings.TrimPrefix(c.build.GetRef(), "refs/tags/"),
Target: c.build.GetDeploy(),
Label: c.labels,
Expand Down
16 changes: 8 additions & 8 deletions compiler/types/pipeline/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
//
// swagger:model PipelineBuild
type Build struct {
ID string `json:"id,omitempty" yaml:"id,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Metadata Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"`
ID string `json:"id,omitempty" yaml:"id,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Metadata Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"`
Environment raw.StringSliceMap `json:"environment,omitempty" yaml:"environment,omitempty"`
Worker Worker `json:"worker,omitempty" yaml:"worker,omitempty"`
Secrets SecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"`
Services ContainerSlice `json:"services,omitempty" yaml:"services,omitempty"`
Stages StageSlice `json:"stages,omitempty" yaml:"stages,omitempty"`
Steps ContainerSlice `json:"steps,omitempty" yaml:"steps,omitempty"`
Worker Worker `json:"worker,omitempty" yaml:"worker,omitempty"`
Secrets SecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"`
Services ContainerSlice `json:"services,omitempty" yaml:"services,omitempty"`
Stages StageSlice `json:"stages,omitempty" yaml:"stages,omitempty"`
Steps ContainerSlice `json:"steps,omitempty" yaml:"steps,omitempty"`
}

// Purge removes the steps, in every stage, that contain a ruleset
Expand Down
4 changes: 2 additions & 2 deletions compiler/types/pipeline/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ type (
Ulimits UlimitSlice `json:"ulimits,omitempty" yaml:"ulimits,omitempty"`
Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
ReportAs string `json:"report_as,omitempty" yaml:"report_as,omitempty"`
IDRequest string `json:"id_request,omitempty" yaml:"id_request,omitempty"`
ReportAs string `json:"report_as,omitempty" yaml:"report_as,omitempty"`
IDRequest string `json:"id_request,omitempty" yaml:"id_request,omitempty"`
}
)

Expand Down
8 changes: 4 additions & 4 deletions compiler/types/pipeline/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ package pipeline
//
// swagger:model PipelineMetadata
type Metadata struct {
Template bool `json:"template,omitempty" yaml:"template,omitempty"`
Clone bool `json:"clone,omitempty" yaml:"clone,omitempty"`
Template bool `json:"template,omitempty" yaml:"template,omitempty"`
Clone bool `json:"clone,omitempty" yaml:"clone,omitempty"`
Environment []string `json:"environment,omitempty" yaml:"environment,omitempty"`
AutoCancel *CancelOptions `json:"auto_cancel,omitempty" yaml:"auto_cancel,omitempty"`
}

// CancelOptions is the pipeline representation of the auto_cancel block for a pipeline.
type CancelOptions struct {
Running bool `yaml:"running,omitempty" json:"running,omitempty"`
Pending bool `yaml:"pending,omitempty" json:"pending,omitempty"`
Running bool `yaml:"running,omitempty" json:"running,omitempty"`
Pending bool `yaml:"pending,omitempty" json:"pending,omitempty"`
DefaultBranch bool `yaml:"default_branch,omitempty" json:"default_branch,omitempty"`
}
12 changes: 10 additions & 2 deletions compiler/types/pipeline/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type (
Event Ruletype `json:"event,omitempty" yaml:"event,omitempty"`
Path Ruletype `json:"path,omitempty" yaml:"path,omitempty"`
Repo Ruletype `json:"repo,omitempty" yaml:"repo,omitempty"`
Sender Ruletype `json:"sender,omitempty" yaml:"sender,omitempty"`
Status Ruletype `json:"status,omitempty" yaml:"status,omitempty"`
Tag Ruletype `json:"tag,omitempty" yaml:"tag,omitempty"`
Target Ruletype `json:"target,omitempty" yaml:"target,omitempty"`
Expand All @@ -56,6 +57,7 @@ type (
Event string `json:"event,omitempty" yaml:"event,omitempty"`
Path []string `json:"path,omitempty" yaml:"path,omitempty"`
Repo string `json:"repo,omitempty" yaml:"repo,omitempty"`
Sender string `json:"sender,omitempty" yaml:"sender,omitempty"`
Status string `json:"status,omitempty" yaml:"status,omitempty"`
Tag string `json:"tag,omitempty" yaml:"tag,omitempty"`
Target string `json:"target,omitempty" yaml:"target,omitempty"`
Expand Down Expand Up @@ -113,6 +115,7 @@ func (r *Rules) Empty() bool {
len(r.Event) == 0 &&
len(r.Path) == 0 &&
len(r.Repo) == 0 &&
len(r.Sender) == 0 &&
len(r.Status) == 0 &&
len(r.Tag) == 0 &&
len(r.Target) == 0 &&
Expand Down Expand Up @@ -168,6 +171,11 @@ func (r *Rules) Match(from *RuleData, matcher, op string) (bool, error) {
return false, err
}

matchSender, err := r.Sender.MatchSingle(from.Sender, matcher, op)
if err != nil {
return false, err
}

matchTag, err := r.Tag.MatchSingle(from.Tag, matcher, op)
if err != nil {
return false, err
Expand All @@ -190,9 +198,9 @@ func (r *Rules) Match(from *RuleData, matcher, op string) (bool, error) {

switch op {
case constants.OperatorOr:
return (matchBranch || matchComment || matchEvent || matchPath || matchRepo || matchTag || matchTarget || matchLabel || matchInstance || status), nil
return (matchBranch || matchComment || matchEvent || matchPath || matchRepo || matchSender || matchTag || matchTarget || matchLabel || matchInstance || status), nil
default:
return (matchBranch && matchComment && matchEvent && matchPath && matchRepo && matchTag && matchTarget && matchLabel && matchInstance && status), nil
return (matchBranch && matchComment && matchEvent && matchPath && matchRepo && matchSender && matchTag && matchTarget && matchLabel && matchInstance && status), nil
}
}

Expand Down
5 changes: 5 additions & 0 deletions compiler/types/pipeline/ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func TestPipeline_Ruleset_Match(t *testing.T) {
data: &RuleData{Branch: "dev", Comment: "ok to test", Event: "push", Repo: "octocat/hello-world", Status: "failure", Tag: "refs/heads/main", Target: ""},
want: true,
},
{
ruleset: &Ruleset{If: Rules{Sender: []string{"octocat"}}, Operator: "and"},
data: &RuleData{Branch: "dev", Comment: "ok to test", Event: "push", Repo: "octocat/hello-world", Sender: "octocat", Status: "pending", Tag: "refs/heads/main", Target: ""},
want: true,
},
// If with or operator
{
ruleset: &Ruleset{If: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Operator: "or"},
Expand Down
18 changes: 9 additions & 9 deletions compiler/types/yaml/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (

// Build is the yaml representation of a build for a pipeline.
type Build struct {
Version string `yaml:"version,omitempty" json:"version,omitempty" jsonschema:"required,minLength=1,description=Provide syntax version used to evaluate the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/version/"`
Git Git `yaml:"git,omitempty" json:"git,omitempty" jsonschema:"description=Provide the git access specifications.\nReference: https://go-vela.github.io/docs/reference/yaml/git/"`
Metadata Metadata `yaml:"metadata,omitempty" json:"metadata,omitempty" jsonschema:"description=Pass extra information.\nReference: https://go-vela.github.io/docs/reference/yaml/metadata/"`
Version string `yaml:"version,omitempty" json:"version,omitempty" jsonschema:"required,minLength=1,description=Provide syntax version used to evaluate the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/version/"`
Metadata Metadata `yaml:"metadata,omitempty" json:"metadata,omitempty" jsonschema:"description=Pass extra information.\nReference: https://go-vela.github.io/docs/reference/yaml/metadata/"`
Environment raw.StringSliceMap `yaml:"environment,omitempty" json:"environment,omitempty" jsonschema:"description=Provide global environment variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-environment-key"`
Worker Worker `yaml:"worker,omitempty" json:"worker,omitempty" jsonschema:"description=Limit the pipeline to certain types of workers.\nReference: https://go-vela.github.io/docs/reference/yaml/worker/"`
Secrets SecretSlice `yaml:"secrets,omitempty" json:"secrets,omitempty" jsonschema:"description=Provide sensitive information.\nReference: https://go-vela.github.io/docs/reference/yaml/secrets/"`
Services ServiceSlice `yaml:"services,omitempty" json:"services,omitempty" jsonschema:"description=Provide detached (headless) execution instructions.\nReference: https://go-vela.github.io/docs/reference/yaml/services/"`
Stages StageSlice `yaml:"stages,omitempty" json:"stages,omitempty" jsonschema:"oneof_required=stages,description=Provide parallel execution instructions.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/"`
Steps StepSlice `yaml:"steps,omitempty" json:"steps,omitempty" jsonschema:"oneof_required=steps,description=Provide sequential execution instructions.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/"`
Templates TemplateSlice `yaml:"templates,omitempty" json:"templates,omitempty" jsonschema:"description=Provide the name of templates to expand.\nReference: https://go-vela.github.io/docs/reference/yaml/templates/"`
Worker Worker `yaml:"worker,omitempty" json:"worker,omitempty" jsonschema:"description=Limit the pipeline to certain types of workers.\nReference: https://go-vela.github.io/docs/reference/yaml/worker/"`
Secrets SecretSlice `yaml:"secrets,omitempty" json:"secrets,omitempty" jsonschema:"description=Provide sensitive information.\nReference: https://go-vela.github.io/docs/reference/yaml/secrets/"`
Services ServiceSlice `yaml:"services,omitempty" json:"services,omitempty" jsonschema:"description=Provide detached (headless) execution instructions.\nReference: https://go-vela.github.io/docs/reference/yaml/services/"`
Stages StageSlice `yaml:"stages,omitempty" json:"stages,omitempty" jsonschema:"oneof_required=stages,description=Provide parallel execution instructions.\nReference: https://go-vela.github.io/docs/reference/yaml/stages/"`
Steps StepSlice `yaml:"steps,omitempty" json:"steps,omitempty" jsonschema:"oneof_required=steps,description=Provide sequential execution instructions.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/"`
Templates TemplateSlice `yaml:"templates,omitempty" json:"templates,omitempty" jsonschema:"description=Provide the name of templates to expand.\nReference: https://go-vela.github.io/docs/reference/yaml/templates/"`
Git Git `yaml:"git,omitempty" json:"git,omitempty" jsonschema:"description=Provide the git access specifications.\nReference: https://go-vela.github.io/docs/reference/yaml/git/"`

Check failure on line 21 in compiler/types/yaml/build.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/types/yaml/build.go#L21

tag is not aligned, should be: yaml:"git,omitempty" json:"git,omitempty" jsonschema:"description=Provide the git access specifications.\nReference: https://go-vela.github.io/docs/reference/yaml/git/" (tagalign)
Raw output
compiler/types/yaml/build.go:21:33: tag is not aligned, should be: yaml:"git,omitempty"         json:"git,omitempty"         jsonschema:"description=Provide the git access specifications.\nReference: https://go-vela.github.io/docs/reference/yaml/git/" (tagalign)
	Git         Git                `yaml:"git,omitempty"       json:"git,omitempty"      jsonschema:"description=Provide the git access specifications.\nReference: https://go-vela.github.io/docs/reference/yaml/git/"`
	                               ^
}

// ToPipelineAPI converts the Build type to an API Pipeline type.
Expand Down
Loading

0 comments on commit 9f0faeb

Please sign in to comment.