Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when: match only the current ref type #139

Merged
merged 1 commit into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/runconfig/runconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"

"agola.io/agola/internal/config"
itypes "agola.io/agola/internal/services/types"
"agola.io/agola/internal/util"
rstypes "agola.io/agola/services/runservice/types"
"agola.io/agola/services/types"
Expand Down Expand Up @@ -195,13 +196,13 @@ fi

// GenRunConfigTasks generates a run config tasks from a run in the config, expanding all the references to tasks
// this functions assumes that the config is already checked for possible errors (i.e referenced task must exits)
func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string, variables map[string]string, branch, tag, ref string) map[string]*rstypes.RunConfigTask {
func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string, variables map[string]string, refType itypes.RunRefType, branch, tag, ref string) map[string]*rstypes.RunConfigTask {
cr := c.Run(runName)

rcts := map[string]*rstypes.RunConfigTask{}

for _, ct := range cr.Tasks {
include := types.MatchWhen(ct.When.ToWhen(), branch, tag, ref)
include := types.MatchWhen(ct.When.ToWhen(), refType, branch, tag, ref)

steps := make(rstypes.Steps, len(ct.Steps))
for i, cpts := range ct.Steps {
Expand Down
2 changes: 1 addition & 1 deletion internal/runconfig/runconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ func TestGenRunConfig(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
out := GenRunConfigTasks(uuid, tt.in, "run01", tt.variables, "", "", "")
out := GenRunConfigTasks(uuid, tt.in, "run01", tt.variables, "", "", "", "")

if diff := cmp.Diff(tt.out, out); diff != "" {
t.Error(diff)
Expand Down
6 changes: 3 additions & 3 deletions internal/services/gateway/action/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,12 @@ func (h *ActionHandler) CreateRuns(ctx context.Context, req *CreateRunRequest) e
continue
}

if match := types.MatchWhen(run.When.ToWhen(), req.Branch, req.Tag, req.Ref); !match {
if match := types.MatchWhen(run.When.ToWhen(), req.RefType, req.Branch, req.Tag, req.Ref); !match {
h.log.Debugf("skipping run since when condition doesn't match")
continue
}

rcts := runconfig.GenRunConfigTasks(util.DefaultUUIDGenerator{}, config, run.Name, variables, req.Branch, req.Tag, req.Ref)
rcts := runconfig.GenRunConfigTasks(util.DefaultUUIDGenerator{}, config, run.Name, variables, req.RefType, req.Branch, req.Tag, req.Ref)

createRunReq := &rsapitypes.RunCreateRequest{
RunConfigTasks: rcts,
Expand Down Expand Up @@ -560,7 +560,7 @@ func (h *ActionHandler) genRunVariables(ctx context.Context, req *CreateRunReque
// find the value match
var varval cstypes.VariableValue
for _, varval = range pvar.Values {
match := types.MatchWhen(varval.When, req.Branch, req.Tag, req.Ref)
match := types.MatchWhen(varval.When, req.RefType, req.Branch, req.Tag, req.Ref)
if !match {
continue
}
Expand Down
278 changes: 0 additions & 278 deletions services/configstore/types/types_test.go

This file was deleted.

8 changes: 5 additions & 3 deletions services/types/when.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package types

import (
"regexp"

itypes "agola.io/agola/internal/services/types"
)

type When struct {
Expand All @@ -41,12 +43,12 @@ type WhenCondition struct {
Match string `json:"match,omitempty"`
}

func MatchWhen(when *When, branch, tag, ref string) bool {
func MatchWhen(when *When, refType itypes.RunRefType, branch, tag, ref string) bool {
include := true
if when != nil {
include = false
// test only if branch is not empty, if empty mean that we are not in a branch
if when.Branch != nil && branch != "" {
if refType == itypes.RunRefTypeBranch && when.Branch != nil && branch != "" {
// first check includes and override with excludes
if matchCondition(when.Branch.Include, branch) {
include = true
Expand All @@ -56,7 +58,7 @@ func MatchWhen(when *When, branch, tag, ref string) bool {
}
}
// test only if tag is not empty, if empty mean that we are not in a tag
if when.Tag != nil && tag != "" {
if refType == itypes.RunRefTypeBranch && when.Tag != nil && tag != "" {
// first check includes and override with excludes
if matchCondition(when.Tag.Include, tag) {
include = true
Expand Down
Loading