therubymug-hitch 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. data/README.rdoc +48 -0
  2. data/Rakefile +50 -0
  3. data/bin/hitch +8 -0
  4. data/bin/hitchrc +6 -0
  5. data/bin/unhitch +6 -0
  6. data/lib/hitch.rb +288 -0
  7. metadata +61 -0
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ hitch
2
+ by Rogelio J. Samour
3
+ http://therubymug.com
4
+
5
+ == DESCRIPTION:
6
+
7
+ Hitch allows developers to be properly credited when Pair Programming and using Git.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * General Awesomeness
12
+
13
+ == SYNOPSIS:
14
+
15
+ hitch tpope
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * Git, RubyGems
20
+
21
+ == INSTALL:
22
+
23
+ * sudo gem install therubymug-hitch
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 Rogelio J. Samour
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ begin
10
+ load 'tasks/setup.rb'
11
+ rescue LoadError
12
+ raise RuntimeError, '### please install the "bones" gem ###'
13
+ end
14
+ end
15
+
16
+ ensure_in_path 'lib'
17
+ require 'hitch'
18
+
19
+ task :default => 'spec:run'
20
+
21
+ PROJ.name = 'hitch'
22
+ PROJ.authors = 'Rogelio J. Samour (therubymug)'
23
+ PROJ.email = 'rogelio@therubymug.com'
24
+ PROJ.url = 'http://github.com/therubymug/hitch'
25
+ PROJ.version = Hitch::VERSION
26
+ PROJ.rubyforge.name = 'hitch'
27
+ PROJ.dependencies = ['highline']
28
+
29
+ PROJ.spec.opts << '--color'
30
+
31
+ require 'fileutils'
32
+
33
+ spec = Gem::Specification.new do |s|
34
+ s.name = %q{hitch}
35
+ s.version = "0.0.1"
36
+ s.summary = %q{Hitch allows developers to be properly credited when Pair Programming and using Git.}
37
+ s.email = %q{ro@hashrocket.com}
38
+ s.homepage = %q{http://github.com/therubymug/hitch}
39
+ s.has_rdoc = false
40
+ s.authors = ["Rogelio Samour", "Les Hill"]
41
+ s.files = %w( README.rdoc Rakefile ) + Dir["{bin,lib}/**/*"].sort
42
+ s.extra_rdoc_files = ["README.rdoc"]
43
+ s.executables = ["hitch", "unhitch", "hitchrc"]
44
+ end
45
+
46
+ desc "Generate the static gemspec required for github"
47
+ task :gemspec do
48
+ open("hitch.gemspec", "w").write(spec.to_ruby)
49
+ end
50
+
data/bin/hitch ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib hitch]))
4
+ include Hitch
5
+
6
+ if personal_info
7
+ hitch
8
+ end
data/bin/hitchrc ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib hitch]))
4
+ include Hitch
5
+
6
+ create_hitchrc
data/bin/unhitch ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib hitch]))
4
+ include Hitch
5
+
6
+ unhitch
data/lib/hitch.rb ADDED
@@ -0,0 +1,288 @@
1
+ require 'highline'
2
+
3
+ module Hitch
4
+ # :stopdoc:
5
+ VERSION = '0.0.1'
6
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
+ # :startdoc:
9
+
10
+ # Returns the version string for the library.
11
+ #
12
+ def self.version
13
+ VERSION
14
+ end
15
+
16
+ # Returns the library path for the module. If any arguments are given,
17
+ # they will be joined to the end of the libray path using
18
+ # <tt>File.join</tt>.
19
+ #
20
+ def self.libpath( *args )
21
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
22
+ end
23
+
24
+ # Returns the lpath for the module. If any arguments are given,
25
+ # they will be joined to the end of the path using
26
+ # <tt>File.join</tt>.
27
+ #
28
+ def self.path( *args )
29
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
30
+ end
31
+
32
+ # Utility method used to require all files ending in .rb that lie in the
33
+ # directory below this file that has the same name as the filename passed
34
+ # in. Optionally, a specific _directory_ name can be passed in such that
35
+ # the _filename_ does not have to be equivalent to the directory.
36
+ #
37
+ def self.require_all_libs_relative_to( fname, dir = nil )
38
+ dir ||= ::File.basename(fname, '.*')
39
+ search_me = ::File.expand_path(
40
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
41
+
42
+ Dir.glob(search_me).sort.each {|rb| require rb}
43
+ end
44
+
45
+ HighLine.track_eof = false
46
+
47
+ def write_hitchrc
48
+ personal_info['pairing_with'] = pairing_with
49
+ File.open(hitchrc, File::CREAT|File::TRUNC|File::RDWR, 0644) do |out|
50
+ YAML.dump(personal_info, out)
51
+ end
52
+ end
53
+
54
+ def hitchrc
55
+ @hitchrc ||= File.expand_path("~/.hitchrc")
56
+ end
57
+
58
+ def personal_info
59
+ if File.exists?(hitchrc)
60
+ @personal_info ||= YAML::load_file(hitchrc)
61
+ else
62
+ @personal_info ||= {}
63
+ end
64
+ end
65
+
66
+ def hitch_pairs
67
+ @hitch_pairs ||= File.expand_path("~/.hitch_pairs")
68
+ end
69
+
70
+ def pairs
71
+ if File.exists?(hitch_pairs)
72
+ @pairs ||= YAML::load_file(hitch_pairs)
73
+ else
74
+ @pairs ||= {}
75
+ end
76
+ end
77
+
78
+ def write_hitch_pairs
79
+ File.open(hitch_pairs, File::CREAT|File::TRUNC|File::RDWR, 0644) do |out|
80
+ YAML.dump(pairs, out)
81
+ end
82
+ end
83
+
84
+ def ui
85
+ @ui ||= HighLine.new
86
+ end
87
+
88
+ def valid_hitchrc?(hitchrc)
89
+ return false if hitchrc.empty?
90
+ return false if hitchrc['my_name'].empty?
91
+ return false if hitchrc['my_github'].empty?
92
+ return false if hitchrc['group_email'].empty?
93
+ return true
94
+ end
95
+
96
+ def write_gitconfig
97
+ clean_gitconfig
98
+ File.open(File.join(ENV['HOME'], ".gitconfig"), "a+") do |f|
99
+ f.puts "# start - lines added by hitch #"
100
+ f.puts "[user]"
101
+ f.puts "\tname = '#{hitch_name}'"
102
+ f.puts "\temail = #{hitch_email}"
103
+ f.puts "# end - lines added by hitch #"
104
+ end
105
+ end
106
+
107
+ def add_pair(git_name)
108
+ pairing_with << git_name
109
+ pairing_with.sort!
110
+ pairing_with.uniq!
111
+ end
112
+
113
+ def pairing_with
114
+ @pairing_with ||= (personal_info['pairing_with'] or [])
115
+ end
116
+
117
+ def hitch_name
118
+ my_pairs_and_i.map {|github, name| name}.join(' and ')
119
+ end
120
+
121
+ def hitch_email
122
+ "#{group_prefix}+#{my_pairs_and_i.map{|github, name| github}.join('+')}@#{group_domain}"
123
+ end
124
+
125
+ def my_pairs_and_i
126
+ and_i = pairing_with.map {|github| [github, pairs[github]]}
127
+ and_i << [personal_info['my_github'], personal_info['my_name']]
128
+ and_i.sort_by {|github, name| github }
129
+ end
130
+
131
+ def group_prefix
132
+ personal_info['group_email'].split('@').first
133
+ end
134
+
135
+ def group_domain
136
+ personal_info['group_email'].split('@').last
137
+ end
138
+
139
+ def clean_gitconfig
140
+ config_file = File.expand_path("~/.gitconfig")
141
+ body = File.read(config_file)
142
+ body.gsub!(/# start - lines added by hitch #\n.*?\n# end - lines added by hitch #\n/m, '')
143
+ File.open(config_file + ".tmp", 'w') {|f| f.write(body)}
144
+ File.rename(config_file + ".tmp", config_file)
145
+ end
146
+
147
+ def prep_gitconfig
148
+ if pairing?
149
+ write_gitconfig
150
+ else
151
+ clean_gitconfig
152
+ end
153
+ end
154
+
155
+ def unhitch
156
+ if personal_info
157
+ clear_pair_info
158
+ write_hitchrc
159
+ clean_gitconfig
160
+ print_current_status
161
+ end
162
+ end
163
+
164
+ def print_current_status
165
+ if pairing?
166
+ ui.say " Currently pairing with #{pairing_with.join(' ')}."
167
+ else
168
+ ui.say " Currently coding solo."
169
+ end
170
+ end
171
+
172
+ def print_version
173
+ ui.say "hitch v#{Hitch.version}"
174
+ end
175
+
176
+ def print_help
177
+ print_version
178
+ ui.say ""
179
+ ui.say "Usage:"
180
+ ui.say "\thitch <github_username>"
181
+ ui.say "\thitch -i to see all available pairs"
182
+ ui.say "\tunhitch to clear"
183
+ ui.say "\thitchrc to create ~/.hitchrc"
184
+ ui.say ""
185
+ end
186
+
187
+ def clear_pair_info
188
+ personal_info['pairing_with'] = []
189
+ end
190
+
191
+ def pairing?
192
+ return false if personal_info.empty?
193
+ return false if personal_info['pairing_with'].nil? || personal_info['pairing_with'].length.zero?
194
+ true
195
+ end
196
+
197
+ def existing_pair?(pair)
198
+ pairs.any? {|github, name| github == pair}
199
+ end
200
+
201
+ def interactive
202
+ key = pair_name = ""
203
+ ui.choose do |menu|
204
+ menu.prompt = "Who is your pair?"
205
+ pairs.sort_by {|github, name| github }.each do |github, name|
206
+ menu_label = github == personal_info['my_github'] ? "#{github}: #{personal_info['my_name']} (Pick yourself to code solo)" : "#{github}: #{name}"
207
+ menu.choice(menu_label) do
208
+ clear_pair_info
209
+ unless github == personal_info['my_github']
210
+ add_pair(github)
211
+ end
212
+ end
213
+ end
214
+ end
215
+ write_hitchrc
216
+ prep_gitconfig
217
+ end
218
+
219
+ def hitch
220
+ opts = ARGV
221
+ case opts
222
+ when ["-i"]
223
+ interactive
224
+ when ["-h"]
225
+ print_help
226
+ when ["-v"]
227
+ print_version
228
+ else
229
+ if opts.any?
230
+ save_pairs = false
231
+ clear_pair_info
232
+
233
+ opts.each do |opt|
234
+ unless existing_pair?(opt)
235
+ ui.say("I don't know who #{opt} is.")
236
+ if ui.agree("Do you want to add #{opt} to ~/.hitch_pairs? ", true)
237
+ pairs[opt] = ui.ask("What is #{opt}'s full name?") do |q|
238
+ q.validate = /\A[(\w+)\s?]+\Z/
239
+ end
240
+ add_pair(opt)
241
+ save_pairs ||= true
242
+ else
243
+ ui.say("Ignoring #{opt}.")
244
+ end
245
+ else
246
+ add_pair(opt)
247
+ end
248
+ end
249
+ write_hitchrc
250
+ write_hitch_pairs if save_pairs
251
+ prep_gitconfig
252
+ end
253
+
254
+ print_current_status
255
+ end
256
+ end
257
+
258
+ def create_hitchrc
259
+ begin
260
+ unless File.exists?(hitchrc) and !ui.agree("Do you want to overwrite your #{ENV['HOME']}/.hitchrc file?", true)
261
+ ui.say("We need to setup your #{ENV['HOME']}/.hitchrc file")
262
+ personal_info['my_name'] = ui.ask("What is your full name?") do |q|
263
+ q.validate = /\A([\w\.\(\)]+\s?)+\z/
264
+ end
265
+
266
+ personal_info['my_github'] = ui.ask("What is your github username?") do |q|
267
+ q.case = :down
268
+ q.validate = /\A[a-z0-9\-]+\z/
269
+ end
270
+
271
+ personal_info['group_email'] = ui.ask("What is the group email? e.g. dev@hashrocket.com will become dev+therubymug+leshill@hashrocket.com") do |q|
272
+ q.case = :down
273
+ q.validate = /\A[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+\z/ # Simple email validation.
274
+ end
275
+
276
+ write_hitchrc
277
+ end
278
+ rescue EOFError # HighLine throws this if @input.eof?
279
+ break
280
+ end
281
+
282
+ print_current_status
283
+ end
284
+ end # module Hitch
285
+
286
+ Hitch.require_all_libs_relative_to(__FILE__)
287
+
288
+ # EOF
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: therubymug-hitch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rogelio Samour
8
+ - Les Hill
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-04-20 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email: ro@hashrocket.com
19
+ executables:
20
+ - hitch
21
+ - unhitch
22
+ - hitchrc
23
+ extensions: []
24
+
25
+ extra_rdoc_files:
26
+ - README.rdoc
27
+ files:
28
+ - README.rdoc
29
+ - Rakefile
30
+ - bin/hitch
31
+ - bin/hitchrc
32
+ - bin/unhitch
33
+ - lib/hitch.rb
34
+ has_rdoc: false
35
+ homepage: http://github.com/therubymug/hitch
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.2.0
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: Hitch allows developers to be properly credited when Pair Programming and using Git.
60
+ test_files: []
61
+