-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRakefile
More file actions
56 lines (46 loc) · 1.55 KB
/
Rakefile
File metadata and controls
56 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
$LOAD_PATH.unshift(__dir__)
require "date"
require "slack-ruby-client"
require "reviewbot/github"
unless ENV["RACK_ENV"] == "production"
require "dotenv"
Dotenv.load
end
Slack.configure do |config|
config.token = ENV["SLACK_API_TOKEN"]
raise "Missing ENV[\"SLACK_API_TOKEN\"]" unless config.token
end
desc "Posts reviewable pull requests into a channel"
task :post_reviewable_pull_requests, %i[repositories channel labels] do |_, args|
today = Date.today
if today.saturday? || today.sunday?
puts "Not posting on the weekend"
next
end
slack_client = Slack::Web::Client.new
github = ReviewBot::GitHub.new
repositories = args.repositories.split("+")
channel = args.channel
labels = args.labels&.split("+")
need_review = github.reviewable_pull_requests(repositories: repositories, labels: labels)[:need_review]
if need_review.empty?
slack_client.chat_postMessage(channel: channel, text: "There are no pull requests that need to be reviewed.", as_user: true)
next
end
slack_client.chat_postMessage(channel: channel, text: "The following pull requests need to be reviewed:", as_user: true)
need_review.each do |pull_request|
slack_client.chat_postMessage(
channel: channel,
as_user: true,
attachments: [
{
fallback: "##{pull_request.number} - #{pull_request.title}:\n#{pull_request.html_url}",
title: "##{pull_request.number}",
text: "#{pull_request.title}:\n#{pull_request.html_url}",
color: "#03b70b"
}
]
)
end
end