From 26b5a649995e306205ae8ab8b0071288acd9318f Mon Sep 17 00:00:00 2001 From: Valentino Date: Fri, 14 Sep 2012 11:06:17 -0400 Subject: [PATCH] Colorized output and fixed issue with lgtm lookup --- Gemfile.lock | 22 ++++++++++----------- git_reflow.gemspec | 6 +++--- lib/git_reflow.rb | 41 ++++++++++++++++++++++++++------------- lib/git_reflow/version.rb | 2 +- spec/spec_helper.rb | 2 +- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2c1b400..4208196 100644 --- a/Gemfile.lock +++ b/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/ @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/git_reflow.gemspec b/git_reflow.gemspec index 009f440..a3963d5 100644 --- a/git_reflow.gemspec +++ b/git_reflow.gemspec @@ -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 diff --git a/lib/git_reflow.rb b/lib/git_reflow.rb index e7f1c5e..de94917 100644 --- a/lib/git_reflow.rb +++ b/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 @@ -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}` @@ -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 @@ -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 @@ -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 diff --git a/lib/git_reflow/version.rb b/lib/git_reflow/version.rb index 3812d11..26ab841 100644 --- a/lib/git_reflow/version.rb +++ b/lib/git_reflow/version.rb @@ -1,3 +1,3 @@ module GitReflow - VERSION = "0.2.1" + VERSION = "0.2.2" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e4575f1..f318a07 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require 'rubygems' require 'rspec' -require 'json' +require 'multi_json' require 'webmock/rspec' require 'ruby-debug'