Skip to content

Commit

Permalink
Merge pull request #16 from remind101/abort-prod-push
Browse files Browse the repository at this point in the history
Ask for confirmation before deploying to prod. Fix #13.
  • Loading branch information
benguillet committed May 15, 2015
2 parents 0482ff5 + 256d633 commit eb3aae3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions deploy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deploy

import (
"bufio"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -70,6 +71,10 @@ var flags = []cli.Flag{
},
}

var ProtectedEnvironments = map[string]bool{
"production": true,
}

// NewApp returns a new cli.App for the deploy command.
func NewApp() *cli.App {
app := cli.NewApp()
Expand Down Expand Up @@ -182,6 +187,13 @@ func newDeploymentRequest(c *cli.Context) (*github.DeploymentRequest, error) {
return nil, fmt.Errorf("--env flag is required")
}

if ProtectedEnvironments[env] {
yes := askYN("Are you sure you want to push to production?")
if !yes {
return nil, fmt.Errorf("Deployment aborted.")
}
}

var contexts *[]string
if c.Bool("force") {
s := []string{}
Expand Down Expand Up @@ -341,3 +353,10 @@ func SplitRepo(nwo, defaultOrg string) (owner string, repo string, err error) {

return
}

func askYN(prompt string) bool {
r := bufio.NewReader(os.Stdin)
fmt.Printf("%s (y/N)\n", prompt)
a, _ := r.ReadString('\n')
return strings.ToUpper(a) == "Y\n"
}

0 comments on commit eb3aae3

Please sign in to comment.