Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Ranson committed Nov 5, 2024
1 parent 74301a3 commit 3388a62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions cmd/foreach/foreach.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
var exec executor.Executor = executor.NewRealExecutor()

var (
repoFile string
repoFile = "repos.txt"
successful bool
failed bool

Expand All @@ -48,7 +48,7 @@ var (
failedReposFileName string
)

const previousResultsSymlink = ".previous_results"
const previousResultsSymlink = "..turbolift_previous_results"

func formatArguments(arguments []string) string {
quotedArgs := make([]string, len(arguments))
Expand Down Expand Up @@ -80,7 +80,7 @@ marks that no further options should be interpreted by turbolift.`,
Args: cobra.MinimumNArgs(1),
}

cmd.Flags().StringVar(&repoFile, "repos", "", "A file containing a list of repositories to clone.")
cmd.Flags().StringVar(&repoFile, "repos", "repos.txt", "A file containing a list of repositories to clone.")
cmd.Flags().BoolVar(&successful, "successful", false, "Indication of whether to run against previously successful repos only.")
cmd.Flags().BoolVar(&failed, "failed", false, "Indication of whether to run against previously failed repos only.")

Expand All @@ -94,24 +94,24 @@ func runE(c *cobra.Command, args []string) error {
return errors.New("Use -- to separate command")
}

customRepoFile := repoFile != ""
if moreThanOne(successful, failed, customRepoFile) {
return errors.New("only one repositories flag or option may be specified: either --successful; --failed; or --repos <file>")
isCustomRepoFile := repoFile != "repos.txt"
if moreThanOne(successful, failed, isCustomRepoFile) {
return errors.New("a maximum of one repositories flag / option may be specified: either --successful; --failed; or --repos <file>")
}
if successful {
previousResults, err := os.Readlink(previousResultsSymlink)
if err != nil {
return errors.New("no previous foreach logs found")
}
repoFile = path.Join(previousResults, "successful", "repos.txt")
logger.Printf("Running against previously successful repos only")
} else if failed {
previousResults, err := os.Readlink(previousResultsSymlink)
if err != nil {
return errors.New("no previous foreach logs found")
}
repoFile = path.Join(previousResults, "failed", "repos.txt")
} else if !customRepoFile {
repoFile = "repos.txt"
logger.Printf("Running against previously failed repos only")
}

readCampaignActivity := logger.StartActivity("Reading campaign data (%s)", repoFile)
Expand Down
4 changes: 2 additions & 2 deletions cmd/foreach/foreach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestItCreatesSymlinksSuccessfully(t *testing.T) {
assert.Contains(t, out, "turbolift foreach completed")
assert.Contains(t, out, "2 OK, 0 skipped, 1 errored")

resultsDir, err := os.Readlink(".previous_results")
resultsDir, err := os.Readlink("..turbolift_previous_results")
if err != nil {

t.Errorf("Error reading symlink: %s", err)
Expand Down Expand Up @@ -334,7 +334,7 @@ func setUpSymlink() error {
if err != nil {
return err
}
err = os.Symlink("mock_output", ".previous_results")
err = os.Symlink("mock_output", "..turbolift_previous_results")
if err != nil {
return err
}
Expand Down

0 comments on commit 3388a62

Please sign in to comment.