Skip to content

Commit

Permalink
Add detail output flag to print status bits info
Browse files Browse the repository at this point in the history
Fixes:#54

commit-id:2bee239b
  • Loading branch information
ejoffe committed Jun 22, 2021
1 parent edf19ff commit b4546ff
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/amend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
}

ctx := context.Background()
sd := spr.NewStackedPR(nil, nil, gitcmd, os.Stdout, false)
sd := spr.NewStackedPR(nil, nil, gitcmd, os.Stdout, false, false)
sd.AmendCommit(ctx)
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/spr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func init() {

// command line options
type opts struct {
Debug bool `short:"d" long:"debug" description:"Show runtime debug info."`
Debug bool `long:"debug" description:"Show runtime debug info."`
Detail bool `short:"d" long:"detail" description:"Show detailed output."`
Merge bool `short:"m" long:"merge" description:"Merge all mergeable pull requests."`
Status bool `short:"s" long:"status" description:"Show status of open pull requests."`
Update bool `short:"u" long:"update" description:"Update and create pull requests for unmerged commits in the stack."`
Expand Down Expand Up @@ -79,7 +80,7 @@ func main() {

ctx := context.Background()
client := githubclient.NewGitHubClient(ctx, &cfg)
stackedpr := spr.NewStackedPR(&cfg, client, gitcmd, os.Stdout, opts.Debug)
stackedpr := spr.NewStackedPR(&cfg, client, gitcmd, os.Stdout, opts.Debug, opts.Detail)

if opts.Update {
stackedpr.UpdatePullRequests(ctx)
Expand Down
16 changes: 15 additions & 1 deletion spr/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import (
)

// NewStackedPR constructs and returns a new stackediff instance.
func NewStackedPR(config *config.Config, github github.GitHubInterface, gitcmd git.GitInterface, writer io.Writer, debug bool) *stackediff {
func NewStackedPR(config *config.Config, github github.GitHubInterface, gitcmd git.GitInterface, writer io.Writer,
debug bool, detail bool) *stackediff {
if debug {
return &stackediff{
config: config,
github: github,
gitcmd: gitcmd,
writer: writer,
debug: true,
detail: false,
profiletimer: profiletimer.StartProfileTimer(),
}
}
Expand All @@ -36,6 +38,7 @@ func NewStackedPR(config *config.Config, github github.GitHubInterface, gitcmd g
gitcmd: gitcmd,
writer: writer,
debug: false,
detail: detail,
profiletimer: profiletimer.StartNoopTimer(),
}
}
Expand All @@ -46,6 +49,7 @@ type stackediff struct {
gitcmd git.GitInterface
writer io.Writer
debug bool
detail bool
profiletimer profiletimer.Timer
}

Expand Down Expand Up @@ -233,6 +237,9 @@ func (sd *stackediff) StatusPullRequests(ctx context.Context) {
pr := githubInfo.PullRequests[i]
fmt.Fprintf(sd.writer, "%s\n", pr.String(sd.config))
}
if sd.detail {
fmt.Fprint(sd.writer, detailMessage)
}
sd.profiletimer.Step("StatusPullRequests::End")
}

Expand Down Expand Up @@ -448,3 +455,10 @@ func check(err error) {
panic(err)
}
}

var detailMessage = ` ││││
│││└─ stack check
││└── no merge conflicts
│└─── pull request approved
└──── github checks pass
`
8 changes: 4 additions & 4 deletions spr/spr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestSPRBasicFlowFourCommits(t *testing.T) {
LocalBranch: "master",
}
var output bytes.Buffer
s := NewStackedPR(&cfg, githubmock, gitmock, &output, false)
s := NewStackedPR(&cfg, githubmock, gitmock, &output, false, false)

ctx := context.Background()

Expand Down Expand Up @@ -137,7 +137,7 @@ func TestSPRAmendCommit(t *testing.T) {
LocalBranch: "master",
}
var output bytes.Buffer
s := NewStackedPR(&cfg, githubmock, gitmock, &output, false)
s := NewStackedPR(&cfg, githubmock, gitmock, &output, false, false)

ctx := context.Background()

Expand Down Expand Up @@ -237,7 +237,7 @@ func TestSPRReorderCommit(t *testing.T) {
LocalBranch: "master",
}
var output bytes.Buffer
s := NewStackedPR(&cfg, githubmock, gitmock, &output, false)
s := NewStackedPR(&cfg, githubmock, gitmock, &output, false, false)

ctx := context.Background()

Expand Down Expand Up @@ -321,7 +321,7 @@ func TestSPRReorderCommit(t *testing.T) {

func TestParseLocalCommitStack(t *testing.T) {
var buffer bytes.Buffer
sd := NewStackedPR(&config.Config{}, nil, nil, &buffer, false)
sd := NewStackedPR(&config.Config{}, nil, nil, &buffer, false, false)
tests := []struct {
name string
inputCommitLog string
Expand Down

0 comments on commit b4546ff

Please sign in to comment.