Skip to content

Commit

Permalink
fix(create_prs): Fix race condition (#151)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sledigabel authored Nov 5, 2024
1 parent 0dffae8 commit 557329a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ jobs:
go-version: ^1.16

- name: Run tests
run: go test ./...

run: make test
7 changes: 5 additions & 2 deletions cmd/create_prs/create_prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ package create_prs

import (
"fmt"
"github.com/skyscanner/turbolift/internal/prompt"
"os"
"path"
"strings"
"time"

"github.com/skyscanner/turbolift/internal/prompt"

"github.com/spf13/cobra"

"github.com/skyscanner/turbolift/internal/campaign"
Expand Down Expand Up @@ -72,12 +73,14 @@ func run(c *cobra.Command, _ []string) {
readCampaignActivity.EndWithFailure(err)
return
}
readCampaignActivity.EndWithSuccess()

// checking whether the description has changed
if prDescriptionUnchanged(dir) {
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)) {
return
}
}
readCampaignActivity.EndWithSuccess()

doneCount := 0
skippedCount := 0
Expand Down
15 changes: 3 additions & 12 deletions cmd/create_prs/create_prs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,7 @@ func runCommand() (string, error) {
outBuffer := bytes.NewBufferString("")
cmd.SetOut(outBuffer)
err := cmd.Execute()
if err != nil {
return outBuffer.String(), err
}
return outBuffer.String(), nil
return outBuffer.String(), err
}

func runCommandWithAlternativeDescriptionFile(fileName string) (string, error) {
Expand All @@ -237,10 +234,7 @@ func runCommandWithAlternativeDescriptionFile(fileName string) (string, error) {
outBuffer := bytes.NewBufferString("")
cmd.SetOut(outBuffer)
err := cmd.Execute()
if err != nil {
return outBuffer.String(), err
}
return outBuffer.String(), nil
return outBuffer.String(), err
}

func runCommandDraft() (string, error) {
Expand All @@ -249,8 +243,5 @@ func runCommandDraft() (string, error) {
outBuffer := bytes.NewBufferString("")
cmd.SetOut(outBuffer)
err := cmd.Execute()
if err != nil {
return outBuffer.String(), err
}
return outBuffer.String(), nil
return outBuffer.String(), err
}

0 comments on commit 557329a

Please sign in to comment.