Skip to content

Commit

Permalink
Rebasing after #67
Browse files Browse the repository at this point in the history
The `pr-status` command was added after and needed the extra danse to
include the new repo file option.

Also renamed the `pr_status` package into `prstatus` as gofumpt told me
packages should not include underscores.
https://go.dev/blog/package-names
  • Loading branch information
sledigabel committed May 24, 2023
1 parent b8a8f5a commit 5c9e79c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
23 changes: 16 additions & 7 deletions cmd/pr_status/pr_status.go → cmd/prstatus/prstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
*
*/

package pr_status
package prstatus

import (
"fmt"
"os"
"path"
"strings"

"github.com/fatih/color"
"github.com/rodaine/table"
"github.com/spf13/cobra"

"github.com/skyscanner/turbolift/internal/campaign"
"github.com/skyscanner/turbolift/internal/github"
"github.com/skyscanner/turbolift/internal/logging"
"github.com/spf13/cobra"
"os"
"path"
"strings"
)

var reactionsOrder = []string{
Expand All @@ -52,7 +54,10 @@ var reactionsMapping = map[string]string{

var gh github.GitHub = github.NewRealGitHub()

var list bool
var (
list bool
repoFile string
)

func NewPrStatusCmd() *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -61,15 +66,19 @@ func NewPrStatusCmd() *cobra.Command {
Run: run,
}
cmd.Flags().BoolVar(&list, "list", false, "Displays a listing by PR")
cmd.Flags().StringVar(&repoFile, "repos", "repos.txt", "A file containing a list of repositories to clone.")

return cmd
}

func run(c *cobra.Command, _ []string) {
logger := logging.NewLogger(c)

// dir, err := campaign.OpenCampaign()
options := campaign.NewCampaignOptions()
options.RepoFilename = repoFile
readCampaignActivity := logger.StartActivity("Reading campaign data")
dir, err := campaign.OpenCampaign()
dir, err := campaign.OpenCampaign(options)
if err != nil {
readCampaignActivity.EndWithFailure(err)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/

package pr_status
package prstatus

import (
"bytes"
Expand All @@ -22,9 +22,10 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"

"github.com/skyscanner/turbolift/internal/github"
"github.com/skyscanner/turbolift/internal/testsupport"
"github.com/stretchr/testify/assert"
)

func init() {
Expand Down Expand Up @@ -109,7 +110,6 @@ func runCommand(showList bool) (string, error) {
outBuffer := bytes.NewBufferString("")
cmd.SetOut(outBuffer)
err := cmd.Execute()

if err != nil {
return outBuffer.String(), err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import (
"fmt"
"log"

"github.com/spf13/cobra"

cloneCmd "github.com/skyscanner/turbolift/cmd/clone"
commitCmd "github.com/skyscanner/turbolift/cmd/commit"
createPrsCmd "github.com/skyscanner/turbolift/cmd/create_prs"
"github.com/skyscanner/turbolift/cmd/flags"
foreachCmd "github.com/skyscanner/turbolift/cmd/foreach"
initCmd "github.com/skyscanner/turbolift/cmd/init"
prStatusCmd "github.com/skyscanner/turbolift/cmd/prstatus"
updatePrsCmd "github.com/skyscanner/turbolift/cmd/update_prs"
"github.com/spf13/cobra"

prStatusCmd "github.com/skyscanner/turbolift/cmd/pr_status"
)

var (
Expand Down
8 changes: 4 additions & 4 deletions internal/testsupport/testsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ func PrepareTempCampaign(createDirs bool, repos ...string) string {
tempDir := CreateAndEnterTempDirectory()

delimitedList := strings.Join(repos, "\n")
err := ioutil.WriteFile("repos.txt", []byte(delimitedList), os.ModePerm|0644)
err := ioutil.WriteFile("repos.txt", []byte(delimitedList), os.ModePerm|0o644)
if err != nil {
panic(err)
}

if createDirs {
for _, name := range repos {
dirToCreate := path.Join("work", name)
err := os.MkdirAll(dirToCreate, os.ModeDir|0755)
err := os.MkdirAll(dirToCreate, os.ModeDir|0o755)
if err != nil {
panic(err)
}
}
}

dummyPrDescription := "# PR title\nPR body"
err = ioutil.WriteFile("README.md", []byte(dummyPrDescription), os.ModePerm|0644)
err = ioutil.WriteFile("README.md", []byte(dummyPrDescription), os.ModePerm|0o644)
if err != nil {
panic(err)
}
Expand All @@ -67,7 +67,7 @@ func PrepareTempCampaign(createDirs bool, repos ...string) string {

func CreateAnotherRepoFile(filename string, repos ...string) {
delimitedList := strings.Join(repos, "\n")
err := ioutil.WriteFile(filename, []byte(delimitedList), os.ModePerm|0644)
err := ioutil.WriteFile(filename, []byte(delimitedList), os.ModePerm|0o644)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 5c9e79c

Please sign in to comment.