Skip to content

Commit

Permalink
Merge pull request #12 from danielma/dma/emojis-with-pr-title
Browse files Browse the repository at this point in the history
feat: show PR title in message
  • Loading branch information
Daniel Ma authored May 4, 2017
2 parents b89efc9 + cfd0779 commit 055e96f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/review_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_relative 'review_bot/extensions'
require_relative 'review_bot/reviewer'
require_relative 'review_bot/reminder'
require_relative 'review_bot/notification'

module ReviewBot
VERSION = '0.2.0'.freeze
Expand Down
28 changes: 28 additions & 0 deletions lib/review_bot/notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true
module ReviewBot
class Notification
def initialize(pull_request:, suggested_reviewers:)
@pull_request = pull_request
@suggested_reviewers = suggested_reviewers
end

attr_reader :pull_request, :suggested_reviewers

def message
[needs_review_from, pull_request.html_url].join("\n")
end

private

def needs_review_from
[
%("#{pull_request.title}" needs a #{needed_review_type} from),
suggested_reviewers.map(&:slack_emoji).join(' ')
].join(' ')
end

def needed_review_type
pull_request.needs_first_review? ? 'first review' : 'second review'
end
end
end
16 changes: 4 additions & 12 deletions lib/review_bot/reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ def message
return if notifications.empty?

# :smile_cat: https://github.com/danielma/reviewbot/pull/3 needs a first review from :dma: :dmas_evil_twin:
message = ":smile_cat: :wave:\n"
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(' ')
end.join("\n\n")
message_header = ":smile_cat: :wave:\n"
message_header + notifications.map(&:message).join("\n\n")
end

def app_reviewers
Expand Down Expand Up @@ -56,10 +49,9 @@ def potential_notifications

next if suggested_reviewers.empty?

OpenStruct.new(
Notification.new(
pull_request: pull,
suggested_reviewers: suggested_reviewers,
work_hours_since_last_touch: work_hours_since_last_touch
suggested_reviewers: suggested_reviewers
)
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/review_bot/reviewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ def timezone
def work_hour?
HourOfDay.new(timezone.utc_to_local(Time.now.utc)).work_hour?
end

def slack_emoji
":#{slack}:"
end
end
end

0 comments on commit 055e96f

Please sign in to comment.