tweak branch conversion logic per feedback

This commit is contained in:
Brad Rydzewski 2019-07-29 13:38:27 -07:00
parent 70fa398b35
commit e0f7e22dee
8 changed files with 64 additions and 4 deletions

2
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/buildkite/yaml v2.1.0+incompatible
github.com/docker/distribution v2.7.1+incompatible
github.com/docker/go-units v0.3.3
github.com/drone/drone-runtime v1.0.7-0.20190729070836-38f28a11afe8
github.com/drone/drone-runtime v1.0.7-0.20190729202838-87c84080f4a1
github.com/ghodss/yaml v1.0.0
github.com/google/go-cmp v0.2.0
github.com/kr/pretty v0.1.0 // indirect

2
go.sum
View File

@ -23,6 +23,8 @@ github.com/drone/drone-runtime v1.0.5 h1:fEdUvKd5+l8BQaPXntjUtSIVLvGWo3Blgb/zrXL
github.com/drone/drone-runtime v1.0.5/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs=
github.com/drone/drone-runtime v1.0.7-0.20190729070836-38f28a11afe8 h1:lcS2z7+ZySmVM+XJJjBZZPTcn6IB1BSfLWtDGyco3xo=
github.com/drone/drone-runtime v1.0.7-0.20190729070836-38f28a11afe8/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs=
github.com/drone/drone-runtime v1.0.7-0.20190729202838-87c84080f4a1 h1:9xaZM1rM1/0FqFEijgnFcvWd0vRqOw+iO1YR7pBgPCw=
github.com/drone/drone-runtime v1.0.7-0.20190729202838-87c84080f4a1/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs=
github.com/drone/signal v1.0.0 h1:NrnM2M/4yAuU/tXs6RP1a1ZfxnaHwYkd0kJurA1p6uI=
github.com/drone/signal v1.0.0/go.mod h1:S8t92eFT0g4WUgEc/LxG+LCuiskpMNsG0ajAMGnyZpc=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=

View File

@ -114,7 +114,6 @@ func Convert(d []byte, remote string) ([]byte, error) {
if len(from.Branches.Include) > 0 && len(from.Branches.Exclude) == 0 {
pipeline.Trigger.Branch.Include = nil
pipeline.Trigger.Ref.Include = []string{
"refs/tags/**",
"refs/pull/**", // github
"refs/pull-requests/**", // bitbucket
"refs/merge-requests/**", // gitlab
@ -125,6 +124,15 @@ func Convert(d []byte, remote string) ([]byte, error) {
"refs/heads/"+branch,
)
}
for _, step := range pipeline.Steps {
if sliceContains("tag", step.When.Event.Include) {
pipeline.Trigger.Ref.Include = append(
pipeline.Trigger.Ref.Include,
"refs/tags/**",
)
break
}
}
}
// registry credentials need to be emulated in 0.8. The
@ -417,4 +425,14 @@ func toWorkspacePath(link string) string {
path = strings.TrimPrefix(path, "/")
path = strings.TrimSuffix(path, "/")
return "src/" + hostname + "/" + path
}
// helper function returns true if the slice the string.
func sliceContains(match string, items []string) bool {
for _, item := range items {
if item == match {
return true
}
}
return false
}

View File

@ -24,6 +24,10 @@ func TestConvert(t *testing.T) {
before: "testdata/branches.yml",
after: "testdata/branches.yml.golden",
},
{
before: "testdata/tags.yml",
after: "testdata/tags.yml.golden",
},
{
before: "testdata/vault_1.yml",
after: "testdata/vault_1.yml.golden",

View File

@ -15,7 +15,6 @@ steps:
trigger:
ref:
- refs/tags/**
- refs/pull/**
- refs/pull-requests/**
- refs/merge-requests/**

View File

@ -71,7 +71,6 @@ volumes:
trigger:
ref:
- refs/tags/**
- refs/pull/**
- refs/pull-requests/**
- refs/merge-requests/**

View File

@ -0,0 +1,10 @@
branches:
- master
pipeline:
greeting:
image: alpine
commands:
- echo hello
when:
event: [ tag, push ]

View File

@ -0,0 +1,28 @@
---
kind: pipeline
name: default
platform:
os: linux
arch: amd64
steps:
- name: greeting
pull: if-not-exists
image: alpine
commands:
- echo hello
when:
event:
- tag
- push
trigger:
ref:
- refs/pull/**
- refs/pull-requests/**
- refs/merge-requests/**
- refs/heads/master
- refs/tags/**
...