pair-up 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c85ff4124c27a9d99a65ba8d69c7bf7ae3b9b4a
4
+ data.tar.gz: 8ea00b9f79aa675a2f1d0b001de8dda9b3289ff5
5
+ SHA512:
6
+ metadata.gz: 8e2501b0b20763e21a031df15d85c681710698c0646ad1ba29c55dffb77a022f95bf3c93dcf2e98d5309a23d716b3230d64a9665204c7f05262e98849a88b1e3
7
+ data.tar.gz: 3be127eb8ec810b9b1916dc8cdf0fd686d1895c012b0b1e09431cfaf9e4dc94c0fb9742ce6ac023b8d2b1d874fef4291f4eeef7fa607cfd07c7cf41557bb34e8
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'highline', '~>1.6.2'
4
+ gem 'rake'
5
+ gem 'rspec', '~> 3.2.0'
6
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ coderay (1.0.9)
5
+ diff-lcs (1.2.5)
6
+ highline (1.6.20)
7
+ method_source (0.8.2)
8
+ pry (0.9.12.2)
9
+ coderay (~> 1.0.5)
10
+ method_source (~> 0.8)
11
+ slop (~> 3.4)
12
+ rake (10.1.0)
13
+ rspec (3.2.0)
14
+ rspec-core (~> 3.2.0)
15
+ rspec-expectations (~> 3.2.0)
16
+ rspec-mocks (~> 3.2.0)
17
+ rspec-core (3.2.0)
18
+ rspec-support (~> 3.2.0)
19
+ rspec-expectations (3.2.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.2.0)
22
+ rspec-mocks (3.2.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.2.0)
25
+ rspec-support (3.2.1)
26
+ slop (3.4.6)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ highline (~> 1.6.2)
33
+ pry
34
+ rake
35
+ rspec (~> 3.2.0)
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2009-2011 Rogelio J. Samour
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ Git Pair
2
+ =====
3
+ by Andre Helberg (@A-Helberg)
4
+
5
+ [![Build Status](https://travis-ci.org/A-Helberg/git-pair.svg)](https://travis-ci.org/A-Helberg/git-pair)
6
+
7
+ Description:
8
+ -----------
9
+
10
+ Git Pair allows developers to be jointly credited when Pair Programming and using Git.
11
+
12
+ Features:
13
+ --------
14
+
15
+ * Persists pair between different terminal instances.
16
+ * Can be used in OSX GUI applications ( after restarting the application )
17
+ * Allows you to expire the pair information in N hours. e.g. git pair --expire 8 fry leela
18
+
19
+ Installation & Usage:
20
+ ----------
21
+ Install the gem and add the setup to the end of your zshrc or bashrc file
22
+ ```shell
23
+ $ gem install git-pair
24
+ ```
25
+
26
+ ```shell
27
+ $ pair --setup >> ~/.zshrc
28
+ ```
29
+
30
+ Restart your terminal.
31
+
32
+ To pair with someone replace the following names with your github names
33
+ ```shell
34
+ $ pair A-Helberg aleciafb
35
+ ```
36
+
37
+ Now just commit as you usually would. If you use a gui application on OSX, remember to restart it when you setupa new pair or switch pairs for it to take effect. The first person will be used as the author and the second person as the committer.
38
+
39
+ To switch the pairs around run:
40
+ ``` shell
41
+ $ pair --switch
42
+ ```
43
+
44
+ Don't forget to unpair when you are done:
45
+ ``` shell
46
+ $ pair -u
47
+ ```
48
+
49
+ For some help and a complete list of features:
50
+ ```shell
51
+ $ pair -h
52
+ ```
53
+
54
+ Install:
55
+ -------
56
+
57
+ ``` shell
58
+ gem install git-pair
59
+ ```
60
+
61
+ ``` shell
62
+ pair --setup
63
+ ```
64
+
65
+ * this prints out the necessary shell function and aliases you need to add to your ~/.bashrc or ~/.zshrc
66
+ - eg. `pair --setup >> ~/.zshrc`
67
+ * Or copy/paste [the code](lib/git-pair/git-pair.sh) into your ~/.bashrc or ~/.zshrc
68
+ * As another option, copy/symlink the script to a separate file (e.g. `~/.bash/git-pair.sh` or `/etc/profile.d/git-pair.sh`) and source it. You can get the path using `pair --setup-path`.
69
+ * Restart your terminal.
70
+
71
+ Development:
72
+ -----------
73
+
74
+ * Fork git-pair
75
+ * Add tests and code for your feature
76
+ * Create a pull request
77
+ * Double-check TravisCI to make sure all tests pass
78
+
79
+ Requirements:
80
+ ------------
81
+
82
+ * Git, HighLine
83
+
84
+ Acknowledgements:
85
+ ----------------
86
+
87
+ * Rogelio J. Samour (http://blog.therubymug.com)
88
+ * Stephen Caudill
89
+ * Les Hill
90
+ * Tim Pope
91
+
92
+ License:
93
+ -------
94
+ Released under the MIT License. See the [LICENSE][license] file for further details.
95
+
96
+ [license]: https://github.com/A-Helberg/git-pair/blob/master/LICENSE.md
data/Rakefile ADDED
@@ -0,0 +1,122 @@
1
+ #############################################################################
2
+ #
3
+ # Helper functions
4
+ #
5
+ #############################################################################
6
+
7
+ def name
8
+ @name ||= Dir['*.gemspec'].first.split('.').first
9
+ end
10
+
11
+ def version
12
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
13
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
14
+ end
15
+
16
+ def date
17
+ Date.today.to_s
18
+ end
19
+
20
+ def gemspec_file
21
+ "#{name}.gemspec"
22
+ end
23
+
24
+ def gem_file
25
+ "#{name}-#{version}.gem"
26
+ end
27
+
28
+ def replace_header(head, header_name)
29
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
30
+ end
31
+
32
+ #############################################################################
33
+ #
34
+ # Standard tasks
35
+ #
36
+ #############################################################################
37
+
38
+ require 'rspec'
39
+ require 'rspec/core/rake_task'
40
+
41
+ desc "Run all specs"
42
+ task RSpec::Core::RakeTask.new('spec')
43
+
44
+ task :default => "spec"
45
+
46
+ desc "Open an irb session preloaded with this library"
47
+ task :console do
48
+ sh "irb -rubygems -r ./lib/#{name}.rb"
49
+ end
50
+
51
+ #############################################################################
52
+ #
53
+ # Custom tasks (add your own tasks here)
54
+ #
55
+ #############################################################################
56
+
57
+
58
+ #############################################################################
59
+ #
60
+ # Packaging tasks
61
+ #
62
+ #############################################################################
63
+
64
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
65
+ task :release => :build do
66
+ unless `git branch` =~ /^\* master$/
67
+ puts "You must be on the master branch to release!"
68
+ exit!
69
+ end
70
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
71
+ sh "git tag v#{version}"
72
+ sh "git push origin master"
73
+ sh "git push origin v#{version}"
74
+ sh "gem push pkg/#{name}-#{version}.gem"
75
+ end
76
+
77
+ desc "Build #{gem_file} into the pkg directory"
78
+ task :build => :gemspec do
79
+ sh "mkdir -p pkg"
80
+ sh "gem build #{gemspec_file}"
81
+ sh "mv #{gem_file} pkg"
82
+ end
83
+
84
+ desc "Generate #{gemspec_file}"
85
+ task :gemspec => :validate do
86
+ # read spec file and split out manifest section
87
+ spec = File.read(gemspec_file)
88
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
89
+
90
+ # replace name version and date
91
+ replace_header(head, :name)
92
+ replace_header(head, :version)
93
+ replace_header(head, :date)
94
+
95
+ # determine file list from git ls-files
96
+ files = `git ls-files`.
97
+ split("\n").
98
+ sort.
99
+ reject { |file| file =~ /^\./ }.
100
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
101
+ map { |file| " #{file}" }.
102
+ join("\n")
103
+
104
+ # piece file back together and write
105
+ manifest = " s.files = %w[\n#{files}\n ]\n"
106
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
107
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
108
+ puts "Updated #{gemspec_file}"
109
+ end
110
+
111
+ desc "Validate #{gemspec_file}"
112
+ task :validate do
113
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
114
+ unless libfiles.empty?
115
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
116
+ exit!
117
+ end
118
+ unless Dir['VERSION*'].empty?
119
+ puts "A `VERSION` file at root level violates Gem best practices."
120
+ exit!
121
+ end
122
+ end
data/bin/pair ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib git-pair]))
4
+
5
+ args = ARGV
6
+ options = []
7
+ opts = OptionParser.new do |opts|
8
+ opts.banner = "Usage: git pair [options] first_pair_username second_pair_username"
9
+ opts.separator ""
10
+ opts.separator "General options:"
11
+
12
+ opts.on("-s", "--setup", "Print out shell goodies") do
13
+ options = [:setup]
14
+ end
15
+
16
+ opts.on("--setup-path", "Print out path to shell goodies") do
17
+ options = [:print_setup_path]
18
+ end
19
+
20
+ opts.on("-e N", "--expire N", Integer, "Expire pair information in N hours.") do |n|
21
+ options = [:expire, n]
22
+ end
23
+
24
+ opts.on("-u", "--unpair", "Clear pair information") do
25
+ options = [:unpair]
26
+ end
27
+
28
+ opts.on("--switch", "Switch author and committer") do
29
+ options = [:switch]
30
+ end
31
+
32
+ opts.separator ""
33
+ opts.separator "Common options:"
34
+
35
+ opts.on_tail("-h", "--help", "Show this message") do
36
+ puts opts
37
+ exit
38
+ end
39
+
40
+ opts.on_tail("-v", "--version", "Show version") do
41
+ abort "git pair v#{GitPair::VERSION}"
42
+ end
43
+ end
44
+
45
+ if args.any?
46
+ opts.parse!(args)
47
+ if options.delete(:expire)
48
+ system(GitPair.expire_command(options.pop))
49
+ end
50
+
51
+ options = [:export, args] if options.empty?
52
+ else
53
+ options = [:print_info]
54
+ end
55
+
56
+ GitPair.send(*options)
data/git-pair.gemspec ADDED
@@ -0,0 +1,49 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.specification_version = 2 if s.respond_to? :specification_version=
4
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
5
+ s.rubygems_version = '1.3.5'
6
+
7
+ s.name = %q{pair-up}
8
+ s.version = '1.0.0'
9
+ s.date = Time.now.strftime('%F')
10
+ s.license = 'MIT'
11
+
12
+ s.description = %q{Git author attribution helper for pair programmers.}
13
+ s.summary = %q{pair-up allows developers to be properly credited when Pair Programming and using Git.}
14
+ s.authors = [%q{Andre Helberg}]
15
+ s.email = ["helberg.andre@gmail.com"]
16
+ s.homepage = %q{http://github.com/A-Helberg/git-pair}
17
+ s.require_paths = %w[lib]
18
+ s.extra_rdoc_files = %w[README.md LICENSE.md]
19
+ s.rdoc_options = [%q{--charset=UTF-8}]
20
+
21
+ s.executables = [%q{pair}]
22
+ s.add_development_dependency(%q<rspec>, ["~> 3.2"])
23
+ s.add_runtime_dependency(%q<highline>, ["~> 1.6"])
24
+
25
+ ## Leave this section as-is. It will be automatically generated from the
26
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
27
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
28
+ # = MANIFEST =
29
+ s.files = %w[
30
+ Gemfile
31
+ Gemfile.lock
32
+ LICENSE.md
33
+ README.md
34
+ Rakefile
35
+ bin/pair
36
+ git-pair.gemspec
37
+ lib/git-pair.rb
38
+ lib/git-pair/participant.rb
39
+ lib/git-pair/git-pair.sh
40
+ lib/git-pair/ui.rb
41
+ spec/git-pair/participant_spec.rb
42
+ spec/git-pair/ui_spec.rb
43
+ spec/git-pair_spec.rb
44
+ spec/spec_helper.rb
45
+ ]
46
+ # = MANIFEST =
47
+
48
+ s.test_files = s.files.grep(%r{^spec/})
49
+ end
data/lib/git-pair.rb ADDED
@@ -0,0 +1,161 @@
1
+ require 'highline'
2
+ require 'yaml'
3
+
4
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib git-pair ui]))
5
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib git-pair participant]))
6
+
7
+ module GitPair
8
+
9
+ VERSION = '1.0.0'
10
+
11
+ def self.print_info
12
+ if GitPair.pairing? && STDOUT.tty?
13
+ GitPair::UI.highline.say("Author: #{GitPair.git_author_name} <#{GitPair.git_author_email}>, Comitter: #{GitPair.git_committer_name} <#{GitPair.git_committer_email}>")
14
+ end
15
+ end
16
+
17
+ def self.export(pairs)
18
+ GitPair.current_pair = pairs
19
+
20
+ if GitPair.mac?
21
+ `launchctl setenv GIT_AUTHOR_NAME '#{GitPair.git_author_name}' GIT_AUTHOR_EMAIL '#{GitPair.git_author_email}'`
22
+ `launchctl setenv GIT_COMMITTER_NAME '#{GitPair.git_committer_name}' GIT_COMMITTER_EMAIL '#{GitPair.git_committer_email}'`
23
+ end
24
+
25
+ write_export_file
26
+ print_info
27
+ end
28
+
29
+ def self.expire_command(time)
30
+ %Q(sleep #{to_seconds(time)} && #{GitPair.bin_path} --unpair&)
31
+ end
32
+
33
+ def self.unpair
34
+ GitPair.current_pair = []
35
+
36
+ if GitPair.mac?
37
+ `launchctl unsetenv GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL`
38
+ `launchctl unsetenv GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL`
39
+ end
40
+
41
+ write_export_file
42
+ end
43
+
44
+ def self.author_command
45
+ if GitPair.pairing?
46
+ "export GIT_AUTHOR_NAME='#{GitPair.git_author_name}' GIT_AUTHOR_EMAIL='#{GitPair.git_author_email}' GIT_COMMITTER_NAME='#{GitPair.git_committer_name}' GIT_COMMITTER_EMAIL='#{GitPair.git_committer_email}'"
47
+ else
48
+ "unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL"
49
+ end
50
+ end
51
+
52
+ def self.current_pair
53
+ config[:current_pair] ||= []
54
+ end
55
+
56
+ def self.switch
57
+ if not current_pair.empty?
58
+ GitPair.export current_pair.reverse
59
+ end
60
+ end
61
+
62
+ def self.current_pair=(pairs)
63
+ config[:current_pair] = []
64
+ pairs.each do |participant|
65
+ if GitPair::Participant.find(participant)
66
+ config[:current_pair] << participant
67
+ else
68
+ if GitPair::UI.prompt_for_pair(participant)
69
+ config[:current_pair] << participant
70
+ end
71
+ end
72
+ end
73
+ write_file
74
+ end
75
+
76
+ def self.git_author_name
77
+ dev = GitPair::Participant.find(current_pair[0])
78
+ dev["name"]
79
+ end
80
+
81
+ def self.git_author_email
82
+ dev = GitPair::Participant.find(current_pair[0])
83
+ dev["email"]
84
+ end
85
+
86
+ def self.git_committer_name
87
+ dev = GitPair::Participant.find(current_pair[1])
88
+ dev["name"]
89
+ end
90
+
91
+ def self.git_committer_email
92
+ dev = GitPair::Participant.find(current_pair[1])
93
+ dev["email"]
94
+ end
95
+
96
+ def self.setup_path
97
+ File.join(File.dirname(__FILE__), 'git-pair', 'git-pair.sh')
98
+ end
99
+
100
+ def self.print_setup_path
101
+ puts setup_path
102
+ end
103
+
104
+ def self.setup
105
+ GitPair::UI.highline.say(File.read(setup_path))
106
+ end
107
+
108
+ def self.write_file
109
+ File.open(gitpairrc, File::CREAT|File::TRUNC|File::RDWR, 0644) do |out|
110
+ YAML.dump(config, out)
111
+ end
112
+ end
113
+
114
+ private
115
+
116
+ def self.mac?
117
+ (/darwin14/ =~ RUBY_PLATFORM)
118
+ end
119
+
120
+ def self.config
121
+ @config ||= get_config
122
+ end
123
+
124
+ def self.get_config
125
+ if File.exists?(gitpairrc)
126
+ yamlized = YAML::load_file(gitpairrc)
127
+ return yamlized if yamlized.kind_of?(Hash)
128
+ end
129
+ return {}
130
+ end
131
+
132
+ def self.gitpairrc
133
+ File.expand_path('~/.git-pairrc')
134
+ end
135
+
136
+ def self.gitpair_export_authors
137
+ File.expand_path('~/.git-pair_export_authors')
138
+ end
139
+
140
+ def self.bin_path
141
+ %x[which git-pair].chomp
142
+ end
143
+
144
+ def self.pairing?
145
+ current_pair.any?
146
+ end
147
+
148
+ def self.to_seconds(value)
149
+ value = value.to_s.gsub(/[^\d]/, '').to_i
150
+ unless value.zero?
151
+ value * 60 * 60
152
+ else
153
+ raise StandardError
154
+ end
155
+ end
156
+
157
+ def self.write_export_file
158
+ File.open(gitpair_export_authors, 'w'){|f| f.write(author_command) }
159
+ end
160
+
161
+ end
@@ -0,0 +1,11 @@
1
+ # Add the following to your ~/.bashrc or ~/.zshrc
2
+ #
3
+ # Alternatively, copy/symlink this file and source in your shell. See `git pair --setup-path`.
4
+
5
+ pair() {
6
+ command pair "$@"
7
+ if [[ -s "$HOME/.git-pair_export_authors" ]] ; then source "$HOME/.git-pair_export_authors" ; fi
8
+ }
9
+
10
+ # Uncomment to persist pair info between terminal instances
11
+ # pair
@@ -0,0 +1,41 @@
1
+ module GitPair
2
+ class Participant
3
+
4
+ def self.add(github, email, name)
5
+ unless find(github)
6
+ available_pairs[github] = {}
7
+ available_pairs[github]["email"] = email
8
+ available_pairs[github]["name"] = name
9
+ end
10
+ end
11
+
12
+ def self.find(github)
13
+ available_pairs[github]
14
+ end
15
+
16
+ def self.write_file
17
+ File.open(pairs_file, File::CREAT|File::TRUNC|File::RDWR, 0644) do |out|
18
+ YAML.dump(available_pairs, out)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def self.pairs_file
25
+ File.expand_path("~/.git-pair_pairs")
26
+ end
27
+
28
+ def self.available_pairs
29
+ @available_pairs ||= get_available_pairs
30
+ end
31
+
32
+ def self.get_available_pairs
33
+ if File.exists?(pairs_file)
34
+ yamlized = YAML::load_file(pairs_file)
35
+ return yamlized if yamlized.kind_of?(Hash)
36
+ end
37
+ return {}
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ HighLine.track_eof = false
2
+
3
+ module GitPair
4
+ class UI
5
+
6
+ def self.prompt_for_pair(new_participant)
7
+ highline.say("I don't know who #{new_participant} is.")
8
+ if highline.agree("Do you want to add #{new_participant} to ~/.git-pair_pairs? (yn)")
9
+ participant_name = highline.ask("What is #{new_participant}'s full name?").to_s
10
+ participant_email = highline.ask("What is #{new_participant}'s email?").to_s
11
+ GitPair::Participant.add(new_participant, participant_email, participant_name)
12
+ GitPair::Participant.write_file
13
+ return new_participant
14
+ else
15
+ highline.say("Ignoring #{new_participant}.")
16
+ end
17
+ return nil
18
+ end
19
+
20
+ private
21
+
22
+ def self.highline
23
+ @highline ||= HighLine.new
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPair::Participant do
4
+
5
+ let(:base_pairs) do
6
+ {
7
+ 'bender' => {"email"=>"rcrichoch@fakeinbox.com", "name"=>"Rogelio J. Samour"},
8
+ 'fry' => {"email"=>"crichoch@fakeinbox.com", "name"=>"Phillip J. Fry"},
9
+ 'leela' => {"email"=>"stepriso@fakeinbox.com", "name"=>"Turanga Leela"}
10
+ }
11
+ end
12
+
13
+ describe ".write_file" do
14
+ it "writes the contents of GitPair::Participant.available_pairs to the hitch_pairs file" do
15
+ expect(YAML).to receive(:dump)
16
+ GitPair::Participant.write_file
17
+ end
18
+ end
19
+
20
+ describe ".add" do
21
+
22
+ context "when the participant is not present" do
23
+ it "adds the participant to GitPair::Participant.available_pairs" do
24
+ allow(GitPair::Participant).to receive(:get_available_pairs) { {} }
25
+ GitPair::Participant.add("therubymug", "rcrichoch@fakeinbox.com", "Rogelio J. Samour")
26
+ expect(GitPair::Participant.available_pairs).to eql({"therubymug"=>{"email"=>"rcrichoch@fakeinbox.com", "name"=>"Rogelio J. Samour"}})
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ describe ".find" do
33
+
34
+ context "when the participant is present" do
35
+ it "and_return the full name" do
36
+ expect(GitPair::Participant.find("therubymug")).to eql({"email"=>"rcrichoch@fakeinbox.com", "name"=>"Rogelio J. Samour"})
37
+ end
38
+ end
39
+
40
+ context "when the participant is not present" do
41
+ it "and_return nil" do
42
+ expect(GitPair::Participant.find("nobody")).to be_nil
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPair::UI do
4
+
5
+ describe '.prompt_for_pair' do
6
+
7
+ let(:new_author) { 'leela' }
8
+ let(:new_author_name) { 'Turanga Leela' }
9
+ let(:new_author_email) { 'Turanga Leela' }
10
+
11
+
12
+ before do
13
+ allow(GitPair::UI.highline).to receive(:ask) {new_author_name}
14
+ # expect(GitPair::UI.highline).to receive(:say)
15
+ end
16
+
17
+ it 'states that the new pair is not in the git-pair_pairs file' do
18
+ expect(GitPair::UI.highline).to receive(:say).with("I don't know who #{new_author} is.")
19
+ GitPair::UI.prompt_for_pair(new_author)
20
+ end
21
+
22
+ it 'prompts for pair' do
23
+ expect(GitPair::UI.highline).to receive(:say)
24
+ expect(GitPair::UI.highline).to receive(:agree).with("Do you want to add #{new_author} to ~/.git-pair_pairs? (yn)")
25
+ expect(GitPair::UI.highline).to receive(:say)
26
+ GitPair::UI.prompt_for_pair(new_author)
27
+ end
28
+
29
+ context 'when user does not agree to add new author' do
30
+ it "states it's ignoring the author" do
31
+ allow(GitPair::UI.highline).to receive(:agree) {false}
32
+ expect(GitPair::UI.highline).to receive(:say)
33
+ expect(GitPair::UI.highline).to receive(:say).with("Ignoring #{new_author}.")
34
+ GitPair::UI.prompt_for_pair(new_author)
35
+ end
36
+ end
37
+
38
+ context 'when user agrees to add new author' do
39
+
40
+ before do
41
+ allow(GitPair::UI.highline).to receive(:agree) {true}
42
+ expect(GitPair::UI.highline).to receive(:say)
43
+ end
44
+
45
+ it "asks for the new author's name" do
46
+ expect(GitPair::UI.highline).to receive(:ask).with("What is #{new_author}'s full name?")
47
+ GitPair::UI.prompt_for_pair(new_author)
48
+ end
49
+
50
+ it "adds the new author" do
51
+ expect(GitPair::Participant).to receive(:add).with(new_author, new_author_name, new_author_email)
52
+ GitPair::UI.prompt_for_pair(new_author)
53
+ end
54
+
55
+ it "writes the ~/.hitch_pairs file" do
56
+ expect(GitPair::Participant).to receive(:write_file)
57
+ GitPair::UI.prompt_for_pair(new_author)
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,233 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitPair do
4
+
5
+ let(:pairs_data) {
6
+ {
7
+ 'leela' => { 'name' => 'Turanga Leela', 'email' => 'leela@futurama.test'},
8
+ 'fry' => { 'name' => 'Philip J. Fry', 'email' => 'fry@futurama.test'},
9
+ 'zoidberg' => { 'name' => 'John A. Zoidberg', 'email' => 'zoidberg@futurama.test' }
10
+ }
11
+ }
12
+
13
+ let(:gitpair_config) do
14
+ {
15
+ :current_pair => ["leela", "fry"]
16
+ }
17
+ end
18
+
19
+ before do
20
+ allow(GitPair::Participant).to receive(:config) { gitpair_config }
21
+ allow(GitPair::Participant).to receive(:available_pairs) { pairs_data }
22
+ allow(GitPair).to receive(:write_file)
23
+ end
24
+
25
+ describe '.print_info' do
26
+
27
+ context 'when pairing' do
28
+ it 'returns the author and commiters names and emails' do
29
+ expect(GitPair::UI.highline).to receive(:say).with("Author: Turanga Leela <leela@futurama.test>, Comitter: Philip J. Fry <fry@futurama.test>")
30
+ GitPair.current_pair = ['leela', 'fry']
31
+ GitPair.print_info
32
+ end
33
+ end
34
+
35
+ context 'when not pairing' do
36
+ it 'returns nothing' do
37
+ GitPair.current_pair = []
38
+ expect(GitPair.print_info).to be_nil
39
+ end
40
+ end
41
+
42
+ context 'when not in an interactive shell' do
43
+ it 'returns nothing' do
44
+ allow(STDOUT).to receive(:tty?) { false }
45
+ expect(GitPair::UI.highline).to_not receive(:say)
46
+ GitPair.current_pair = ['leela', 'fry']
47
+ GitPair.print_info
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ describe '.switch' do
54
+
55
+ it "switches the author and commiter around" do
56
+ allow(GitPair::UI.highline).to receive(:say)
57
+ GitPair.current_pair= ['leela', 'fry']
58
+ expect(GitPair.current_pair).to eql(['leela', 'fry'])
59
+ GitPair.switch
60
+ expect(GitPair.current_pair).to eql(["fry", "leela"])
61
+ end
62
+ end
63
+
64
+ describe '.export' do
65
+
66
+ let(:pairs) { ['fry', 'leela'] }
67
+
68
+ before do
69
+ allow(GitPair).to receive(:print_info)
70
+ end
71
+
72
+ it 'sets the current pair' do
73
+ expect(GitPair).to receive(:current_pair=) {pairs}
74
+ GitPair.export(pairs)
75
+ end
76
+
77
+ it 'writes the export file' do
78
+ expect(GitPair).to receive(:write_export_file)
79
+ GitPair.export(pairs)
80
+ end
81
+
82
+ it 'prints out pair info' do
83
+ expect(GitPair).to receive(:print_info)
84
+ GitPair.export(pairs)
85
+ end
86
+
87
+ end
88
+
89
+ describe '.expire_command' do
90
+ before do
91
+ allow(GitPair).to receive(:bin_path) {'/usr/local/bin/git-pair'}
92
+ end
93
+
94
+ context 'with a valid string' do
95
+ let(:time_string) { '8' }
96
+ it 'returns the system command to call' do
97
+ expect(GitPair.expire_command(time_string)).to eql('sleep 28800 && /usr/local/bin/git-pair --unpair&')
98
+ end
99
+ end
100
+
101
+ context 'with a valid integer' do
102
+ let(:time_string) { 8 }
103
+ it 'returns the system command to call' do
104
+ expect(GitPair.expire_command(time_string)).to eql('sleep 28800 && /usr/local/bin/git-pair --unpair&')
105
+ end
106
+ end
107
+
108
+ context 'with an invalid string' do
109
+ let(:time_string) { 'BAR' }
110
+ it 'raises an error' do
111
+ expect {GitPair.expire_command(time_string)}.to raise_error(StandardError)
112
+ end
113
+ end
114
+
115
+ end
116
+
117
+ describe '.unpair' do
118
+
119
+ let(:pairs) { ['fry', 'leela'] }
120
+
121
+ it 'sets the current pair to an empty array' do
122
+ allow(GitPair).to receive(:current_pair=)
123
+ GitPair.unpair
124
+ end
125
+
126
+ it 'writes the export file' do
127
+ allow(GitPair).to receive(:write_export_file)
128
+ GitPair.unpair
129
+ end
130
+
131
+ end
132
+
133
+ describe '.author_command' do
134
+
135
+ context 'when pairing' do
136
+ it 'returns the export shell command for GIT_AUTHOR_* and GIT_COMMITTER_*' do
137
+ GitPair.current_pair = ['leela', 'fry']
138
+ expect(GitPair.author_command).to eql("export GIT_AUTHOR_NAME='Turanga Leela' GIT_AUTHOR_EMAIL='leela@futurama.test' GIT_COMMITTER_NAME='Philip J. Fry' GIT_COMMITTER_EMAIL='fry@futurama.test'")
139
+ end
140
+
141
+ it 'uses the first pair as author and the second as commiter' do
142
+ GitPair.current_pair = ['fry', 'leela']
143
+ expect(GitPair.author_command).to eql("export GIT_AUTHOR_NAME='Philip J. Fry' GIT_AUTHOR_EMAIL='fry@futurama.test' GIT_COMMITTER_NAME='Turanga Leela' GIT_COMMITTER_EMAIL='leela@futurama.test'")
144
+ end
145
+ end
146
+
147
+ context 'when not pairing' do
148
+ it 'returns the unset shell command for GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL' do
149
+ GitPair.current_pair = []
150
+ expect(GitPair.author_command).to eql("unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL")
151
+ end
152
+ end
153
+
154
+ context 'with more than 2 developers' do
155
+ it "ignores the everyone but the first two" do
156
+ GitPair.current_pair = ['leela', 'fry', 'zoidberg']
157
+ expect(GitPair.author_command).to eql("export GIT_AUTHOR_NAME='Turanga Leela' GIT_AUTHOR_EMAIL='leela@futurama.test' GIT_COMMITTER_NAME='Philip J. Fry' GIT_COMMITTER_EMAIL='fry@futurama.test'")
158
+ end
159
+ end
160
+
161
+ end
162
+
163
+ describe '.current_pair' do
164
+ it 'returns an array of Github usernames' do
165
+ allow(GitPair).to receive(:config) {gitpair_config}
166
+ expect(GitPair.current_pair).to eql(['leela', 'fry'])
167
+ end
168
+ end
169
+
170
+ describe '.current_pair=' do
171
+
172
+ before { allow(GitPair).to receive(:write_file) }
173
+
174
+ it 'writes the git-pairrc file' do
175
+ expect(GitPair).to receive(:write_file)
176
+ GitPair.current_pair = ['leela', 'fry']
177
+ end
178
+
179
+ context 'when there are no new participants' do
180
+ it 'sets the current pair with the participants given' do
181
+ GitPair.current_pair = ['leela', 'fry']
182
+ expect(GitPair.current_pair).to eql(['leela', 'fry'])
183
+ end
184
+ end
185
+
186
+ context 'when there are new participants' do
187
+
188
+ let(:new_participant) { 'therubymug' }
189
+
190
+ it "prompts for the new participant's info" do
191
+ expect(GitPair::UI).to receive(:prompt_for_pair).with(new_participant)
192
+ GitPair.current_pair = [new_participant, 'fry']
193
+ end
194
+
195
+ it 'adds the new participant to current pair' do
196
+ allow(GitPair::UI).to receive(:prompt_for_pair) {new_participant}
197
+ GitPair.current_pair = [new_participant, 'fry']
198
+ expect(GitPair.current_pair).to eql([new_participant, 'fry'])
199
+ end
200
+
201
+ end
202
+ end
203
+
204
+ describe '.git_author_name' do
205
+ it "returns the first participant's name" do
206
+ allow(GitPair).to receive(:config) { gitpair_config }
207
+ expect(GitPair.git_author_name).to eql('Turanga Leela')
208
+ end
209
+ end
210
+
211
+ describe '.git_author_email' do
212
+ it "returns the first participant's email" do
213
+ allow(GitPair).to receive(:config) { gitpair_config }
214
+ expect(GitPair.git_author_email).to eql('leela@futurama.test')
215
+ end
216
+ end
217
+
218
+ describe '.git_committer_name' do
219
+ it "returns the second participant's name" do
220
+ allow(GitPair).to receive(:config) { gitpair_config }
221
+ expect(GitPair.git_committer_name).to eql('Philip J. Fry')
222
+ end
223
+ end
224
+
225
+ describe '.git_committer_email' do
226
+ it "returns the second participant's email" do
227
+ allow(GitPair).to receive(:config) { gitpair_config }
228
+ expect(GitPair.git_committer_email).to eql('fry@futurama.test')
229
+ end
230
+ end
231
+
232
+
233
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+ require 'fileutils'
3
+ require 'tempfile'
4
+ require 'pry'
5
+
6
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'git-pair')
7
+
8
+ RSpec.configure do |config|
9
+ config.color = true
10
+ config.formatter = 'progress'
11
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pair-up
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andre Helberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ description: Git author attribution helper for pair programmers.
42
+ email:
43
+ - helberg.andre@gmail.com
44
+ executables:
45
+ - pair
46
+ extensions: []
47
+ extra_rdoc_files:
48
+ - README.md
49
+ - LICENSE.md
50
+ files:
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.md
54
+ - README.md
55
+ - Rakefile
56
+ - bin/pair
57
+ - git-pair.gemspec
58
+ - lib/git-pair.rb
59
+ - lib/git-pair/git-pair.sh
60
+ - lib/git-pair/participant.rb
61
+ - lib/git-pair/ui.rb
62
+ - spec/git-pair/participant_spec.rb
63
+ - spec/git-pair/ui_spec.rb
64
+ - spec/git-pair_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: http://github.com/A-Helberg/git-pair
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options:
72
+ - "--charset=UTF-8"
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.5
88
+ signing_key:
89
+ specification_version: 2
90
+ summary: pair-up allows developers to be properly credited when Pair Programming and
91
+ using Git.
92
+ test_files:
93
+ - spec/git-pair/participant_spec.rb
94
+ - spec/git-pair/ui_spec.rb
95
+ - spec/git-pair_spec.rb
96
+ - spec/spec_helper.rb