Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Simplify commit list
Browse files Browse the repository at this point in the history
Simplify the diff command (changelog) by removing space-consuming extras
making it less readable to publish a changelog.

It removes the table format (headers and cells) and the commit author
leaving just the commit message and the hash.
  • Loading branch information
nahk committed Sep 14, 2018
1 parent 9326c78 commit f137055
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
16 changes: 7 additions & 9 deletions commands/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package commands

import (
"fmt"
"io"
"os"

"errors"

"github.com/blablacar/contactkey/context"
"github.com/blablacar/contactkey/services"
"github.com/olekukonko/tablewriter"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -28,10 +28,10 @@ func init() {
}

type Diff struct {
Env string
Service string
Context *context.Context
TableWriter *tablewriter.Table
Env string
Service string
Context *context.Context
Writer io.Writer
}

func (d Diff) execute() error {
Expand Down Expand Up @@ -74,11 +74,9 @@ func (d Diff) execute() error {
}

log.Println(fmt.Sprintf("Diff between %q(deployed) and %q(branch) \n", uniqueVersion, sha1))
d.TableWriter.SetHeader([]string{"Author", "sha1", "description"})
for _, change := range changes.Commits {
d.TableWriter.Append([]string{change.AuthorFullName, change.DisplayId, change.Title})
fmt.Fprintf(d.Writer, "- %s (%s)\n", change.Title, change.DisplayId)
}
d.TableWriter.Render()
}
return nil
}
Expand All @@ -87,5 +85,5 @@ func (d *Diff) fill(context *context.Context, service string, env string) {
d.Env = env
d.Service = service
d.Context = context
d.TableWriter = tablewriter.NewWriter(os.Stdout)
d.Writer = os.Stdout
}
8 changes: 2 additions & 6 deletions commands/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/blablacar/contactkey/context"
"github.com/blablacar/contactkey/services"
"github.com/olekukonko/tablewriter"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -45,9 +44,10 @@ func TestDiffExecute(t *testing.T) {
},
}

cmd.TableWriter = tablewriter.NewWriter(out)
cmd.Writer = out

cmd.execute()

if out.String() == "" {
t.Errorf("Unexpected stdout : %q", out)
}
Expand All @@ -57,10 +57,6 @@ func TestDiffExecute(t *testing.T) {
t.Error("Diff not found")
}

if !strings.Contains(out.String(), "AuthorFullName") {
t.Error("AuthorFullName not found")
}

if !strings.Contains(out.String(), "DisplayId") {
t.Error("DisplayId not found")
}
Expand Down

0 comments on commit f137055

Please sign in to comment.