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.
|
||||
f.WriteCmd(fmt.Sprintf("git add -A"))
|
||||
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:
|
||||
// otherwise we just do a standard git push
|
||||
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.
|
||||
f.WriteCmd(fmt.Sprintf("git add -A"))
|
||||
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:
|
||||
// otherwise we just do a standard git push
|
||||
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.
|
||||
f.WriteCmd(fmt.Sprintf("git add -A"))
|
||||
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:
|
||||
// otherwise we just do a standard git push
|
||||
f.WriteCmd(fmt.Sprintf("git push tsuru $COMMIT:master"))
|
||||
|
|
|
@ -3,15 +3,14 @@ package notify
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/drone/drone/shared/model"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
const (
|
||||
slackEndpoint = "https://%s.slack.com/services/hooks/incoming-webhook?token=%s"
|
||||
slackStartedMessage = "*Building* %s, commit <%s|%s>, author %s"
|
||||
slackSuccessMessage = "*Success* %s, commit <%s|%s>, author %s"
|
||||
slackFailureMessage = "*Failed* %s, commit <%s|%s>, author %s"
|
||||
slackStartedMessage = "*Building* %s <%s|%s>, by %s:\n> %s"
|
||||
slackSuccessMessage = "*Success* %s <%s|%s>, by %s:\n> %s"
|
||||
slackFailureMessage = "*Failed* %s <%s|%s>, by %s:\n> %s"
|
||||
)
|
||||
|
||||
type Slack struct {
|
||||
|
@ -24,7 +23,7 @@ type Slack struct {
|
|||
Failure bool `yaml:"on_failure,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Slack) Send(context *model.Request) error {
|
||||
func (s *Slack) Send(context *Context) error {
|
||||
switch {
|
||||
case context.Commit.Status == "Started" && s.Started:
|
||||
return s.sendStarted(context)
|
||||
|
@ -37,21 +36,36 @@ func (s *Slack) Send(context *model.Request) error {
|
|||
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)
|
||||
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 {
|
||||
return s.send(s.getMessage(context, slackStartedMessage), "warning")
|
||||
func (s *Slack) sendStarted(context *Context) error {
|
||||
return s.send(getMessage(context, slackStartedMessage), "warning")
|
||||
}
|
||||
|
||||
func (s *Slack) sendSuccess(context *model.Request) error {
|
||||
return s.send(s.getMessage(context, slackSuccessMessage), "good")
|
||||
func (s *Slack) sendSuccess(context *Context) error {
|
||||
return s.send(getMessage(context, slackSuccessMessage), "good")
|
||||
}
|
||||
|
||||
func (s *Slack) sendFailure(context *model.Request) error {
|
||||
return s.send(s.getMessage(context, slackFailureMessage), "danger")
|
||||
func (s *Slack) sendFailure(context *Context) error {
|
||||
return s.send(getMessage(context, slackFailureMessage), "danger")
|
||||
}
|
||||
|
||||
// helper function to send HTTP requests
|
||||
|
@ -86,8 +100,7 @@ func (s *Slack) send(msg string, color string) error {
|
|||
|
||||
// send payload
|
||||
url := fmt.Sprintf(slackEndpoint, s.Team, s.Token)
|
||||
|
||||
go sendJson(url, payload, nil)
|
||||
go sendJson(url, payload)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -244,6 +244,8 @@ func (b *Builder) setup() error {
|
|||
if err := b.dockerClient.Images.Pull(b.Build.Image); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
log.Errf("failed to inspect image %s", b.Build.Image)
|
||||
}
|
||||
|
||||
// create the Docker image
|
||||
|
@ -439,7 +441,7 @@ func (b *Builder) writeDockerfile(dir string) error {
|
|||
switch {
|
||||
case strings.HasPrefix(b.Build.Image, "bradrydzewski/"),
|
||||
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
|
||||
// inherit from the ubuntu cloud ISO
|
||||
dockerfile.WriteUser("ubuntu")
|
||||
|
|
|
@ -570,7 +570,7 @@ func TestWriteBuildScript(t *testing.T) {
|
|||
f.WriteEnv("CI_BRANCH", "master")
|
||||
f.WriteEnv("CI_PULL_REQUEST", "123")
|
||||
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 checkout -qf -b pr/123 origin/pr/123")
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ var builders = map[string]*image{
|
|||
"gcc4.8": {Tag: "bradrydzewski/gcc:4.8"},
|
||||
|
||||
// Golang build images
|
||||
"go": {Tag: "bradrydzewski/go:1.2"},
|
||||
"go": {Tag: "bradrydzewski/go:1.3"},
|
||||
"go1": {Tag: "bradrydzewski/go:1.0"},
|
||||
"go1.1": {Tag: "bradrydzewski/go:1.1"},
|
||||
"go1.2": {Tag: "bradrydzewski/go:1.2"},
|
||||
|
|
|
@ -103,21 +103,18 @@ func (r *Repo) Commands() []string {
|
|||
}
|
||||
|
||||
cmds := []string{}
|
||||
cmds = append(cmds, fmt.Sprintf("git clone --depth=%d --recursive --branch=%s %s %s", r.Depth, branch, r.Path, r.Dir))
|
||||
|
||||
switch {
|
||||
// if a specific commit is provided then we'll
|
||||
// need to clone it.
|
||||
case len(r.PR) > 0:
|
||||
|
||||
if len(r.PR) > 0 {
|
||||
// If a specific PR is provided then we need to clone it.
|
||||
cmds = append(cmds, fmt.Sprintf("git clone --depth=%d --recursive %s %s", r.Depth, r.Path, r.Dir))
|
||||
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 fetch origin +refs/pull/%s/merge:", r.PR))
|
||||
//cmds = append(cmds, fmt.Sprintf("git checkout -qf %s", "FETCH_HEAD"))
|
||||
// if a specific commit is provided then we'll
|
||||
// need to clone it.
|
||||
case len(r.Commit) > 0:
|
||||
cmds = append(cmds, fmt.Sprintf("git checkout -qf %s", r.Commit))
|
||||
} else {
|
||||
// Otherwise just clone the branch.
|
||||
cmds = append(cmds, fmt.Sprintf("git clone --depth=%d --recursive --branch=%s %s %s", r.Depth, branch, r.Path, r.Dir))
|
||||
// If a specific commit is provided then we'll need to check it out.
|
||||
if len(r.Commit) > 0 {
|
||||
cmds = append(cmds, fmt.Sprintf("git checkout -qf %s", r.Commit))
|
||||
}
|
||||
}
|
||||
|
||||
return cmds
|
||||
|
|
Loading…
Reference in a new issue