-
Notifications
You must be signed in to change notification settings - Fork 520
Add commit support for changelog subcommand #1014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -598,3 +607,35 @@ func (r *Repo) tagsForBranch(branch string) ([]string, error) { | |||
|
|||
return strings.Fields(status.Output()), nil | |||
} | |||
|
|||
// Add adds a file to the staging area of the repo | |||
func (r *Repo) Add(filename string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be useful to add tests for Add
and Commit
? Per usual, I would be fine with them coming in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sure, I added three more unit tests on top. I was not completely sure how to test a failing commit (should usually succeed), but I think this is not a critical path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/hold
cmd/krel/cmd/changelog.go
Outdated
func pushChanges(repo *git.Repo, branch string, tag semver.Version) error { | ||
if !rootOpts.nomock { | ||
logrus.Info("Using dry mode, which does not modify any remote content") | ||
repo.SetDry() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit strange to me that the repo is set to "dryrun mode" only when this more or less random function is called. I'd assume, that all the components are constructed or setup as early with settings like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I moved this part to happen directly after the CloneOrOpenDefaultGitHubRepoSSH()
.
pkg/git/git_test.go
Outdated
func TestCheckoutSuccess(t *testing.T) { | ||
testRepo := newTestRepo(t) | ||
defer testRepo.cleanup(t) | ||
|
||
err := testRepo.sut.Checkout(Master, testRepo.testFileName) | ||
require.Nil(t, err) | ||
} | ||
|
||
func TestCheckoutFailureWrongRevision(t *testing.T) { | ||
testRepo := newTestRepo(t) | ||
defer testRepo.cleanup(t) | ||
|
||
err := testRepo.sut.Checkout("wrong") | ||
require.NotNil(t, err) | ||
} | ||
|
||
func TestAddSuccess(t *testing.T) { | ||
testRepo := newTestRepo(t) | ||
defer testRepo.cleanup(t) | ||
|
||
f, err := ioutil.TempFile(testRepo.sut.Dir(), "test") | ||
require.Nil(t, err) | ||
require.Nil(t, f.Close()) | ||
|
||
err = testRepo.sut.Add(filepath.Base(f.Name())) | ||
require.Nil(t, err) | ||
} | ||
|
||
func TestAddFailureWrongPath(t *testing.T) { | ||
testRepo := newTestRepo(t) | ||
defer testRepo.cleanup(t) | ||
|
||
err := testRepo.sut.Add("wrong") | ||
require.NotNil(t, err) | ||
} | ||
|
||
func TestCommitSuccess(t *testing.T) { | ||
testRepo := newTestRepo(t) | ||
defer testRepo.cleanup(t) | ||
|
||
err := testRepo.sut.Commit("msg") | ||
require.Nil(t, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, many of those don't really test much. If I'd change e.g. the commit method to
func (r *Repo) Commit(_ string) error {
return nil
}
the tests would still pass.
I suggest to either mock stuff you wrap (e.g. the "inner" git.Repository
) and assert that certain methods have been called (with certain args, ...) (e.g. the Worktree
or the worktree.Commit
methods). Alternatively, as those tests are already integration-y tests anyway, assert on the expected end-state (check that a git object has actually been created)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point. Mocking would be a bit hard because git.Repository
aka inner
is a structure and not a public interface we can mock easily. I'll update the tests to test the end-state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Probably not for this PR, but we are heading in an interesting direction!)
Mocking would be a bit hard because git.Repository aka inner is a structure and not a public interface
Right now, inner
is a struct. But what if you decided it should be an interface (currently) with the methods ResolveRevision
, Tags
, Remote
, Worktree
, CommitObject
, Head
? 😎💥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this sounds good, I can follow up on that 👍
The next step after this PR would be to write some kind of integration test for the tool, probably side-by-side to the executable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My follow up on this: #1017
This adds the ability to modify the master branch and the release branch to contain the updated markdown changelog. Signed-off-by: Sascha Grunert <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cpanato, hasheddan, saschagrunert The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This looks good to go! |
This adds the ability to modify the master branch and the release branch
to contain the updated markdown changelog. The output dir is now
obsolete since we're directly writing into the repo for the markdown file
and to the local working path for the HTML file.
Demo: