Skip to content

Instantly share code, notes, and snippets.

@hokuma
Last active June 7, 2018 05:50
Show Gist options
  • Save hokuma/eae4d695908ea8e5770e48782ef1c864 to your computer and use it in GitHub Desktop.
Save hokuma/eae4d695908ea8e5770e48782ef1c864 to your computer and use it in GitHub Desktop.
bugspots reviewer
require 'octokit'
# Hotspotの結果は、以下のようになっている
# Scanning . repo
# Found 3010 bugfix commits, with 2029 hotspots:
#
# Fixes:
# - :bug: fix xxx
# - fix yyy bug
# - zzz bug fixed
# ....
#
# Hotspots:
# 12.3429 - hoge.rb
# 10.0199 - fuga.rb
# ....
# Hotspots部分だけ正規表現でスコアとファイル名を抽出します
hotspots = []
ARGF.each do |line|
line.chomp!
result = line.match(/(\d+\.\d+) - (.*)/)
next unless result
if result[1].to_f > ENV['BUGSPOTS_SCORE_THRESHOLD'].to_i
hotspots << result[2]
end
end
result = ENV['CI_PULL_REQUEST'].match(%r{github\.com\/(.*)\/(.*)\/pull\/(\d+)$})
repo = "#{result[1]}/#{result[2]}"
number = result[3].to_i
client = Octokit::Client.new access_token: ENV['REVIEWER_BOT_TOKEN']
files = client.pull_request_files(repo, number)
modified_files = files.map do |file|
file[:filename]
end
body = <<EOF
:warning: バグ報告が多いファイルを変更しています。 :warning:
注意深くレビューしましょう。
#{(hotspots & modified_files).join("\n")}
EOF
client.add_comment(repo, number, body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment