Add Dropbox plugin

This commit is contained in:
mopemoepe 2014-12-22 02:06:12 +09:00
parent f1c5a45b5a
commit 7898103663
2 changed files with 48 additions and 6 deletions

View file

@ -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
}

View file

@ -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 {