-
Notifications
You must be signed in to change notification settings - Fork 0
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
♻️ Refactor Actions to accept email for GitLab #46
Merged
amadeu01
merged 9 commits into
add-support-email-from-pairs
from
ac-wt/accept-user-email-in-add-command
Oct 30, 2020
+152
−10
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c190697
:art: Using parenthesis on config function call
3675765
:sparkles: Introduce Storage module
aafc480
:truck: Move SystemBehaviour
04bebb2
:sparkles: Introduce StorageBehaviour
3ba155c
:wrench: Configure StorageBehaviour test mocks
ef46836
:recycle: Refactor Storage to return user data
7181aaa
:sparkles: Use Storage in Actions
d4b8af5
:art: Run mix format
3be0e2e
:rotating_light: Solve linter offence
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,3 +2,6 @@ import Config | |
|
||
config :git_pair, | ||
command_runner: GitPair.SystemMock | ||
|
||
config :git_pair, | ||
storage: GitPair.StorageMock |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule GitPair.StorageBehaviour do | ||
@moduledoc false | ||
|
||
@callback add(String.t()) :: {atom(), list()} | ||
@callback add(list(String.t())) :: {atom(), list()} | ||
end |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule GitPair.Storage do | ||
@git_config "config" | ||
@key "pair" | ||
@github_noreply_email "@users.noreply.github.com" | ||
|
||
def add([identifier, email]) do | ||
run(["--add", "#{@key}.#{identifier}.identifier", identifier]) | ||
run(["--add", "#{@key}.#{identifier}.email", email]) | ||
|
||
{:ok, | ||
[ | ||
identifier: identifier, | ||
email: email | ||
]} | ||
end | ||
|
||
def add(identifier) do | ||
add([identifier, identifier <> @github_noreply_email]) | ||
end | ||
|
||
def run(command) do | ||
runner().cmd("git", [@git_config | command]) | ||
end | ||
|
||
def runner() do | ||
Application.get_env(:git_pair, :command_runner, System) | ||
end | ||
end |
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 |
---|---|---|
|
@@ -4,19 +4,39 @@ defmodule GitPair.ActionsTest do | |
import Mox | ||
|
||
alias GitPair.Actions | ||
alias GitPair.StorageMock | ||
wevtimoteo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
alias GitPair.SystemMock | ||
|
||
setup :verify_on_exit! | ||
|
||
test ".add calls git config add command" do | ||
expect(SystemMock, :cmd, fn _cmd, _options -> | ||
{"", 0} | ||
test ".add calls git config add command passing username" do | ||
expect(StorageMock, :add, fn identifier -> | ||
{:ok, | ||
[ | ||
identifier: identifier, | ||
email: "[email protected]" | ||
]} | ||
end) | ||
|
||
{result, message} = Actions.add(["fake_user"]) | ||
|
||
assert result == :ok | ||
assert message == "User fake_user ([email protected]) added" | ||
end | ||
|
||
test ".add calls git config add command passing identifier and email" do | ||
expect(StorageMock, :add, fn [identifier, email] -> | ||
{:ok, | ||
[ | ||
identifier: identifier, | ||
email: "[email protected]" | ||
]} | ||
end) | ||
|
||
{result, message} = Actions.add(["fake-user"]) | ||
{result, message} = Actions.add(["fake_user", "[email protected]"]) | ||
|
||
assert result == :ok | ||
assert message == "User fake-user added" | ||
assert message == "User fake_user ([email protected]) added" | ||
end | ||
|
||
test ".rm calls git config unset command" do | ||
|
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
defmodule GitPair.StorageTest do | ||
use ExUnit.Case, async: true | ||
|
||
import Mox | ||
|
||
alias GitPair.Storage | ||
alias GitPair.SystemMock | ||
|
||
setup :verify_on_exit! | ||
|
||
describe "add/1" do | ||
test "store user with identifier with GitHub no-reply email" do | ||
command_prefix = ["config", "--add"] | ||
|
||
expect(SystemMock, :cmd, fn _cmd, options -> | ||
assert options == command_prefix ++ ["pair.fake_user.identifier", "fake_user"] | ||
{"", 0} | ||
end) | ||
|
||
expect(SystemMock, :cmd, fn _cmd, options -> | ||
assert options == | ||
command_prefix ++ ["pair.fake_user.email", "[email protected]"] | ||
|
||
{"", 0} | ||
end) | ||
|
||
{result, user_data} = Storage.add("fake_user") | ||
|
||
assert result == :ok | ||
|
||
assert user_data == [ | ||
identifier: "fake_user", | ||
email: "[email protected]" | ||
] | ||
end | ||
end | ||
|
||
describe "add/2" do | ||
test "stores user with identifier and email" do | ||
command_prefix = ["config", "--add"] | ||
|
||
expect(SystemMock, :cmd, fn _cmd, options -> | ||
assert options == command_prefix ++ ["pair.fake_user.identifier", "fake_user"] | ||
{"", 0} | ||
end) | ||
|
||
expect(SystemMock, :cmd, fn _cmd, options -> | ||
assert options == command_prefix ++ ["pair.fake_user.email", "[email protected]"] | ||
{"", 0} | ||
end) | ||
|
||
{result, user_data} = Storage.add(["fake_user", "[email protected]"]) | ||
|
||
assert result == :ok | ||
|
||
assert user_data == [ | ||
identifier: "fake_user", | ||
email: "[email protected]" | ||
] | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Mox.defmock(GitPair.SystemMock, for: GitPair.SystemBehaviour) | ||
Mox.defmock(GitPair.StorageMock, for: GitPair.StorageBehaviour) | ||
|
||
ExUnit.start() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Modules should have a @moduledoc tag.
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.
We will do it later.