Skip to content

Commit 3bee051

Browse files
dmitshurgopherbot
authored andcommitted
cmd/releasebot: shorten code asking for Y/n response
The Y/n prompt code performs just one atomic action. Reformat its code to be more compact accordingly. (This will help make the diff of future CLs in stack smaller.) Change-Id: Iaead279e4529cf627f68c46b914a29226f56463c Reviewed-on: https://go-review.googlesource.com/c/build/+/382934 Trust: Dmitri Shuralyov <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Trust: Carlos Amedee <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent 7517b10 commit 3bee051

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

cmd/releasebot/git.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,13 @@ func (w *Work) gitTagVersion() {
9797
fmt.Println("dry-run")
9898
return
9999
}
100-
var response string
101-
_, err := fmt.Scanln(&response)
102-
if err != nil {
100+
var resp string
101+
if _, err := fmt.Scanln(&resp); err != nil {
103102
w.log.Panic(err)
104-
}
105-
if response != "Y" && response != "y" {
103+
} else if resp != "Y" && resp != "y" {
106104
w.log.Fatal("stopped as requested")
107105
}
108-
out, err = r.runErr("git", "tag", w.Version, w.VersionCommit)
106+
out, err := r.runErr("git", "tag", w.Version, w.VersionCommit)
109107
if err != nil {
110108
w.logError("git tag failed: %s\n%s", err, out)
111109
return

cmd/releasebot/main.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,10 @@ func mailDLCL() {
212212
fmt.Println("dry-run")
213213
return
214214
}
215-
var response string
216-
_, err := fmt.Scanln(&response)
217-
if err != nil {
215+
var resp string
216+
if _, err := fmt.Scanln(&resp); err != nil {
218217
log.Fatalln(err)
219-
}
220-
if response != "Y" && response != "y" {
218+
} else if resp != "Y" && resp != "y" {
221219
log.Fatalln("stopped as requested")
222220
}
223221
changeURL, err := task.MailDLCL(context.Background(), versions)
@@ -268,12 +266,10 @@ func postTweet(kind string) {
268266
fmt.Printf("and with the following announcement URL:\n\n\t%s\n\n", tweet.Announcement)
269267
}
270268
fmt.Print("Ok? (Y/n) ")
271-
var response string
272-
_, err = fmt.Scanln(&response)
273-
if err != nil {
269+
var resp string
270+
if _, err = fmt.Scanln(&resp); err != nil {
274271
log.Fatalln(err)
275-
}
276-
if response != "Y" && response != "y" {
272+
} else if resp != "Y" && resp != "y" {
277273
log.Fatalln("stopped as requested")
278274
}
279275
tweetRelease := map[string]func(workflow.TaskContext, task.ReleaseTweet, bool) (string, error){

0 commit comments

Comments
 (0)