-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require confirmation if rolling back more than 9 releases #975
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"log" | ||
"os" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
"text/tabwriter" | ||
"time" | ||
|
@@ -226,7 +227,36 @@ func runRollback(cmd *Command, args []string) { | |
os.Exit(2) | ||
} | ||
ver := strings.TrimPrefix(args[0], "v") | ||
rollbackSafetyCheck(ver, appname) | ||
|
||
rel, err := client.ReleaseRollback(appname, ver, message) | ||
must(err) | ||
log.Printf("Rolled back %s to v%s as v%d.\n", appname, ver, rel.Version) | ||
} | ||
|
||
func rollbackSafetyCheck(verStr, appname string) { | ||
// Grab head release to get the current version | ||
hrels, err := client.ReleaseList(appname, &heroku.ListRange{ | ||
Field: "version", | ||
Max: 1, | ||
Descending: true, | ||
}) | ||
must(err) | ||
|
||
currVer := hrels[0].Version | ||
verNum, err := strconv.Atoi(verStr) | ||
must(err) | ||
|
||
diff := currVer - verNum | ||
if diff >= 10 { | ||
var vconfirmation string | ||
fmt.Printf("WARNING. Attempting to rollback %d versions from v%d to v%d.\n", diff, currVer, verNum) | ||
fmt.Printf("To proceed, type v%d: ", verNum) | ||
fmt.Scanln(&vconfirmation) | ||
vconfirmation = strings.TrimPrefix(vconfirmation, "v") | ||
if vconfirmation != verStr { | ||
fmt.Println("Rollback confirmation did not match.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use printFatal so it ends up on stderr and colorized. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mustConfirm takes care of the error now $ EMPIRE_API_URL=http://$(docker-machine ip default):8080 ./build/emp rollback v1 -a acme-inc
warning: Attempting to rollback 19 versions from v20 to v1. Type v1 to continue:
> v3838
error: Confirmation did not match "v1". |
||
os.Exit(2) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably re-use the mustConfirm helper here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, perfect