Merge pull request #744 from shawnzhu/heroku

use api key for deployment to heroku
This commit is contained in:
Brad Rydzewski 2014-12-11 11:41:23 -08:00
commit c18f4385cd
2 changed files with 20 additions and 2 deletions

View file

@ -14,11 +14,16 @@ const (
// individual that made the commit. // individual that made the commit.
CmdGlobalEmail = "git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')" CmdGlobalEmail = "git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')"
CmdGlobalUser = "git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')" CmdGlobalUser = "git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')"
// Command to write the API token to ~/.netrc
// use "_" since heroku git authentication ignores username
CmdLogin = "echo 'machine git.heroku.com login _ password %s' >> ~/.netrc"
) )
type Heroku struct { type Heroku struct {
App string `yaml:"app,omitempty"` App string `yaml:"app,omitempty"`
Force bool `yaml:"force,omitempty"` Force bool `yaml:"force,omitempty"`
Token string `yaml:"token,omitempty"`
Condition *condition.Condition `yaml:"when,omitempty"` Condition *condition.Condition `yaml:"when,omitempty"`
} }
@ -27,9 +32,10 @@ func (h *Heroku) Write(f *buildfile.Buildfile) {
f.WriteCmdSilent(CmdRevParse) f.WriteCmdSilent(CmdRevParse)
f.WriteCmdSilent(CmdGlobalUser) f.WriteCmdSilent(CmdGlobalUser)
f.WriteCmdSilent(CmdGlobalEmail) f.WriteCmdSilent(CmdGlobalEmail)
f.WriteCmdSilent(fmt.Sprintf(CmdLogin, h.Token))
// add heroku as a git remote // add heroku as a git remote
f.WriteCmd(fmt.Sprintf("git remote add heroku git@heroku.com:%s.git", h.App)) f.WriteCmd(fmt.Sprintf("git remote add heroku https://git.heroku.com/%s.git", h.App))
switch h.Force { switch h.Force {
case true: case true:

View file

@ -26,6 +26,18 @@ func Test_Heroku(t *testing.T) {
g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true) g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true)
}) })
g.It("Should write token", func() {
b := new(buildfile.Buildfile)
h := Heroku{
App: "drone",
Token: "mock-token",
}
h.Write(b)
out := b.String()
g.Assert(strings.Contains(out, "\necho 'machine git.heroku.com login _ password mock-token' >> ~/.netrc\n")).Equal(true)
})
g.It("Should add remote", func() { g.It("Should add remote", func() {
b := new(buildfile.Buildfile) b := new(buildfile.Buildfile)
h := Heroku{ h := Heroku{
@ -34,7 +46,7 @@ func Test_Heroku(t *testing.T) {
h.Write(b) h.Write(b)
out := b.String() out := b.String()
g.Assert(strings.Contains(out, "\ngit remote add heroku git@heroku.com:drone.git\n")).Equal(true) g.Assert(strings.Contains(out, "\ngit remote add heroku https://git.heroku.com/drone.git\n")).Equal(true)
}) })
g.It("Should push to remote", func() { g.It("Should push to remote", func() {