Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/git_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def checkout_fresh_branch(branch:, base:)
# Returns true iff a commit was actually created; false when
# bin/importmap pin was a no-op and there is nothing to commit.
def commit_changes(message:)
@repo.config("user.name", @author_name)
@repo.config("user.email", @author_email)
@repo.add(["config/importmap.rb", "vendor/javascript"])
@repo.commit(message, author: "#{@author_name} <#{@author_email}>")
@repo.commit(message)
true
rescue Git::FailedError => e
return false if e.result.stderr.to_s.include?("nothing to commit")
Expand Down
10 changes: 7 additions & 3 deletions test/git_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class GitClientTest < Minitest::Test

AUTHOR_NAME = "Test Bot"
AUTHOR_EMAIL = "bot@example.com"
AUTHOR_STRING = "Test Bot <bot@example.com>"

def setup
@repo = Minitest::Mock.new
Expand Down Expand Up @@ -44,14 +43,17 @@ def test_checkout_fresh_branch_resets_existing_branch_to_base

def test_commit_changes_stages_and_commits_returning_true
@repo.expect(:add, nil, [["config/importmap.rb", "vendor/javascript"]])
@repo.expect(:commit, nil, ["Bump lodash from 4.17.20 to 4.17.21"],
author: AUTHOR_STRING)
@repo.expect(:config, nil, ["user.name", AUTHOR_NAME])
@repo.expect(:config, nil, ["user.email", AUTHOR_EMAIL])
@repo.expect(:commit, nil, ["Bump lodash from 4.17.20 to 4.17.21"])

assert_equal true, @client.commit_changes(message: "Bump lodash from 4.17.20 to 4.17.21")
end

def test_commit_changes_returns_false_when_nothing_to_commit
@repo.expect(:add, nil, [["config/importmap.rb", "vendor/javascript"]])
@repo.expect(:config, nil, ["user.name", AUTHOR_NAME])
@repo.expect(:config, nil, ["user.email", AUTHOR_EMAIL])
@repo.expect(:commit, nil) do |_msg, **_opts|
raise git_failed_error("nothing to commit, working tree clean")
end
Expand All @@ -61,6 +63,8 @@ def test_commit_changes_returns_false_when_nothing_to_commit

def test_commit_changes_re_raises_unexpected_git_errors
@repo.expect(:add, nil, [["config/importmap.rb", "vendor/javascript"]])
@repo.expect(:config, nil, ["user.name", AUTHOR_NAME])
@repo.expect(:config, nil, ["user.email", AUTHOR_EMAIL])
@repo.expect(:commit, nil) do |_msg, **_opts|
raise git_failed_error("lock file exists")
end
Expand Down