merged plugin changes from master to exp
This commit is contained in:
parent
c283fcae20
commit
ea05ec725a
8 changed files with 47 additions and 35 deletions
|
@ -38,7 +38,7 @@ func (g *Git) Write(f *buildfile.Buildfile) {
|
||||||
// that need to be deployed to git remote.
|
// that need to be deployed to git remote.
|
||||||
f.WriteCmd(fmt.Sprintf("git add -A"))
|
f.WriteCmd(fmt.Sprintf("git add -A"))
|
||||||
f.WriteCmd(fmt.Sprintf("git commit -m 'add build artifacts'"))
|
f.WriteCmd(fmt.Sprintf("git commit -m 'add build artifacts'"))
|
||||||
f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:%s --force", destinationBranch))
|
f.WriteCmd(fmt.Sprintf("git push deploy HEAD:%s --force", destinationBranch))
|
||||||
case false:
|
case false:
|
||||||
// otherwise we just do a standard git push
|
// otherwise we just do a standard git push
|
||||||
f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:%s", destinationBranch))
|
f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:%s", destinationBranch))
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (h *Heroku) Write(f *buildfile.Buildfile) {
|
||||||
// that need to be deployed to Heroku.
|
// that need to be deployed to Heroku.
|
||||||
f.WriteCmd(fmt.Sprintf("git add -A"))
|
f.WriteCmd(fmt.Sprintf("git add -A"))
|
||||||
f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'"))
|
f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'"))
|
||||||
f.WriteCmd(fmt.Sprintf("git push heroku $COMMIT:master --force"))
|
f.WriteCmd(fmt.Sprintf("git push heroku HEAD:master --force"))
|
||||||
case false:
|
case false:
|
||||||
// otherwise we just do a standard git push
|
// otherwise we just do a standard git push
|
||||||
f.WriteCmd(fmt.Sprintf("git push heroku $COMMIT:master"))
|
f.WriteCmd(fmt.Sprintf("git push heroku $COMMIT:master"))
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (t *Tsuru) Write(f *buildfile.Buildfile) {
|
||||||
// that need to be deployed to Tsuru.
|
// that need to be deployed to Tsuru.
|
||||||
f.WriteCmd(fmt.Sprintf("git add -A"))
|
f.WriteCmd(fmt.Sprintf("git add -A"))
|
||||||
f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'"))
|
f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'"))
|
||||||
f.WriteCmd(fmt.Sprintf("git push tsuru $COMMIT:master --force"))
|
f.WriteCmd(fmt.Sprintf("git push tsuru HEAD:master --force"))
|
||||||
case false:
|
case false:
|
||||||
// otherwise we just do a standard git push
|
// otherwise we just do a standard git push
|
||||||
f.WriteCmd(fmt.Sprintf("git push tsuru $COMMIT:master"))
|
f.WriteCmd(fmt.Sprintf("git push tsuru $COMMIT:master"))
|
||||||
|
|
|
@ -3,15 +3,14 @@ package notify
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"github.com/drone/drone/shared/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
slackEndpoint = "https://%s.slack.com/services/hooks/incoming-webhook?token=%s"
|
slackEndpoint = "https://%s.slack.com/services/hooks/incoming-webhook?token=%s"
|
||||||
slackStartedMessage = "*Building* %s, commit <%s|%s>, author %s"
|
slackStartedMessage = "*Building* %s <%s|%s>, by %s:\n> %s"
|
||||||
slackSuccessMessage = "*Success* %s, commit <%s|%s>, author %s"
|
slackSuccessMessage = "*Success* %s <%s|%s>, by %s:\n> %s"
|
||||||
slackFailureMessage = "*Failed* %s, commit <%s|%s>, author %s"
|
slackFailureMessage = "*Failed* %s <%s|%s>, by %s:\n> %s"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Slack struct {
|
type Slack struct {
|
||||||
|
@ -24,7 +23,7 @@ type Slack struct {
|
||||||
Failure bool `yaml:"on_failure,omitempty"`
|
Failure bool `yaml:"on_failure,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Slack) Send(context *model.Request) error {
|
func (s *Slack) Send(context *Context) error {
|
||||||
switch {
|
switch {
|
||||||
case context.Commit.Status == "Started" && s.Started:
|
case context.Commit.Status == "Started" && s.Started:
|
||||||
return s.sendStarted(context)
|
return s.sendStarted(context)
|
||||||
|
@ -37,21 +36,36 @@ func (s *Slack) Send(context *model.Request) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Slack) getMessage(context *model.Request, message string) string {
|
func getBuildUrl(context *Context) string {
|
||||||
|
branchQuery := url.Values{}
|
||||||
|
if context.Commit.Branch != "" {
|
||||||
|
branchQuery.Set("branch", context.Commit.Branch)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s/%s/commit/%s?%s", context.Host, context.Repo.Slug, context.Commit.Hash, branchQuery.Encode())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMessage(context *Context, message string) string {
|
||||||
url := getBuildUrl(context)
|
url := getBuildUrl(context)
|
||||||
return fmt.Sprintf(message, context.Repo.Name, url, context.Commit.ShaShort(), context.Commit.Author)
|
return fmt.Sprintf(
|
||||||
|
message,
|
||||||
|
context.Repo.Name,
|
||||||
|
url,
|
||||||
|
context.Commit.HashShort(),
|
||||||
|
context.Commit.Author,
|
||||||
|
context.Commit.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Slack) sendStarted(context *model.Request) error {
|
func (s *Slack) sendStarted(context *Context) error {
|
||||||
return s.send(s.getMessage(context, slackStartedMessage), "warning")
|
return s.send(getMessage(context, slackStartedMessage), "warning")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Slack) sendSuccess(context *model.Request) error {
|
func (s *Slack) sendSuccess(context *Context) error {
|
||||||
return s.send(s.getMessage(context, slackSuccessMessage), "good")
|
return s.send(getMessage(context, slackSuccessMessage), "good")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Slack) sendFailure(context *model.Request) error {
|
func (s *Slack) sendFailure(context *Context) error {
|
||||||
return s.send(s.getMessage(context, slackFailureMessage), "danger")
|
return s.send(getMessage(context, slackFailureMessage), "danger")
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to send HTTP requests
|
// helper function to send HTTP requests
|
||||||
|
@ -86,8 +100,7 @@ func (s *Slack) send(msg string, color string) error {
|
||||||
|
|
||||||
// send payload
|
// send payload
|
||||||
url := fmt.Sprintf(slackEndpoint, s.Team, s.Token)
|
url := fmt.Sprintf(slackEndpoint, s.Team, s.Token)
|
||||||
|
go sendJson(url, payload)
|
||||||
go sendJson(url, payload, nil)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,6 +244,8 @@ func (b *Builder) setup() error {
|
||||||
if err := b.dockerClient.Images.Pull(b.Build.Image); err != nil {
|
if err := b.dockerClient.Images.Pull(b.Build.Image); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
log.Errf("failed to inspect image %s", b.Build.Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the Docker image
|
// create the Docker image
|
||||||
|
@ -439,7 +441,7 @@ func (b *Builder) writeDockerfile(dir string) error {
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(b.Build.Image, "bradrydzewski/"),
|
case strings.HasPrefix(b.Build.Image, "bradrydzewski/"),
|
||||||
strings.HasPrefix(b.Build.Image, "drone/"):
|
strings.HasPrefix(b.Build.Image, "drone/"):
|
||||||
// the default user for all official Drone imnage
|
// the default user for all official Drone image
|
||||||
// is the "ubuntu" user, since all build images
|
// is the "ubuntu" user, since all build images
|
||||||
// inherit from the ubuntu cloud ISO
|
// inherit from the ubuntu cloud ISO
|
||||||
dockerfile.WriteUser("ubuntu")
|
dockerfile.WriteUser("ubuntu")
|
||||||
|
|
|
@ -570,7 +570,7 @@ func TestWriteBuildScript(t *testing.T) {
|
||||||
f.WriteEnv("CI_BRANCH", "master")
|
f.WriteEnv("CI_BRANCH", "master")
|
||||||
f.WriteEnv("CI_PULL_REQUEST", "123")
|
f.WriteEnv("CI_PULL_REQUEST", "123")
|
||||||
f.WriteHost("127.0.0.1")
|
f.WriteHost("127.0.0.1")
|
||||||
f.WriteCmd("git clone --depth=0 --recursive --branch=master git://github.com/drone/drone.git /var/cache/drone/github.com/drone/drone")
|
f.WriteCmd("git clone --depth=0 --recursive git://github.com/drone/drone.git /var/cache/drone/github.com/drone/drone")
|
||||||
f.WriteCmd("git fetch origin +refs/pull/123/head:refs/remotes/origin/pr/123")
|
f.WriteCmd("git fetch origin +refs/pull/123/head:refs/remotes/origin/pr/123")
|
||||||
f.WriteCmd("git checkout -qf -b pr/123 origin/pr/123")
|
f.WriteCmd("git checkout -qf -b pr/123 origin/pr/123")
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ var builders = map[string]*image{
|
||||||
"gcc4.8": {Tag: "bradrydzewski/gcc:4.8"},
|
"gcc4.8": {Tag: "bradrydzewski/gcc:4.8"},
|
||||||
|
|
||||||
// Golang build images
|
// Golang build images
|
||||||
"go": {Tag: "bradrydzewski/go:1.2"},
|
"go": {Tag: "bradrydzewski/go:1.3"},
|
||||||
"go1": {Tag: "bradrydzewski/go:1.0"},
|
"go1": {Tag: "bradrydzewski/go:1.0"},
|
||||||
"go1.1": {Tag: "bradrydzewski/go:1.1"},
|
"go1.1": {Tag: "bradrydzewski/go:1.1"},
|
||||||
"go1.2": {Tag: "bradrydzewski/go:1.2"},
|
"go1.2": {Tag: "bradrydzewski/go:1.2"},
|
||||||
|
|
|
@ -103,21 +103,18 @@ func (r *Repo) Commands() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmds := []string{}
|
cmds := []string{}
|
||||||
cmds = append(cmds, fmt.Sprintf("git clone --depth=%d --recursive --branch=%s %s %s", r.Depth, branch, r.Path, r.Dir))
|
if len(r.PR) > 0 {
|
||||||
|
// If a specific PR is provided then we need to clone it.
|
||||||
switch {
|
cmds = append(cmds, fmt.Sprintf("git clone --depth=%d --recursive %s %s", r.Depth, r.Path, r.Dir))
|
||||||
// if a specific commit is provided then we'll
|
|
||||||
// need to clone it.
|
|
||||||
case len(r.PR) > 0:
|
|
||||||
|
|
||||||
cmds = append(cmds, fmt.Sprintf("git fetch origin +refs/pull/%s/head:refs/remotes/origin/pr/%s", r.PR, r.PR))
|
cmds = append(cmds, fmt.Sprintf("git fetch origin +refs/pull/%s/head:refs/remotes/origin/pr/%s", r.PR, r.PR))
|
||||||
cmds = append(cmds, fmt.Sprintf("git checkout -qf -b pr/%s origin/pr/%s", r.PR, r.PR))
|
cmds = append(cmds, fmt.Sprintf("git checkout -qf -b pr/%s origin/pr/%s", r.PR, r.PR))
|
||||||
//cmds = append(cmds, fmt.Sprintf("git fetch origin +refs/pull/%s/merge:", r.PR))
|
} else {
|
||||||
//cmds = append(cmds, fmt.Sprintf("git checkout -qf %s", "FETCH_HEAD"))
|
// Otherwise just clone the branch.
|
||||||
// if a specific commit is provided then we'll
|
cmds = append(cmds, fmt.Sprintf("git clone --depth=%d --recursive --branch=%s %s %s", r.Depth, branch, r.Path, r.Dir))
|
||||||
// need to clone it.
|
// If a specific commit is provided then we'll need to check it out.
|
||||||
case len(r.Commit) > 0:
|
if len(r.Commit) > 0 {
|
||||||
cmds = append(cmds, fmt.Sprintf("git checkout -qf %s", r.Commit))
|
cmds = append(cmds, fmt.Sprintf("git checkout -qf %s", r.Commit))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmds
|
return cmds
|
||||||
|
|
Loading…
Reference in a new issue