Skip to content

Commit

Permalink
Merge pull request #11 from danielma/dma/all-emojis-all-the-time
Browse files Browse the repository at this point in the history
change: add all faces even if it's not a work hour
  • Loading branch information
Daniel Ma authored May 4, 2017
2 parents dd211af + 2340583 commit b7bce4b
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 31 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true
source 'https://rubygems.org'

gem 'awesome_print'
gem 'github_api'
gem 'rest-client'
gem 'rubocop'
gem 'timezone'
gem 'awesome_print'
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
addressable (2.4.0)
ast (2.3.0)
awesome_print (1.7.0)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
Expand Down Expand Up @@ -31,16 +32,28 @@ GEM
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
rack (1.6.4)
rainbow (2.2.1)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rubocop (0.47.1)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
thread_safe (0.3.5)
timezone (0.99.2)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
unicode-display_width (1.1.3)

PLATFORMS
ruby
Expand All @@ -49,6 +62,7 @@ DEPENDENCIES
awesome_print
github_api
rest-client
rubocop
timezone

BUNDLED WITH
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'bundler'
Bundler.setup

Expand Down
11 changes: 6 additions & 5 deletions lib/review_bot.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# frozen_string_literal: true
require 'json'
require 'github_api'
require 'rest-client'
require 'timezone'
require 'time'
require 'awesome_print'

require_relative "review_bot/hour_of_day"
require_relative "review_bot/pull_request"
require_relative "review_bot/extensions"
require_relative "review_bot/reviewer"
require_relative "review_bot/reminder"
require_relative 'review_bot/hour_of_day'
require_relative 'review_bot/pull_request'
require_relative 'review_bot/extensions'
require_relative 'review_bot/reviewer'
require_relative 'review_bot/reminder'

module ReviewBot
end
1 change: 1 addition & 0 deletions lib/review_bot/extensions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class Time
def round_to(interval)
self.class.at((to_f / interval).round * interval).utc
Expand Down
5 changes: 3 additions & 2 deletions lib/review_bot/hour_of_day.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module ReviewBot
class HourOfDay
# 8am to 5pm are work hours, so we only count the hour if it's inside that range
Expand All @@ -14,7 +15,7 @@ def self.work_hours_between(start_time, end_time, timezone)

while rounded_start_time < rounded_end_time
rounded_start_time += ONE_HOUR
work_hours += 1 if new(timezone.utc_to_local rounded_start_time).work_hour?
work_hours += 1 if new(timezone.utc_to_local(rounded_start_time)).work_hour?
end

work_hours
Expand All @@ -31,7 +32,7 @@ def work_hour?
end

def inspect
"HourOfDay(#{rounded_time.strftime("%a-%I%P")} work_hour: #{work_hour?})"
"HourOfDay(#{rounded_time.strftime('%a-%I%P')} work_hour: #{work_hour?})"
end
end
end
23 changes: 12 additions & 11 deletions lib/review_bot/pull_request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module ReviewBot
class PullRequest < SimpleDelegator
def needs_review?
Expand All @@ -9,9 +10,9 @@ def needs_first_review?
end

def reviewers
[comments_from_other_humans, reviews_from_other_humans].flatten.
map { |i| i['user']['login'] }.
uniq
[comments_from_other_humans, reviews_from_other_humans].flatten
.map { |i| i['user']['login'] }
.uniq
end

def last_touched_at
Expand All @@ -30,9 +31,9 @@ def inspect
"last touched: #{last_touched_at}",
"review_in_progress: #{review_in_progress?}",
"needs_review: #{needs_review?}",
"url: #{html_url}",
].join(", ") +
" )"
"url: #{html_url}"
].join(', ') +
' )'
end

private
Expand All @@ -57,9 +58,9 @@ def review_in_progress?
end

def last_touch
@last_touch ||= [comments_from_other_humans, reviews_from_other_humans].flatten.
sort_by { |comment_or_review| comment_or_review['created_at'] || comment_or_review['submitted_at'] }.
last
@last_touch ||= [comments_from_other_humans, reviews_from_other_humans].flatten
.sort_by { |comment_or_review| comment_or_review['created_at'] || comment_or_review['submitted_at'] }
.last
end

def repo_owner
Expand Down Expand Up @@ -92,13 +93,13 @@ def comments_from_other_humans

def reviews
# github_api doesn't support this yet
@reviews ||= (
@reviews ||= begin
conn = Faraday.new(
url: 'https://api.github.com',
headers: { Accept: 'application/vnd.github.black-cat-preview+json' }
)
JSON.parse(conn.get("/repos/#{repo_owner}/#{repo_name}/pulls/#{number}/reviews?access_token=#{ENV['GH_AUTH_TOKEN']}").body)
)
end
end

def reviews_from_humans
Expand Down
15 changes: 7 additions & 8 deletions lib/review_bot/reminder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module ReviewBot
GH = Github.new(oauth_token: ENV['GH_AUTH_TOKEN'])

Expand All @@ -18,10 +19,10 @@ def message
message + notifications.map do |notification|
[
"#{notification.pull_request.html_url} needs a",
notification.pull_request.needs_first_review? ? "first review" : "second review",
"from",
notification.suggested_reviewers.map { |r| ":#{r.slack}:" }.join(" "),
].join(" ")
notification.pull_request.needs_first_review? ? 'first review' : 'second review',
'from',
notification.suggested_reviewers.map { |r| ":#{r.slack}:" }.join(' ')
].join(' ')
end.join("\n\n")
end

Expand Down Expand Up @@ -49,9 +50,7 @@ def potential_notifications

next if work_hours_since_last_touch < app_config['hours_to_review']

suggested_reviewers = potential_reviewers.
select(&:work_hour?).
reject do |reviewer|
suggested_reviewers = potential_reviewers.reject do |reviewer|
pull.reviewers.include?(reviewer['github'])
end

Expand All @@ -60,7 +59,7 @@ def potential_notifications
OpenStruct.new(
pull_request: pull,
suggested_reviewers: suggested_reviewers,
work_hours_since_last_touch: work_hours_since_last_touch,
work_hours_since_last_touch: work_hours_since_last_touch
)
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/review_bot/reviewer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module ReviewBot
class Reviewer < OpenStruct
def work_hours_between(start_time, end_time)
Expand All @@ -9,7 +10,7 @@ def timezone
end

def work_hour?
HourOfDay.new(timezone.utc_to_local Time.now.utc).work_hour?
HourOfDay.new(timezone.utc_to_local(Time.now.utc)).work_hour?
end
end
end
7 changes: 4 additions & 3 deletions review.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'json'

CONFIG = JSON.parse(ENV['CONFIG'])
Expand All @@ -9,12 +10,12 @@ require_relative 'lib/review_bot'

desc 'Send reminders to team members to review PRs'
task :remind, [:mode] do |_t, args|
dry_run = args[:mode] == "dry"
dry_run = args[:mode] == 'dry'

puts "-- DRY RUN --\n\n" if dry_run

CONFIG.each do |app, app_config|
owner, repo = app.split("/")
owner, repo = app.split('/')
room = app_config['room']

puts "#{owner}/#{repo}"
Expand All @@ -38,7 +39,7 @@ task :remind, [:mode] do |_t, args|
channel: room,
text: message,
icon_emoji: SLACK_BOT_ICON,
username: SLACK_BOT_NAME,
username: SLACK_BOT_NAME
)
end
end
Expand Down

0 comments on commit b7bce4b

Please sign in to comment.