pair-salad 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/pair +0 -1
  2. data/lib/pair_salad_runner.rb +81 -0
  3. metadata +5 -5
  4. data/Rakefile +0 -2
data/bin/pair CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- $: << File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
3
2
 
4
3
  require "pair_salad_runner"
5
4
 
@@ -0,0 +1,81 @@
1
+ class PairSaladRunner
2
+ EMAIL_PREFIX = "engineers"
3
+ EMAIL_SUFFIX = "@streamsend.com"
4
+
5
+ def run(args)
6
+ @pair_initials = args.sort
7
+
8
+ check_for_git_directory
9
+ check_for_authors_file
10
+
11
+ @authors = parse_authors_from_file
12
+
13
+ if @authors.any?
14
+ git_username = build_username
15
+ system("git config user.name '#{git_username}'")
16
+
17
+ git_email_address = build_email_address
18
+ system("git config user.email '#{git_email_address}'")
19
+
20
+ puts <<-message
21
+ user.name = #{git_username}
22
+ user.email = #{git_email_address}
23
+ message
24
+ else
25
+ system("git config --unset user.name")
26
+ system("git config --unset user.email")
27
+
28
+ puts "Unset user.name and user.email"
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def check_for_git_directory
35
+ unless File.exists?(".git")
36
+ puts "This doesn't look like a git repository."
37
+ exit 1
38
+ end
39
+ end
40
+
41
+ def check_for_authors_file
42
+ unless File.exists?(".authors")
43
+ puts <<-message
44
+ You do not have an .authors file in the repository.
45
+ Repository needs a file named .authors in the following format:
46
+ ck Clark Kent
47
+ bw Bruce Wayne
48
+ pp Peter Parker
49
+ message
50
+
51
+ exit 1
52
+ end
53
+ end
54
+
55
+ def parse_authors_from_file
56
+ authors = {}
57
+ File.open('.authors').each_line do |line|
58
+ initials, name = line.match(/^(\w+)\s+(.*)$/).captures
59
+ if @pair_initials.include? initials
60
+ authors[initials] = name
61
+ end
62
+ end
63
+ authors
64
+ end
65
+
66
+ def build_username
67
+ author_name = ""
68
+ @pair_initials.each_with_index do |initials, index|
69
+ if index > 0
70
+ author_name << " and #{@authors[initials]}"
71
+ else
72
+ author_name << @authors[initials]
73
+ end
74
+ end
75
+ author_name
76
+ end
77
+
78
+ def build_email_address
79
+ "#{EMAIL_PREFIX}+#{@pair_initials.join("+")}#{EMAIL_SUFFIX}"
80
+ end
81
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pair-salad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: Git utility used when pair programming.
46
+ description: https://github.com/salbertson/pair-salad
47
47
  email:
48
48
  - salbertson@streamsend.com
49
49
  executables:
@@ -51,10 +51,10 @@ executables:
51
51
  extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
- - Rakefile
55
54
  - README.md
55
+ - lib/pair_salad_runner.rb
56
56
  - bin/pair
57
- homepage: ''
57
+ homepage: https://github.com/salbertson/pair-salad
58
58
  licenses: []
59
59
  post_install_message:
60
60
  rdoc_options: []
@@ -77,5 +77,5 @@ rubyforge_project:
77
77
  rubygems_version: 1.8.24
78
78
  signing_key:
79
79
  specification_version: 3
80
- summary: Git utility used when pair programming.
80
+ summary: Handy gem for adding multiple authors to git commits.
81
81
  test_files: []
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"