Skip to content

Commit

Permalink
Colorized output and fixed issue with lgtm lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentino committed Sep 14, 2012
1 parent 7497a85 commit 26b5a64
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
22 changes: 11 additions & 11 deletions Gemfile.lock
@@ -1,12 +1,12 @@
PATH
remote: .
specs:
git_reflow (0.2.1)
github_api (= 0.6.5)
gli (= 2.0.0)
git_reflow (0.2.2)
colorize (= 0.5.8)
github_api (= 0.7.0)
gli (= 2.1.0)
highline
httpclient
json_pure (= 1.7.5)

GEM
remote: http://rubygems.org/
Expand All @@ -17,9 +17,10 @@ GEM
cucumber (>= 1.1.1)
ffi (>= 1.0.11)
rspec (>= 2.7.0)
builder (3.0.0)
builder (3.1.3)
childprocess (0.3.5)
ffi (~> 1.0, >= 1.0.6)
colorize (0.5.8)
crack (0.3.1)
cucumber (1.2.1)
builder (>= 2.1.2)
Expand All @@ -33,15 +34,15 @@ GEM
gherkin (2.11.2)
json (>= 1.4.6)
git (1.2.5)
github_api (0.6.5)
github_api (0.7.0)
faraday (~> 0.8.1)
hashie (~> 1.2.0)
multi_json (~> 1.3)
nokogiri (~> 1.5.2)
oauth2
gli (2.0.0)
gli (2.1.0)
hashie (1.2.0)
highline (1.6.14)
highline (1.6.15)
httpauth (0.1)
httpclient (2.2.7)
jeweler (1.8.4)
Expand All @@ -50,7 +51,6 @@ GEM
rake
rdoc
json (1.7.5)
json_pure (1.7.5)
jwt (0.1.5)
multi_json (>= 1.0)
multi_json (1.3.6)
Expand All @@ -71,10 +71,10 @@ GEM
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.2)
rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.2)
webmock (1.8.9)
webmock (1.8.10)
addressable (>= 2.2.7)
crack (>= 0.1.7)

Expand Down
6 changes: 3 additions & 3 deletions git_reflow.gemspec
Expand Up @@ -23,10 +23,10 @@ spec = Gem::Specification.new do |s|
s.add_development_dependency('aruba', '~> 0.4.6')
s.add_development_dependency('jeweler')
s.add_development_dependency('webmock')
s.add_dependency('gli', '2.0.0')
s.add_dependency('json_pure', '1.7.5')
s.add_dependency('colorize', '0.5.8')
s.add_dependency('gli', '2.1.0')
s.add_dependency('highline')
s.add_dependency('httpclient')
s.add_dependency('github_api', '0.6.5')
s.add_dependency('github_api', '0.7.0')
s.post_install_message = "You need to setup your GitHub OAuth token\nPlease run 'git-reflow setup'"
end
41 changes: 28 additions & 13 deletions lib/git_reflow.rb
@@ -1,10 +1,11 @@
require 'rubygems'
require 'rake'
require 'json/pure'
require 'open-uri'
require "highline/import"
require 'httpclient'
require 'github_api'
require 'json/pure'
require 'colorize'

module GitReflow
extend self
Expand Down Expand Up @@ -130,7 +131,6 @@ def get_first_commit_message
`git log --pretty=format:"%s" --no-merges -n 1`.strip
end

private

def set_oauth_token(oauth_token)
`git config --global --replace-all github.oauth-token #{oauth_token}`
Expand Down Expand Up @@ -188,21 +188,26 @@ def find_authors_of_open_pull_request_comments(pull_request)
# first we'll gather all the authors that have commented on the pull request
all_comments = pull_request_comments(pull_request)
comment_authors = comment_authors_for_pull_request(pull_request)
lgtm_authors = []

# now we need to check that all the commented authors have given a lgtm after the last commit
all_comments.each do |comment|
next unless comment_authors.include?(comment.user.login)
pull_last_committed_at = Time.parse pull_request.head.repo.updated_at
pull_last_committed_at = get_commited_time(pull_request.head.sha)
comment_created_at = Time.parse(comment.created_at)
if comment_created_at > pull_last_committed_at
if comment.body =~ LGTM
comment_authors -= [comment.user.login]
if comment[:body] =~ LGTM
lgtm_authors << comment.user.login
else
comment_authors << comment.user.login unless comment_authors.include?(comment.user.login)
end
else
comment_authors -= [comment.user.login] if comment_authors.include?(comment.user.login)
end
end

comment_authors -= lgtm_authors

comment_authors || []
end

Expand All @@ -212,7 +217,7 @@ def comment_authors_for_pull_request(pull_request, options = {})

all_comments.each do |comment|
next if options[:after] and Time.parse(comment.created_at) < options[:after]
comment_authors << comment.user.login if !comment_authors.include?(comment.user.login) and (options[:with].nil? or comment.body =~ options[:with])
comment_authors << comment.user.login if !comment_authors.include?(comment.user.login) and (options[:with].nil? or comment[:body] =~ options[:with])
end

# remove the current user from the list to check
Expand All @@ -223,34 +228,44 @@ def display_pull_request_summary(pull_request)
summary_data = {
"branches" => "#{pull_request.head.label} -> #{pull_request.base.label}",
"number" => pull_request.number,
"url" => pull_request.html_url,
"reviewed by" => (comment_authors_for_pull_request(pull_request).join(", ") || "nobody")
"url" => pull_request.html_url
}

notices = ""
reviewed_by = comment_authors_for_pull_request(pull_request).map {|author| author.colorize(:red) }

# check for needed lgtm's
pull_comments = pull_request_comments(pull_request)
if pull_comments.any?
if pull_comments.reject {|comment| comment.user.login == github_user}.any?
open_comment_authors = find_authors_of_open_pull_request_comments(pull_request)
last_committed_at = Time.parse pull_request.head.repo.updated_at
last_committed_at = get_commited_time(pull_request.head.sha)
lgtm_authors = comment_authors_for_pull_request(pull_request, :with => LGTM, :after => last_committed_at)

summary_data.merge!("Last comment" => pull_comments.last.body)
summary_data.merge!("LGTM given by" => "#{lgtm_authors.join(', ')}") if lgtm_authors.any?

if lgtm_authors.any?
reviewed_by.map! { |author| lgtm_authors.include?(author.uncolorize) ? author.colorize(:green) : author }
end

notices << "[notice] You still need a LGTM from: #{open_comment_authors.join(', ')}\n" if open_comment_authors.any?
else
notices << "[notice] No one has reviewed your pull request...\n"
end

padding_size = summary_data.keys.max{|a,b| a.size <=> b.size }.size + 2
summary_data['reviewed by'] = reviewed_by.join(', ')

padding_size = summary_data.keys.max_by(&:size).size + 2
summary_data.keys.sort.each do |name|
string_format = " %-#{padding_size}s %s\n"
printf string_format, "#{name}:", summary_data[name]
end

puts "\n#{notices}"
puts "\n#{notices}" if notices != ''
end

def get_commited_time(commit_sha)
last_commit = github.repos.commits.find remote_user, remote_repo_name, commit_sha
Time.parse last_commit.commit.author[:date]
end

# WARNING: this currently only supports OS X and UBUNTU
Expand Down
2 changes: 1 addition & 1 deletion lib/git_reflow/version.rb
@@ -1,3 +1,3 @@
module GitReflow
VERSION = "0.2.1"
VERSION = "0.2.2"
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
@@ -1,6 +1,6 @@
require 'rubygems'
require 'rspec'
require 'json'
require 'multi_json'
require 'webmock/rspec'
require 'ruby-debug'

Expand Down

0 comments on commit 26b5a64

Please sign in to comment.