Skip to content

Commit 7b54ffb

Browse files
authored
Merge pull request #8 from devops-kung-fu/vaporize
fix: Vaporizes tailog and fixes pre-mature exit
2 parents 24b631f + 87d4838 commit 7b54ffb

File tree

9 files changed

+100
-61
lines changed

9 files changed

+100
-61
lines changed

Diff for: .vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"afero"
4+
]
5+
}

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ The current SBoM for ```hinge``` is available [here](hinge-sbom.json).
6161

6262
## Credits
6363

64-
A big thank-you to our friends at [Freepik](https://www.freepik.com) for the ```hinge``` logo.
64+
A big thank-you to our friends at [Freepik](https://www.freepik.com) for the ```hinge``` logo.

Diff for: cmd/root.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77

88
"github.com/devops-kung-fu/hinge/lib"
9-
"github.com/devops-kung-fu/tailog"
109
"github.com/gookit/color"
1110
"github.com/spf13/cobra"
1211
)
@@ -30,22 +29,15 @@ var (
3029
color.Style{color.FgRed, color.OpBold}.Println("Please provide the path to the repository.")
3130
fmt.Println()
3231
_ = cmd.Usage()
32+
os.Exit(1)
3333
} else if len(args) > 1 {
3434
color.Style{color.FgRed, color.OpBold}.Println("Only one path is allowed.")
3535
fmt.Println()
3636
_ = cmd.Usage()
37+
os.Exit(1)
3738
}
38-
os.Exit(1)
3939
},
4040
Run: func(cmd *cobra.Command, args []string) {
41-
tailog := tailog.Tailog(tailog.DEBUG)
42-
switch {
43-
case trace:
44-
_ = tailog.ChangeGlobalLevel(0)
45-
case debug:
46-
_ = tailog.ChangeGlobalLevel(1)
47-
}
48-
4941
repoPath := args[0]
5042
schedule := lib.Schedule{
5143
Interval: "daily",
@@ -63,7 +55,7 @@ var (
6355
case interval == "monthly":
6456
schedule.Interval = interval
6557
}
66-
lib.Generator(tailog, repoPath, verbose, schedule)
58+
lib.Generator(repoPath, verbose, schedule)
6759

6860
},
6961
}

Diff for: go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ module github.com/devops-kung-fu/hinge
33
go 1.16
44

55
require (
6-
github.com/devops-kung-fu/tailog v0.1.7
76
github.com/gookit/color v1.4.2
87
github.com/spf13/afero v1.6.0
98
github.com/spf13/cobra v1.2.1
9+
github.com/stretchr/testify v1.7.0
10+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
1011
golang.org/x/text v0.3.6 // indirect
1112
gopkg.in/yaml.v2 v2.4.0
1213
)

Diff for: go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
5959
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6060
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
6161
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
62-
github.com/devops-kung-fu/tailog v0.1.7 h1:N1eM8c9lwBbOpeeFlPewdKjAn8xAHQWT8ymkCSiYhdE=
63-
github.com/devops-kung-fu/tailog v0.1.7/go.mod h1:ll6LcF1jIJv7s22Vub1kd3VhTs7IsWwEMXTkTM+m7SI=
6462
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
6563
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
6664
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=

Diff for: hinge-sbom.json

+7-34
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"bomFormat": "CycloneDX",
33
"specVersion": "1.2",
4-
"serialNumber": "urn:uuid:c9e967ef-9015-4f27-897b-9011b00a203d",
4+
"serialNumber": "urn:uuid:7206b67d-bb64-4fba-bea1-c4fb3c74145c",
55
"version": 1,
66
"metadata": {
7-
"timestamp": "2021-07-14T14:32:52-06:00",
7+
"timestamp": "2021-07-22T20:58:27-06:00",
88
"tools": [
99
{
1010
"vendor": "CycloneDX",
@@ -31,11 +31,11 @@
3131
}
3232
],
3333
"component": {
34-
"bom-ref": "pkg:golang/github.com/devops-kung-fu/[email protected]20210714142452-6a754f3bc11f",
34+
"bom-ref": "pkg:golang/github.com/devops-kung-fu/[email protected]20210714162810-e7d7d897d5dd",
3535
"type": "application",
3636
"name": "github.com/devops-kung-fu/hinge",
37-
"version": "v0.0.0-20210714142452-6a754f3bc11f",
38-
"purl": "pkg:golang/github.com/devops-kung-fu/[email protected]20210714142452-6a754f3bc11f",
37+
"version": "v0.0.0-20210714162810-e7d7d897d5dd",
38+
"purl": "pkg:golang/github.com/devops-kung-fu/[email protected]20210714162810-e7d7d897d5dd",
3939
"externalReferences": [
4040
{
4141
"url": "https://github.com/devops-kung-fu/hinge",
@@ -45,26 +45,6 @@
4545
}
4646
},
4747
"components": [
48-
{
49-
"bom-ref": "pkg:golang/github.com/devops-kung-fu/[email protected]",
50-
"type": "library",
51-
"name": "github.com/devops-kung-fu/tailog",
52-
"version": "v0.1.7",
53-
"scope": "required",
54-
"hashes": [
55-
{
56-
"alg": "SHA-256",
57-
"content": "37578cf1cf65c016cea5e78594f7b074a8c09fcc401d0593f329a409289885d1"
58-
}
59-
],
60-
"purl": "pkg:golang/github.com/devops-kung-fu/[email protected]",
61-
"externalReferences": [
62-
{
63-
"url": "https://github.com/devops-kung-fu/tailog",
64-
"type": "vcs"
65-
}
66-
]
67-
},
6848
{
6949
"bom-ref": "pkg:golang/github.com/gookit/[email protected]",
7050
"type": "library",
@@ -258,13 +238,6 @@
258238
}
259239
],
260240
"dependencies": [
261-
{
262-
"ref": "pkg:golang/github.com/devops-kung-fu/[email protected]",
263-
"dependsOn": [
264-
"pkg:golang/github.com/gookit/[email protected]",
265-
"pkg:golang/golang.org/x/[email protected]"
266-
]
267-
},
268241
{
269242
"ref": "pkg:golang/github.com/gookit/[email protected]",
270243
"dependsOn": [
@@ -305,12 +278,12 @@
305278
"ref": "pkg:golang/gopkg.in/[email protected]"
306279
},
307280
{
308-
"ref": "pkg:golang/github.com/devops-kung-fu/[email protected]20210714142452-6a754f3bc11f",
281+
"ref": "pkg:golang/github.com/devops-kung-fu/[email protected]20210714162810-e7d7d897d5dd",
309282
"dependsOn": [
310-
"pkg:golang/github.com/devops-kung-fu/[email protected]",
311283
"pkg:golang/github.com/gookit/[email protected]",
312284
"pkg:golang/github.com/spf13/[email protected]",
313285
"pkg:golang/github.com/spf13/[email protected]",
286+
"pkg:golang/golang.org/x/[email protected]",
314287
"pkg:golang/golang.org/x/[email protected]",
315288
"pkg:golang/gopkg.in/[email protected]",
316289
"pkg:golang/[email protected]"

Diff for: lib/error.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package lib
2+
3+
import "log"
4+
5+
//IsError Checks to see if an error exists, and if so
6+
//writes it to the log with the provided prefix
7+
func IsError(err error, prefix string) error {
8+
if err != nil {
9+
log.Printf("%v: %v", prefix, err)
10+
}
11+
return err
12+
}
13+
14+
//IsErrorBool Checks to see if an error exists, and if so
15+
//returns true after writing the error to the log with the provided prefix
16+
func IsErrorBool(err error, prefix string) (b bool) {
17+
if err != nil {
18+
log.Printf("%v: %v", prefix, err)
19+
b = true
20+
}
21+
return
22+
}
23+
24+
//IfErrorLog Checks to see if an error exists, and if so
25+
//simply writes it to the log.
26+
func IfErrorLog(err error, prefix string) {
27+
if err != nil {
28+
log.Printf("%v: %v", prefix, err)
29+
}
30+
}

Diff for: lib/error_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package lib
2+
3+
import (
4+
"bytes"
5+
"errors"
6+
"log"
7+
"os"
8+
"strings"
9+
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestIsError(t *testing.T) {
15+
output := captureOutput(func() {
16+
IsError(errors.New("Test Error"), "[TEST]")
17+
})
18+
19+
if output.Len() == 0 {
20+
assert.GreaterOrEqual(t, output.Len(), 0, "No information logged to STDOUT")
21+
assert.GreaterOrEqual(t, strings.Count(output.String(), "\n"), 1, "Expected only a single line of log output")
22+
}
23+
}
24+
25+
func TestIsErrorBool(t *testing.T) {
26+
output := captureOutput(func() {
27+
IsErrorBool(errors.New("Test Error"), "[TEST]")
28+
})
29+
30+
assert.GreaterOrEqual(t, output.Len(), 0, "No information logged to STDOUT")
31+
assert.GreaterOrEqual(t, strings.Count(output.String(), "\n"), 1, "Expected only a single line of log output")
32+
}
33+
34+
func TestIfErrorLog(t *testing.T) {
35+
output := captureOutput(func() {
36+
IfErrorLog(errors.New("Test Error"), "[TEST]")
37+
})
38+
39+
assert.GreaterOrEqual(t, output.Len(), 0, "No information logged to STDOUT")
40+
assert.GreaterOrEqual(t, strings.Count(output.String(), "\n"), 1, "Expected only a single line of log output")
41+
}
42+
43+
func captureOutput(f func()) bytes.Buffer {
44+
var buf bytes.Buffer
45+
log.SetOutput(&buf)
46+
f()
47+
log.SetOutput(os.Stderr)
48+
return buf
49+
}

Diff for: lib/generate.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ import (
66
"path"
77
"strings"
88

9-
"github.com/devops-kung-fu/tailog"
109
"github.com/gookit/color"
1110
"github.com/spf13/afero"
1211
"gopkg.in/yaml.v2"
1312
)
1413

1514
// Generator - generates the dependabot.yml in the specified repo path.
16-
func Generator(logger *tailog.Logger, repoPath string, verbose bool, schedule Schedule) {
17-
logger.Trace("Setting up filesystem.")
15+
func Generator(repoPath string, verbose bool, schedule Schedule) {
1816
fs := afero.NewOsFs()
19-
logger.Debug("Getting platform ecosystems.")
2017
bundler := platform(fs, `Gemfile|Gemfile\.lock`, repoPath, "bundler", schedule)
2118
cargo := platform(fs, `Cargo\.toml`, repoPath, "cargo", schedule)
2219
composer := platform(fs, `composer\.json`, repoPath, "composer", schedule)
@@ -40,27 +37,21 @@ func Generator(logger *tailog.Logger, repoPath string, verbose bool, schedule Sc
4037
terraform := platform(fs, `(.*)\.tf`, repoPath, "terraform", schedule)
4138
color.Style{color.FgLightBlue}.Print(" ■ ")
4239
fmt.Println("Got platform ecosystems")
43-
// logger.Info("Got platform ecosystems.")
44-
// logger.Debug("Begin joining updates.")
4540
updates := joinUpdates(bundler, cargo, composer, docker, elm, gitsubmodules, githubActual, gomod, gradle, hexmix, maven, npm, nuget, pip, terraform)
4641
color.Style{color.FgLightBlue}.Print(" ■ ")
4742
fmt.Println("Joined all updates")
48-
// logger.Info("Joined all updates.")
49-
logger.Debug("Building configuration.")
5043
config := Configuration{
5144
Version: 2,
5245
Updates: updates,
5346
}
5447
color.Style{color.FgLightBlue}.Print(" ■ ")
5548
fmt.Println("Configuration complete")
56-
//logger.Info("Configuration complete.")
5749
if verbose {
58-
logger.Trace("Output configuration to standard output.")
5950
outputConfig(config)
6051
}
61-
logger.Debug("Writing configuration.")
6252
writeConfig(fs, repoPath, config)
63-
//logger.Info("Done.")
53+
color.Style{color.FgGreen}.Print(" ■ ")
54+
fmt.Println("Updated .github/dependabot.yml")
6455
color.Style{color.FgGreen}.Print(" ■ ")
6556
fmt.Println("Done!")
6657
}

0 commit comments

Comments
 (0)