Skip to content

Commit

Permalink
fix: skip running git diff if debug or lower is not set (#113)
Browse files Browse the repository at this point in the history
* fix: skip running git diff if debug or lower is not set

* test: added test for log-level=debug
lindell authored May 11, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b6c8667 commit 5189374
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/git/git.go
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ func (g *Git) Commit(commitAuthor *domain.CommitAuthor, commitMessage string) er
}

func (g *Git) logDiff(aHash, bHash plumbing.Hash) error {
if !log.IsLevelEnabled(log.GetLevel()) {
if !log.IsLevelEnabled(log.DebugLevel) {
return nil
}

33 changes: 33 additions & 0 deletions tests/table_test.go
Original file line number Diff line number Diff line change
@@ -367,6 +367,39 @@ Repositories with a successful run:
assert.Equal(t, "static-repo\ndynamic-repo\n:0\nCompletion ended with directive: ShellCompDirectiveDefault\n", runData.cmdOut)
},
},

{
name: "debug log",
vc: &vcmock.VersionController{
Repositories: []vcmock.Repository{
createRepo(t, "should-change", "i like apples"),
},
},
args: []string{
"run",
"--author-name", "Test Author",
"--author-email", "test@example.com",
"-B", "custom-branch-name",
"-m", "custom message",
"--log-level", "debug",
changerBinaryPath,
},
verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) {
require.Len(t, vcMock.PullRequests, 1)
assert.Equal(t, "custom-branch-name", vcMock.PullRequests[0].Head)
assert.Equal(t, "master", vcMock.PullRequests[0].Base)
assert.Equal(t, "custom message", vcMock.PullRequests[0].Title)

assert.Contains(t, runData.logOut, "Running on 1 repositories")
assert.Contains(t, runData.logOut, "Cloning and running script")
assert.Contains(t, runData.logOut, "Change done, creating pull request")

assert.Equal(t, `Repositories with a successful run:
should-change #1
`, runData.out)
assert.Contains(t, runData.logOut, `--- a/test.txt\n+++ b/test.txt\n@@ -1 +1 @@\n-i like apples\n\\ No newline at end of file\n+i like bananas\n\\ No newline at end of file\n`)
},
},
}

for _, test := range tests {

0 comments on commit 5189374

Please sign in to comment.