Last active
October 11, 2016 02:54
-
-
Save tondol/062bd7961daa2b70d53c8400bd273fde to your computer and use it in GitHub Desktop.
Slackレビュー催促BOT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# A sample Gemfile | |
source "https://rubygems.org" | |
# gem "rails" | |
gem "slack-api" | |
gem "slack-incoming-webhooks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'open-uri' | |
require 'pp' | |
require 'slack/incoming/webhooks' | |
# TODO: GitHubの設定 | |
GHUserId = "tondol" | |
GHToken = "xxxx" | |
GHIssuesUrl = "https://api.github.com/repos/xxxx/xxxx/issues" | |
GHWebHookUrl = "https://hooks.slack.com/services/xxxx/xxxx/xxxx" | |
# TODO: GitHub IDとslack IDの対応 | |
id_map = { | |
Nonchalant: "ihara" | |
} | |
lines = [] | |
issues = JSON.parse(open(GHIssuesUrl, {http_basic_authentication: [GHUserId, GHToken]}).read) | |
issues.each {|issue| | |
next if issue["labels"].none? {|label| label["name"] == "レビュー待ち" } | |
next unless issue["pull_request"] | |
pr = issue["pull_request"] | |
if issue["assignees"] && issue["assignees"].size > 0 | |
ids = issue["assignees"].map {|user| | |
id = user["login"] | |
next if issue["body"] =~ /-\s*\[x\]\s*@#{id}\s*/ | |
id = id_map[id.to_sym] if id_map[id.to_sym] | |
"<@#{id}>" | |
}.compact.join(" ") | |
link = pr["html_url"] | |
lines << "#{ids}: #{link}" | |
end | |
} | |
exit if lines.empty? | |
body = "下記のプルリクがレビュー未完了のようでした。よろしくお願いいたします!!\n#{lines.join("\n")}" | |
if ARGV.first && ARGV.first.include?("-f") | |
slack = Slack::Incoming::Webhooks.new GHWebHookUrl | |
slack.post body | |
else | |
puts body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment