convert legacy branch syntax to ref trigger

This commit is contained in:
Brad Rydzewski 2019-07-18 18:15:30 -07:00
parent daa7e18674
commit e8b24d482c
6 changed files with 65 additions and 3 deletions

View File

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- Convert legacy branch filter to ref trigger, by [@bradrydzewski](https://github.com/bradrydzewski).
## [1.2.1] - 2019-07-17 ## [1.2.1] - 2019-07-17
### Added ### Added
- Pull if-not-exists when converting legacy yaml files, by [@bradrydzewski](https://github.com/bradrydzewski). - Pull if-not-exists when converting legacy yaml files, by [@bradrydzewski](https://github.com/bradrydzewski).

View File

@ -67,7 +67,7 @@ func Convert(d []byte, remote string) ([]byte, error) {
pipeline.Workspace.Path = "" pipeline.Workspace.Path = ""
} }
if os.Getenv("DRONE_CONVERT_YAML_DEFAULT_WORKSPACE") == "true" { if remote != "" {
if pipeline.Workspace.Base == "" { if pipeline.Workspace.Base == "" {
pipeline.Workspace.Base = "/drone" pipeline.Workspace.Base = "/drone"
} }
@ -109,6 +109,24 @@ func Convert(d []byte, remote string) ([]byte, error) {
pipeline.Trigger.Branch.Include = from.Branches.Include pipeline.Trigger.Branch.Include = from.Branches.Include
pipeline.Trigger.Branch.Exclude = from.Branches.Exclude pipeline.Trigger.Branch.Exclude = from.Branches.Exclude
// if the user specifies branch conditions, we need to make
// sure they are still able to execute tag events.
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
}
for _, branch := range from.Branches.Include {
pipeline.Trigger.Ref.Include = append(
pipeline.Trigger.Ref.Include,
"refs/heads/"+branch,
)
}
}
// registry credentials need to be emulated in 0.8. The // registry credentials need to be emulated in 0.8. The
// migration utility automatically creates a secret named // migration utility automatically creates a secret named
// .dockerconfigjson for the registry credentials, which // .dockerconfigjson for the registry credentials, which

View File

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

View File

@ -0,0 +1,8 @@
branches:
- master
pipeline:
greeting:
image: alpine
commands:
- echo hello

View File

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

View File

@ -70,7 +70,11 @@ volumes:
path: /tmp/go path: /tmp/go
trigger: trigger:
branch: ref:
- master - refs/tags/**
- refs/pull/**
- refs/pull-requests/**
- refs/merge-requests/**
- refs/heads/master
... ...