mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-22 01:50:40 +00:00
tweak branch conversion logic per feedback
This commit is contained in:
parent
70fa398b35
commit
e0f7e22dee
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
|||||||
github.com/buildkite/yaml v2.1.0+incompatible
|
github.com/buildkite/yaml v2.1.0+incompatible
|
||||||
github.com/docker/distribution v2.7.1+incompatible
|
github.com/docker/distribution v2.7.1+incompatible
|
||||||
github.com/docker/go-units v0.3.3
|
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/ghodss/yaml v1.0.0
|
||||||
github.com/google/go-cmp v0.2.0
|
github.com/google/go-cmp v0.2.0
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/kr/pretty v0.1.0 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -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.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 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.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 h1:NrnM2M/4yAuU/tXs6RP1a1ZfxnaHwYkd0kJurA1p6uI=
|
||||||
github.com/drone/signal v1.0.0/go.mod h1:S8t92eFT0g4WUgEc/LxG+LCuiskpMNsG0ajAMGnyZpc=
|
github.com/drone/signal v1.0.0/go.mod h1:S8t92eFT0g4WUgEc/LxG+LCuiskpMNsG0ajAMGnyZpc=
|
||||||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
||||||
|
@ -114,7 +114,6 @@ func Convert(d []byte, remote string) ([]byte, error) {
|
|||||||
if len(from.Branches.Include) > 0 && len(from.Branches.Exclude) == 0 {
|
if len(from.Branches.Include) > 0 && len(from.Branches.Exclude) == 0 {
|
||||||
pipeline.Trigger.Branch.Include = nil
|
pipeline.Trigger.Branch.Include = nil
|
||||||
pipeline.Trigger.Ref.Include = []string{
|
pipeline.Trigger.Ref.Include = []string{
|
||||||
"refs/tags/**",
|
|
||||||
"refs/pull/**", // github
|
"refs/pull/**", // github
|
||||||
"refs/pull-requests/**", // bitbucket
|
"refs/pull-requests/**", // bitbucket
|
||||||
"refs/merge-requests/**", // gitlab
|
"refs/merge-requests/**", // gitlab
|
||||||
@ -125,6 +124,15 @@ func Convert(d []byte, remote string) ([]byte, error) {
|
|||||||
"refs/heads/"+branch,
|
"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
|
// 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.TrimPrefix(path, "/")
|
||||||
path = strings.TrimSuffix(path, "/")
|
path = strings.TrimSuffix(path, "/")
|
||||||
return "src/" + hostname + "/" + 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
|
||||||
}
|
}
|
@ -24,6 +24,10 @@ func TestConvert(t *testing.T) {
|
|||||||
before: "testdata/branches.yml",
|
before: "testdata/branches.yml",
|
||||||
after: "testdata/branches.yml.golden",
|
after: "testdata/branches.yml.golden",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
before: "testdata/tags.yml",
|
||||||
|
after: "testdata/tags.yml.golden",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
before: "testdata/vault_1.yml",
|
before: "testdata/vault_1.yml",
|
||||||
after: "testdata/vault_1.yml.golden",
|
after: "testdata/vault_1.yml.golden",
|
||||||
|
@ -15,7 +15,6 @@ steps:
|
|||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
- refs/pull/**
|
||||||
- refs/pull-requests/**
|
- refs/pull-requests/**
|
||||||
- refs/merge-requests/**
|
- refs/merge-requests/**
|
||||||
|
@ -71,7 +71,6 @@ volumes:
|
|||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
- refs/pull/**
|
||||||
- refs/pull-requests/**
|
- refs/pull-requests/**
|
||||||
- refs/merge-requests/**
|
- refs/merge-requests/**
|
||||||
|
10
yaml/converter/legacy/internal/testdata/tags.yml
vendored
Normal file
10
yaml/converter/legacy/internal/testdata/tags.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
pipeline:
|
||||||
|
greeting:
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- echo hello
|
||||||
|
when:
|
||||||
|
event: [ tag, push ]
|
28
yaml/converter/legacy/internal/testdata/tags.yml.golden
vendored
Normal file
28
yaml/converter/legacy/internal/testdata/tags.yml.golden
vendored
Normal 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/**
|
||||||
|
|
||||||
|
...
|
Loading…
Reference in New Issue
Block a user