Skip to content
This repository was archived by the owner on Mar 31, 2022. It is now read-only.

Commit 007869a

Browse files
author
Matt Royal
committed
Merge pull request #24 from zrob/custom-email
Add ability to use a custom email address per user
2 parents 3db777c + 3668fc7 commit 007869a

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

Diff for: Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
pivotal_git_scripts (1.2.0)
4+
pivotal_git_scripts (1.3.0)
55

66
GEM
77
remote: http://rubygems.org/

Diff for: lib/pivotal_git_scripts/git_pair.rb

+35-5
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ def commit(argv)
5858
end
5959

6060
config = read_pairs_config
61-
author_names, email_ids = extract_author_names_and_email_ids_from_config(config, current_pair_initials)
61+
author_details = extract_author_details_from_config(config, current_pair_initials)
62+
author_names = author_details.keys.map { |i| author_details[i][:name] }
6263
authors = pair_names(author_names)
63-
author_email = random_author_email(email_ids, config['email'])
64+
author_email = random_author_email(author_details)
6465
puts "Committing under #{author_email}"
6566
passthrough_args = argv.map{|arg| "'#{arg}'"}.join(' ')
6667
env_variables = "GIT_AUTHOR_NAME='#{authors}' GIT_AUTHOR_EMAIL='#{author_email}' GIT_COMMITTER_NAME='#{authors}' GIT_COMMITTER_EMAIL='#{author_email}'"
@@ -103,6 +104,9 @@ def parse_cli_options(argv)
103104
domain: pivotallabs.com
104105
# no_solo_prefix: true
105106
#global: true
107+
# include the following section to set custom email addresses for users
108+
#email_addresses:
109+
106110
107111
108112
By default this affects the current project (.git/config).<br/>
@@ -168,9 +172,9 @@ def build_email(emails, config)
168172
end
169173
end
170174

171-
def random_author_email(email_ids, config)
172-
author_id = email_ids.sample
173-
"#{author_id}@#{config['domain']}"
175+
def random_author_email(author_details)
176+
author_id = author_details.keys.sample
177+
author_details[author_id][:email]
174178
end
175179

176180
def set_git_config(global, options)
@@ -205,6 +209,32 @@ def no_email(config)
205209
!config.key? 'email'
206210
end
207211

212+
def extract_author_details_from_config(config, initials)
213+
details = {}
214+
215+
initials.each do |i|
216+
info = read_author_info_from_config(config, [i]).first
217+
218+
full_name, email_id = info.split(";").map(&:strip)
219+
email_id ||= full_name.split(' ').first.downcase
220+
221+
email = read_custom_email_address_from_config(config, i)
222+
email ||= "#{email_id}@#{config['email']['domain']}"
223+
224+
details[i] = {
225+
:name => full_name,
226+
:email => email
227+
}
228+
end
229+
230+
details
231+
end
232+
233+
def read_custom_email_address_from_config(config, initial)
234+
return nil unless config['email_addresses']
235+
return config['email_addresses'][initial.downcase]
236+
end
237+
208238
private
209239

210240
def pair_names(author_names)

Diff for: lib/pivotal_git_scripts/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module PivotalGitScripts
2-
VERSION = "1.2.0"
2+
VERSION = "1.3.0"
33
end

Diff for: spec/cli_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ def git_config_value(name, global = false)
291291
email:
292292
prefix: the-pair
293293
domain: the-host.com
294+
295+
email_addresses:
296+
294297
YAML
295298
end
296299

@@ -377,6 +380,20 @@ def committer_email_of_last_commit
377380
%w([email protected] [email protected]).should include(committer_email_of_last_commit)
378381
end
379382
end
383+
384+
context 'when one of the pair has a custom email address' do
385+
before do
386+
run 'git pair ab bc'
387+
end
388+
389+
it 'uses that email address' do
390+
emails = 6.times.map do
391+
git_pair_commit
392+
author_email_of_last_commit
393+
end.uniq
394+
emails.should =~ ['[email protected]', '[email protected]']
395+
end
396+
end
380397
end
381398

382399
context 'when no pair has been set' do

0 commit comments

Comments
 (0)