Skip to content

Commit

Permalink
refactor: replace debug logger with apex logs
Browse files Browse the repository at this point in the history
Upgrades aevea/git to v3, which adds this support.

Additionally fixes random output for sections
  • Loading branch information
fallion committed Mar 7, 2021
1 parent 4aba748 commit ab8066d
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 62 deletions.
2 changes: 1 addition & 1 deletion cmd/get_commits.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
history "github.com/aevea/git/v2"
history "github.com/aevea/git/v3"
"github.com/go-git/go-git/v5/plumbing"
)

Expand Down
10 changes: 5 additions & 5 deletions cmd/get_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package cmd
import (
"testing"

history "github.com/aevea/git/v2"
history "github.com/aevea/git/v3"
"github.com/stretchr/testify/assert"
)

func TestGetCommitsDetachedTags(t *testing.T) {
repo, err := history.OpenGit("../testdata/detached_tag", nil)
repo, err := history.OpenGit("../testdata/detached_tag")

assert.NoError(t, err)

Expand All @@ -30,7 +30,7 @@ func TestGetCommitsDetachedTags(t *testing.T) {
}

func TestGetCommitsSingleBranch(t *testing.T) {
repo, err := history.OpenGit("../testdata/single_branch_tags", nil)
repo, err := history.OpenGit("../testdata/single_branch_tags")

assert.NoError(t, err)

Expand All @@ -52,7 +52,7 @@ func TestGetCommitsSingleBranch(t *testing.T) {
}

func TestGetCommitsReleaseCommit(t *testing.T) {
repo, err := history.OpenGit("../testdata/release_commit", nil)
repo, err := history.OpenGit("../testdata/release_commit")

assert.NoError(t, err)

Expand All @@ -76,7 +76,7 @@ func TestGetCommitsReleaseCommit(t *testing.T) {
}

func TestGetCommitsReleaseNonCompliantCommit(t *testing.T) {
repo, err := history.OpenGit("../testdata/release_noncompliant_commit", nil)
repo, err := history.OpenGit("../testdata/release_noncompliant_commit")

assert.NoError(t, err)

Expand Down
20 changes: 6 additions & 14 deletions cmd/log.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package cmd

import (
"io/ioutil"
"log"
"os"

history "github.com/aevea/git/v2"
history "github.com/aevea/git/v3"
"github.com/aevea/quoad"
"github.com/aevea/release-notary/internal/text"
"github.com/apex/log"
"github.com/spf13/cobra"
)

Expand All @@ -20,16 +17,11 @@ var logCmd = &cobra.Command{
Short: "Prints commits between two tags",
Long: "In default prints the commits between 2 tags. Can be overriden to specify exact commits.",
RunE: func(cmd *cobra.Command, args []string) error {
debugLogger := log.Logger{}
debugLogger.SetPrefix("[DEBUG] ")
debugLogger.SetOutput(os.Stdout)

if !Verbose {
debugLogger.SetOutput(ioutil.Discard)
debugLogger.SetPrefix("")
if Verbose {
log.SetLevel(log.DebugLevel)
}

repo, err := history.OpenGit(".", &debugLogger)
repo, err := history.OpenGit(".")

if err != nil {
return err
Expand Down Expand Up @@ -67,7 +59,7 @@ var logCmd = &cobra.Command{
)
}

log.Println(text.BuildHistory(parsedCommits))
log.Info(text.BuildHistory(parsedCommits))

return nil
},
Expand Down
22 changes: 7 additions & 15 deletions cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ package cmd

import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"strings"

history "github.com/aevea/git/v2"
history "github.com/aevea/git/v3"
"github.com/aevea/integrations"
"github.com/aevea/quoad"
"github.com/aevea/release-notary/internal/releaser"
"github.com/aevea/release-notary/internal/slack"
"github.com/aevea/release-notary/internal/text"
"github.com/apex/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -30,16 +27,11 @@ var publishCmd = &cobra.Command{
Short: "Publishes release notes",
Long: "",
RunE: func(cmd *cobra.Command, args []string) error {
debugLogger := log.Logger{}
debugLogger.SetPrefix("[DEBUG] ")
debugLogger.SetOutput(os.Stdout)

if !Verbose {
debugLogger.SetOutput(ioutil.Discard)
debugLogger.SetPrefix("")
if Verbose {
log.SetLevel(log.DebugLevel)
}

repo, err := history.OpenGit(".", &debugLogger)
repo, err := history.OpenGit(".")

if err != nil {
return err
Expand Down Expand Up @@ -82,7 +74,7 @@ var publishCmd = &cobra.Command{
}

if DryRun {
fmt.Println("my job here is done...")
log.Info("my job here is done...")
return nil
}

Expand Down Expand Up @@ -118,7 +110,7 @@ var publishCmd = &cobra.Command{

if viper.IsSet("GITLAB_TOKEN") {
if !viper.IsSet("CI_COMMIT_TAG") {
fmt.Print("Release Notary is not running on a tag or CI_COMMIT_TAG is not set")
log.Error("Release Notary is not running on a tag or CI_COMMIT_TAG is not set")
return nil
}

Expand Down
16 changes: 3 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package cmd

import (
"fmt"
"log"
"os"

"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "release-notary",
Short: "Commits up to last tag",
Short: "No root command available please check below",
Long: "",
Run: (func(cmd *cobra.Command, args []string) {
log.Println("hi")
}),
}

// Verbose is used to allow verbose/debug output for any given command
Expand All @@ -29,9 +22,6 @@ func init() {
}

// Execute just executes the rootCmd for Cobra
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
func Execute() error {
return rootCmd.Execute()
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module github.com/aevea/release-notary
go 1.13

require (
github.com/aevea/git/v2 v2.3.1
github.com/aevea/git/v3 v3.0.0
github.com/aevea/integrations v0.5.0
github.com/aevea/magefiles v0.0.0-20200424121010-0004d5a7a2fe
github.com/aevea/quoad v0.4.0
github.com/apex/log v1.9.0
github.com/go-git/go-git/v5 v5.2.0
github.com/json-iterator/go v1.1.10
github.com/magefile/mage v1.11.0
Expand Down
Loading

0 comments on commit ab8066d

Please sign in to comment.