git_reflow 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git_reflow (0.2.1)
5
- github_api (= 0.6.5)
6
- gli (= 2.0.0)
4
+ git_reflow (0.2.2)
5
+ colorize (= 0.5.8)
6
+ github_api (= 0.7.0)
7
+ gli (= 2.1.0)
7
8
  highline
8
9
  httpclient
9
- json_pure (= 1.7.5)
10
10
 
11
11
  GEM
12
12
  remote: http://rubygems.org/
@@ -17,9 +17,10 @@ GEM
17
17
  cucumber (>= 1.1.1)
18
18
  ffi (>= 1.0.11)
19
19
  rspec (>= 2.7.0)
20
- builder (3.0.0)
20
+ builder (3.1.3)
21
21
  childprocess (0.3.5)
22
22
  ffi (~> 1.0, >= 1.0.6)
23
+ colorize (0.5.8)
23
24
  crack (0.3.1)
24
25
  cucumber (1.2.1)
25
26
  builder (>= 2.1.2)
@@ -33,15 +34,15 @@ GEM
33
34
  gherkin (2.11.2)
34
35
  json (>= 1.4.6)
35
36
  git (1.2.5)
36
- github_api (0.6.5)
37
+ github_api (0.7.0)
37
38
  faraday (~> 0.8.1)
38
39
  hashie (~> 1.2.0)
39
40
  multi_json (~> 1.3)
40
41
  nokogiri (~> 1.5.2)
41
42
  oauth2
42
- gli (2.0.0)
43
+ gli (2.1.0)
43
44
  hashie (1.2.0)
44
- highline (1.6.14)
45
+ highline (1.6.15)
45
46
  httpauth (0.1)
46
47
  httpclient (2.2.7)
47
48
  jeweler (1.8.4)
@@ -50,7 +51,6 @@ GEM
50
51
  rake
51
52
  rdoc
52
53
  json (1.7.5)
53
- json_pure (1.7.5)
54
54
  jwt (0.1.5)
55
55
  multi_json (>= 1.0)
56
56
  multi_json (1.3.6)
@@ -71,10 +71,10 @@ GEM
71
71
  rspec-expectations (~> 2.11.0)
72
72
  rspec-mocks (~> 2.11.0)
73
73
  rspec-core (2.11.1)
74
- rspec-expectations (2.11.2)
74
+ rspec-expectations (2.11.3)
75
75
  diff-lcs (~> 1.1.3)
76
76
  rspec-mocks (2.11.2)
77
- webmock (1.8.9)
77
+ webmock (1.8.10)
78
78
  addressable (>= 2.2.7)
79
79
  crack (>= 0.1.7)
80
80
 
data/git_reflow.gemspec CHANGED
@@ -23,10 +23,10 @@ spec = Gem::Specification.new do |s|
23
23
  s.add_development_dependency('aruba', '~> 0.4.6')
24
24
  s.add_development_dependency('jeweler')
25
25
  s.add_development_dependency('webmock')
26
- s.add_dependency('gli', '2.0.0')
27
- s.add_dependency('json_pure', '1.7.5')
26
+ s.add_dependency('colorize', '0.5.8')
27
+ s.add_dependency('gli', '2.1.0')
28
28
  s.add_dependency('highline')
29
29
  s.add_dependency('httpclient')
30
- s.add_dependency('github_api', '0.6.5')
30
+ s.add_dependency('github_api', '0.7.0')
31
31
  s.post_install_message = "You need to setup your GitHub OAuth token\nPlease run 'git-reflow setup'"
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module GitReflow
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/git_reflow.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- require 'json/pure'
4
3
  require 'open-uri'
5
4
  require "highline/import"
6
5
  require 'httpclient'
7
6
  require 'github_api'
7
+ require 'json/pure'
8
+ require 'colorize'
8
9
 
9
10
  module GitReflow
10
11
  extend self
@@ -39,20 +40,8 @@ module GitReflow
39
40
  error_message = e.to_s
40
41
  if error_message =~ /request already exists/i
41
42
  existing_pull_request = find_pull_request( :from => current_branch, :to => options['base'] )
42
- puts "Existing pull request at: #{existing_pull_request[:html_url]}"
43
-
44
- # check for needed lgtm's
45
- pull_comments = pull_request_comments(existing_pull_request)
46
- if pull_comments.any?
47
- open_comment_authors = find_authors_of_open_pull_request_comments(existing_pull_request)
48
- last_committed_at = Time.parse existing_pull_request.head.repo.updated_at
49
- lgtm_authors = comment_authors_for_pull_request(existing_pull_request, :with => LGTM, :after => last_committed_at)
50
- puts "[review] LGTM given by: #{lgtm_authors.join(', ')}" if lgtm_authors.any?
51
- puts "[notice] You still need a LGTM from: #{open_comment_authors.join(', ')}" if open_comment_authors.any?
52
- else
53
- puts "[notice] No one has reviewed your pull request..."
54
- end
55
-
43
+ puts "A pull request already exists for these branches:"
44
+ display_pull_request_summary(existing_pull_request)
56
45
  ask_to_open_in_browser(existing_pull_request.html_url)
57
46
  else
58
47
  puts error_message
@@ -78,13 +67,13 @@ module GitReflow
78
67
  if open_comment_authors.empty?
79
68
  lgtm_authors = comment_authors_for_pull_request(existing_pull_request, :with => LGTM)
80
69
  commit_message = get_first_commit_message
81
- puts "Merging pull request ##{existing_pull_request[:number]}: '#{existing_pull_request[:title]}', from '#{existing_pull_request[:head][:label]}' into '#{existing_pull_request[:base][:label]}'"
70
+ puts "Merging pull request ##{existing_pull_request.number}: '#{existing_pull_request.title}', from '#{existing_pull_request.head.label}' into '#{existing_pull_request.base.label}'"
82
71
 
83
72
  update_destination(options['base'])
84
73
  merge_feature_branch(:feature_branch => feature_branch,
85
74
  :destination_branch => options['base'],
86
- :pull_request_number => existing_pull_request[:number],
87
- :message => "\nCloses ##{existing_pull_request[:number]}\n\nLGTM given by: @#{lgtm_authors.join(', @')}\n")
75
+ :pull_request_number => existing_pull_request.number,
76
+ :message => "\nCloses ##{existing_pull_request.number}\n\nLGTM given by: @#{lgtm_authors.join(', @')}\n")
88
77
  append_to_squashed_commit_message(commit_message)
89
78
  committed = system('git commit')
90
79
 
@@ -142,7 +131,6 @@ module GitReflow
142
131
  `git log --pretty=format:"%s" --no-merges -n 1`.strip
143
132
  end
144
133
 
145
- private
146
134
 
147
135
  def set_oauth_token(oauth_token)
148
136
  `git config --global --replace-all github.oauth-token #{oauth_token}`
@@ -181,8 +169,8 @@ module GitReflow
181
169
  def find_pull_request(options)
182
170
  existing_pull_request = nil
183
171
  github.pull_requests.all(remote_user, remote_repo_name, :state => 'open') do |pull_request|
184
- if pull_request[:base][:label] == "#{remote_user}:#{options[:to]}" and
185
- pull_request[:head][:label] == "#{remote_user}:#{options[:from]}"
172
+ if pull_request.base.label == "#{remote_user}:#{options[:to]}" and
173
+ pull_request.head.label == "#{remote_user}:#{options[:from]}"
186
174
  existing_pull_request = pull_request
187
175
  break
188
176
  end
@@ -191,8 +179,8 @@ module GitReflow
191
179
  end
192
180
 
193
181
  def pull_request_comments(pull_request)
194
- comments = github.issues.comments.all remote_user, remote_repo_name, pull_request[:number]
195
- review_comments = github.pull_requests.comments.all remote_user, remote_repo_name, pull_request[:number]
182
+ comments = github.issues.comments.all remote_user, remote_repo_name, pull_request.number
183
+ review_comments = github.pull_requests.comments.all remote_user, remote_repo_name, pull_request.number
196
184
  comments + review_comments
197
185
  end
198
186
 
@@ -200,21 +188,26 @@ module GitReflow
200
188
  # first we'll gather all the authors that have commented on the pull request
201
189
  all_comments = pull_request_comments(pull_request)
202
190
  comment_authors = comment_authors_for_pull_request(pull_request)
191
+ lgtm_authors = []
203
192
 
204
193
  # now we need to check that all the commented authors have given a lgtm after the last commit
205
194
  all_comments.each do |comment|
206
195
  next unless comment_authors.include?(comment.user.login)
207
- pull_last_committed_at = Time.parse pull_request.head.repo.updated_at
196
+ pull_last_committed_at = get_commited_time(pull_request.head.sha)
208
197
  comment_created_at = Time.parse(comment.created_at)
209
198
  if comment_created_at > pull_last_committed_at
210
- if comment.body =~ LGTM
211
- comment_authors -= [comment.user.login]
199
+ if comment[:body] =~ LGTM
200
+ lgtm_authors << comment.user.login
212
201
  else
213
202
  comment_authors << comment.user.login unless comment_authors.include?(comment.user.login)
214
203
  end
204
+ else
205
+ comment_authors -= [comment.user.login] if comment_authors.include?(comment.user.login)
215
206
  end
216
207
  end
217
208
 
209
+ comment_authors -= lgtm_authors
210
+
218
211
  comment_authors || []
219
212
  end
220
213
 
@@ -224,13 +217,57 @@ module GitReflow
224
217
 
225
218
  all_comments.each do |comment|
226
219
  next if options[:after] and Time.parse(comment.created_at) < options[:after]
227
- comment_authors << comment.user.login if !comment_authors.include?(comment.user.login) and (options[:with].nil? or comment.body =~ options[:with])
220
+ comment_authors << comment.user.login if !comment_authors.include?(comment.user.login) and (options[:with].nil? or comment[:body] =~ options[:with])
228
221
  end
229
222
 
230
223
  # remove the current user from the list to check
231
224
  comment_authors -= [github_user]
232
225
  end
233
226
 
227
+ def display_pull_request_summary(pull_request)
228
+ summary_data = {
229
+ "branches" => "#{pull_request.head.label} -> #{pull_request.base.label}",
230
+ "number" => pull_request.number,
231
+ "url" => pull_request.html_url
232
+ }
233
+
234
+ notices = ""
235
+ reviewed_by = comment_authors_for_pull_request(pull_request).map {|author| author.colorize(:red) }
236
+
237
+ # check for needed lgtm's
238
+ pull_comments = pull_request_comments(pull_request)
239
+ if pull_comments.reject {|comment| comment.user.login == github_user}.any?
240
+ open_comment_authors = find_authors_of_open_pull_request_comments(pull_request)
241
+ last_committed_at = get_commited_time(pull_request.head.sha)
242
+ lgtm_authors = comment_authors_for_pull_request(pull_request, :with => LGTM, :after => last_committed_at)
243
+
244
+ summary_data.merge!("Last comment" => pull_comments.last.body)
245
+
246
+ if lgtm_authors.any?
247
+ reviewed_by.map! { |author| lgtm_authors.include?(author.uncolorize) ? author.colorize(:green) : author }
248
+ end
249
+
250
+ notices << "[notice] You still need a LGTM from: #{open_comment_authors.join(', ')}\n" if open_comment_authors.any?
251
+ else
252
+ notices << "[notice] No one has reviewed your pull request...\n"
253
+ end
254
+
255
+ summary_data['reviewed by'] = reviewed_by.join(', ')
256
+
257
+ padding_size = summary_data.keys.max_by(&:size).size + 2
258
+ summary_data.keys.sort.each do |name|
259
+ string_format = " %-#{padding_size}s %s\n"
260
+ printf string_format, "#{name}:", summary_data[name]
261
+ end
262
+
263
+ puts "\n#{notices}" if notices != ''
264
+ end
265
+
266
+ def get_commited_time(commit_sha)
267
+ last_commit = github.repos.commits.find remote_user, remote_repo_name, commit_sha
268
+ Time.parse last_commit.commit.author[:date]
269
+ end
270
+
234
271
  # WARNING: this currently only supports OS X and UBUNTU
235
272
  def ask_to_open_in_browser(url)
236
273
  if RUBY_PLATFORM =~ /darwin|linux/i
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rspec'
3
- require 'json'
3
+ require 'multi_json'
4
4
  require 'webmock/rspec'
5
5
  require 'ruby-debug'
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_reflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-08-30 00:00:00.000000000 Z
14
+ date: 2012-09-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -110,13 +110,13 @@ dependencies:
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
- name: gli
113
+ name: colorize
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  none: false
116
116
  requirements:
117
117
  - - '='
118
118
  - !ruby/object:Gem::Version
119
- version: 2.0.0
119
+ version: 0.5.8
120
120
  type: :runtime
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
@@ -124,15 +124,15 @@ dependencies:
124
124
  requirements:
125
125
  - - '='
126
126
  - !ruby/object:Gem::Version
127
- version: 2.0.0
127
+ version: 0.5.8
128
128
  - !ruby/object:Gem::Dependency
129
- name: json_pure
129
+ name: gli
130
130
  requirement: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements:
133
133
  - - '='
134
134
  - !ruby/object:Gem::Version
135
- version: 1.7.5
135
+ version: 2.1.0
136
136
  type: :runtime
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
@@ -140,7 +140,7 @@ dependencies:
140
140
  requirements:
141
141
  - - '='
142
142
  - !ruby/object:Gem::Version
143
- version: 1.7.5
143
+ version: 2.1.0
144
144
  - !ruby/object:Gem::Dependency
145
145
  name: highline
146
146
  requirement: !ruby/object:Gem::Requirement
@@ -180,7 +180,7 @@ dependencies:
180
180
  requirements:
181
181
  - - '='
182
182
  - !ruby/object:Gem::Version
183
- version: 0.6.5
183
+ version: 0.7.0
184
184
  type: :runtime
185
185
  prerelease: false
186
186
  version_requirements: !ruby/object:Gem::Requirement
@@ -188,7 +188,7 @@ dependencies:
188
188
  requirements:
189
189
  - - '='
190
190
  - !ruby/object:Gem::Version
191
- version: 0.6.5
191
+ version: 0.7.0
192
192
  description: Git Reflow manages your git workflow.
193
193
  email:
194
194
  - dev@reenhanced.com
@@ -250,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
250
  version: '0'
251
251
  segments:
252
252
  - 0
253
- hash: -1057923408803391323
253
+ hash: -900915323995072277
254
254
  required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  none: false
256
256
  requirements:
@@ -259,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  version: '0'
260
260
  segments:
261
261
  - 0
262
- hash: -1057923408803391323
262
+ hash: -900915323995072277
263
263
  requirements: []
264
264
  rubyforge_project:
265
265
  rubygems_version: 1.8.24