Merge pull request #768 from mopemope/dropbox

Add Dropbox plugin
This commit is contained in:
Brad Rydzewski 2014-12-27 12:52:23 -08:00
commit 4ec8eff504
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

@ -17,6 +17,7 @@ type Publish struct {
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 {