1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/plugin/publish/publish.go

61 lines
1.3 KiB
Go
Raw Normal View History

2014-02-07 13:10:01 +03:00
package publish
import (
"github.com/drone/drone/plugin/condition"
2014-10-08 05:15:33 +03:00
"github.com/drone/drone/plugin/publish/npm"
2014-06-05 00:25:38 +03:00
"github.com/drone/drone/shared/build/buildfile"
"github.com/drone/drone/shared/build/repo"
2014-02-07 13:10:01 +03:00
)
// Publish stores the configuration details
// for publishing build artifacts when
// a Build has succeeded
type Publish struct {
S3 *S3 `yaml:"s3,omitempty"`
Swift *Swift `yaml:"swift,omitempty"`
PyPI *PyPI `yaml:"pypi,omitempty"`
NPM *npm.NPM `yaml:"npm,omitempty"`
Docker *Docker `yaml:"docker,omitempty"`
2014-02-07 13:10:01 +03:00
}
func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) {
// S3
if p.S3 != nil && match(p.S3.GetCondition(), r) {
2014-02-07 13:10:01 +03:00
p.S3.Write(f)
}
// Swift
if p.Swift != nil && match(p.Swift.GetCondition(), r) {
p.Swift.Write(f)
}
// PyPI
if p.PyPI != nil && match(p.PyPI.GetCondition(), r) {
2014-03-28 08:43:58 +03:00
p.PyPI.Write(f)
}
2014-05-04 20:29:51 +03:00
// NPM
if p.NPM != nil && match(p.NPM.GetCondition(), r) {
2014-05-04 20:29:51 +03:00
p.NPM.Write(f)
}
// Docker
if p.Docker != nil && (len(p.Docker.Branch) == 0 || (len(p.Docker.Branch) > 0 && r.Branch == p.Docker.Branch)) {
p.Docker.Write(f, r)
}
2014-02-07 13:10:01 +03:00
}
func match(c *condition.Condition, r *repo.Repo) bool {
switch {
case c == nil:
return true
case !c.MatchBranch(r.Branch):
return false
case !c.MatchOwner(r.Name):
return false
case !c.MatchPullRequest(r.PR):
return false
}
return true
}