Skip to content

Commit 557329a

Browse files
authored
fix(create_prs): Fix race condition (#151)
* fix(create_prs): Fix race condition - Moved `readCampaignActivity.EndWithSuccess()` to the correct position Having the activity end after the Prompt means the spinner creates a race condition. - Simplified error handling in `runCommand` functions by returning the error directly. * feat(ci): update test command to use make
1 parent 0dffae8 commit 557329a

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

.github/workflows/test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ jobs:
1818
go-version: ^1.16
1919

2020
- name: Run tests
21-
run: go test ./...
22-
21+
run: make test

cmd/create_prs/create_prs.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ package create_prs
1717

1818
import (
1919
"fmt"
20-
"github.com/skyscanner/turbolift/internal/prompt"
2120
"os"
2221
"path"
2322
"strings"
2423
"time"
2524

25+
"github.com/skyscanner/turbolift/internal/prompt"
26+
2627
"github.com/spf13/cobra"
2728

2829
"github.com/skyscanner/turbolift/internal/campaign"
@@ -72,12 +73,14 @@ func run(c *cobra.Command, _ []string) {
7273
readCampaignActivity.EndWithFailure(err)
7374
return
7475
}
76+
readCampaignActivity.EndWithSuccess()
77+
78+
// checking whether the description has changed
7579
if prDescriptionUnchanged(dir) {
7680
if !p.AskConfirm(fmt.Sprintf("It looks like the PR title and/or description may not have been updated in %s. Are you sure you want to proceed?", prDescriptionFile)) {
7781
return
7882
}
7983
}
80-
readCampaignActivity.EndWithSuccess()
8184

8285
doneCount := 0
8386
skippedCount := 0

cmd/create_prs/create_prs_test.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ func runCommand() (string, error) {
225225
outBuffer := bytes.NewBufferString("")
226226
cmd.SetOut(outBuffer)
227227
err := cmd.Execute()
228-
if err != nil {
229-
return outBuffer.String(), err
230-
}
231-
return outBuffer.String(), nil
228+
return outBuffer.String(), err
232229
}
233230

234231
func runCommandWithAlternativeDescriptionFile(fileName string) (string, error) {
@@ -237,10 +234,7 @@ func runCommandWithAlternativeDescriptionFile(fileName string) (string, error) {
237234
outBuffer := bytes.NewBufferString("")
238235
cmd.SetOut(outBuffer)
239236
err := cmd.Execute()
240-
if err != nil {
241-
return outBuffer.String(), err
242-
}
243-
return outBuffer.String(), nil
237+
return outBuffer.String(), err
244238
}
245239

246240
func runCommandDraft() (string, error) {
@@ -249,8 +243,5 @@ func runCommandDraft() (string, error) {
249243
outBuffer := bytes.NewBufferString("")
250244
cmd.SetOut(outBuffer)
251245
err := cmd.Execute()
252-
if err != nil {
253-
return outBuffer.String(), err
254-
}
255-
return outBuffer.String(), nil
246+
return outBuffer.String(), err
256247
}

0 commit comments

Comments
 (0)