Last active
August 29, 2015 14:22
-
-
Save june29/b7c3b37a1840c79d65c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Gem::Specification.new do |spec| | |
spec.name = "ruboty-pull-requests" | |
spec.version = "0.0.1" | |
spec.authors = ["Jun OHWADA"] | |
spec.email = ["[email protected]"] | |
spec.summary = "Access to pull requests" | |
spec.files = ["ruboty-pull-requests.rb"] | |
spec.require_path = "." | |
spec.add_dependency "octokit" | |
end |
This file contains hidden or 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 "octokit" | |
module Ruboty | |
module Handlers | |
class PullRequests < Base | |
env :GITHUB_TOKEN, "Set your token" | |
env :GITHUB_API_ENDPOINT, "Set your API endpoint" | |
env :GITHUB_REPOSITORIES, "Set target repositories" | |
on( | |
/pulls\s*(?<label>.*)/i, | |
name: "pull_requests", | |
description: "Access to pull requests" | |
) | |
def pull_requests(message) | |
label = message[:label] | |
targets = [] | |
Octokit.configure do |c| | |
c.api_endpoint = ENV['GITHUB_API_ENDPOINT'] | |
end | |
client = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN']) | |
ENV['GITHUB_REPOSITORIES'].split(",").each do |repository| | |
pulls = client.pulls(repository) | |
targets += | |
if label.empty? | |
pulls | |
else | |
pulls.select { |pr| client.labels_for_issue(repository, pr.number).map(&:name).include?(label) } | |
end | |
end | |
return if targets.empty? | |
text = label.empty? ? "Pull Request の一覧はこちら:\n\n" : "ラベル「#{label}」の付いた Pull Request はこちら:\n\n" | |
text += targets.map { |t| | |
[t.title, t.html_url].join("\n") | |
}.join("\n\n") | |
message.reply(text) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment