From 78981036636b6e1702291a8bd1b8a42dbefc410e Mon Sep 17 00:00:00 2001 From: mopemoepe Date: Mon, 22 Dec 2014 02:06:12 +0900 Subject: [PATCH] Add Dropbox plugin --- plugin/publish/dropbox.go | 36 ++++++++++++++++++++++++++++++++++++ plugin/publish/publish.go | 18 ++++++++++++------ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/plugin/publish/dropbox.go b/plugin/publish/dropbox.go index 30b1a5b2..77dba061 100644 --- a/plugin/publish/dropbox.go +++ b/plugin/publish/dropbox.go @@ -1 +1,37 @@ package publish + +import ( + "fmt" + "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/shared/build/buildfile" + "strings" +) + +type Dropbox struct { + AccessToken string `yaml:"access_token,omitempty"` + + Source string `yaml:"source,omitempty"` + Target string `yaml:"target,omitempty"` + + Condition *condition.Condition `yaml:"when,omitempty"` +} + +func (d *Dropbox) Write(f *buildfile.Buildfile) { + + if len(d.AccessToken) == 0 || len(d.Source) == 0 || len(d.Target) == 0 { + return + } + if strings.HasPrefix(d.Target, "/") { + d.Target = d.Target[1:] + } + + f.WriteCmdSilent("echo 'publishing to Dropbox ...'") + + cmd := "curl --upload-file %s -H \"Authorization: Bearer %s\" \"https://api-content.dropbox.com/1/files_put/auto/%s?overwrite=true\"" + f.WriteCmd(fmt.Sprintf(cmd, d.Source, d.AccessToken, d.Target)) + +} + +func (d *Dropbox) GetCondition() *condition.Condition { + return d.Condition +} diff --git a/plugin/publish/publish.go b/plugin/publish/publish.go index 19ba9e78..4ce6d4b1 100644 --- a/plugin/publish/publish.go +++ b/plugin/publish/publish.go @@ -11,12 +11,13 @@ import ( // 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"` - Github *Github `yaml:"github,omitempty"` + 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"` + Github *Github `yaml:"github,omitempty"` + Dropbox *Dropbox `yaml:"dropbox,omitempty"` } func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) { @@ -49,6 +50,11 @@ func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) { if p.Docker != nil && match(p.Docker.GetCondition(), r) { p.Docker.Write(f) } + + // Dropbox + if p.Dropbox != nil && match(p.Dropbox.GetCondition(), r) { + p.Dropbox.Write(f) + } } func match(c *condition.Condition, r *repo.Repo) bool {