-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow providing commit author via config.yaml (#8)
- Loading branch information
Showing
5 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,8 @@ APIs used to retrieve the upstream versions can have some limitations for unauth | |
GitHub and GitLab APIs in particular use rate limiting, so requests made by `bumper` could fail after a few usages or when bumping a lot of packages. | ||
You can configure `bumper` to use your API keys to avoid those limits. | ||
|
||
It's also possible to configure the value used as the commit author. | ||
|
||
Configuration file is expected to be present at `$XDG_CONFIG_HOME/bumper/config.yaml` or `$HOME/.config/bumper/config.yaml`. | ||
The format is as follows: | ||
```yaml | ||
|
@@ -88,6 +90,8 @@ check: | |
apiKeys: | ||
gitlab.com: gitlab_com_api_key | ||
other.gitlab.instance: other_api_key | ||
commit: | ||
author: John Doe <[email protected]> | ||
``` | ||
**Warning**: All configuration fields are optional and the file isn't checked for additional keys! | ||
This means that `bumper` will not fail if you make a typo or other mistake. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,20 @@ package bumper | |
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/bcyran/bumper/internal/testutils" | ||
"github.com/bcyran/bumper/pack" | ||
"github.com/bcyran/bumper/upstream" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/config" | ||
) | ||
|
||
var ( | ||
commitConfigProvider, _ = config.NewYAML(config.Source(strings.NewReader("{empty: {}, commit: {author: John Doe <[email protected]>}}"))) | ||
emptyCommitConfig = commitConfigProvider.Get("empty") | ||
commitConfigWithAuthor = commitConfigProvider.Get("commit") | ||
) | ||
|
||
func TestCommitAction_Success(t *testing.T) { | ||
|
@@ -27,7 +35,7 @@ func TestCommitAction_Success(t *testing.T) { | |
fakeCommandRunner, commandRuns := testutils.MakeFakeCommandRunner(&commandRetvals) | ||
|
||
// execute the action with our mocked command runner | ||
action := NewCommitAction(fakeCommandRunner) | ||
action := NewCommitAction(fakeCommandRunner, emptyCommitConfig) | ||
result := action.Execute(pkg) | ||
|
||
// result assertions | ||
|
@@ -54,6 +62,38 @@ func TestCommitAction_Success(t *testing.T) { | |
assert.Equal(t, expectedCommitCommand, (*commandRuns)[2]) | ||
} | ||
|
||
func TestCommitAction_SuccessWithAuthor(t *testing.T) { | ||
// our Package struct | ||
pkg := &pack.Package{ | ||
Path: "/foo/bar/baz", | ||
UpstreamVersion: upstream.Version("1.2.3"), | ||
IsOutdated: true, | ||
} | ||
|
||
// mock return values for commands | ||
commandRetvals := []testutils.CommandRunnerRetval{ | ||
{Stdout: []byte(" M .SRCINFO\x00 M PKGBUILD\x00"), Err: nil}, // git status | ||
{Stdout: []byte{}, Err: nil}, // git add | ||
{Stdout: []byte{}, Err: nil}, // git commit | ||
} | ||
fakeCommandRunner, commandRuns := testutils.MakeFakeCommandRunner(&commandRetvals) | ||
|
||
// execute the action with our mocked command runner | ||
action := NewCommitAction(fakeCommandRunner, commitConfigWithAuthor) | ||
result := action.Execute(pkg) | ||
|
||
// result assertions | ||
assert.Equal(t, ActionSuccessStatus, result.GetStatus()) | ||
assert.Equal(t, "committed", result.String()) | ||
|
||
// expect valid git commit command | ||
expectedCommitMessage := fmt.Sprintf("Bump version to %s", pkg.UpstreamVersion) | ||
expectedCommitCommand := testutils.CommandRunnerParams{ | ||
Cwd: pkg.Path, Command: "git", Args: []string{"commit", "--message", expectedCommitMessage, "--author", "John Doe <[email protected]>"}, | ||
} | ||
assert.Equal(t, expectedCommitCommand, (*commandRuns)[2]) | ||
} | ||
|
||
func TestCommitAction_Skip(t *testing.T) { | ||
// our Package struct | ||
pkg := &pack.Package{ | ||
|
@@ -69,7 +109,7 @@ func TestCommitAction_Skip(t *testing.T) { | |
fakeCommandRunner, _ := testutils.MakeFakeCommandRunner(&commandRetvals) | ||
|
||
// execute the action with our mocked command runner | ||
action := NewCommitAction(fakeCommandRunner) | ||
action := NewCommitAction(fakeCommandRunner, emptyCommitConfig) | ||
result := action.Execute(pkg) | ||
|
||
assert.Equal(t, ActionSkippedStatus, result.GetStatus()) | ||
|
@@ -91,7 +131,7 @@ func TestCommitAction_Fail(t *testing.T) { | |
fakeCommandRunner, _ := testutils.MakeFakeCommandRunner(&commandRetvals) | ||
|
||
// execute the action with our mocked command runner | ||
action := NewCommitAction(fakeCommandRunner) | ||
action := NewCommitAction(fakeCommandRunner, emptyCommitConfig) | ||
result := action.Execute(pkg) | ||
|
||
assert.Equal(t, ActionFailedStatus, result.GetStatus()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters