lib/ruboty/github/actions/create_pull_request.rb in ruboty-qiita-github-0.2.3 vs lib/ruboty/github/actions/create_pull_request.rb in ruboty-qiita-github-0.3.0
- old
+ new
@@ -1,29 +1,38 @@
+# frozen_string_literal: true
+
module Ruboty
module Github
module Actions
class CreatePullRequest < Base
def call
if has_access_token?
- create
+ create_with_error_handling
else
require_access_token
end
+ # Action handlers should return truthy value to tell ruboty that the given message has been handled.
+ # Otherwise, ruboty tries to execute other handlers.
+ true
end
private
- def create
- message.reply("Created #{pull_request.html_url}")
+ def create_with_error_handling
+ create
rescue Octokit::Unauthorized
- message.reply("Failed in authentication (401)")
+ message.reply('Failed in authentication (401)')
rescue Octokit::NotFound
- message.reply("Could not find that repository")
- rescue => exception
- message.reply("Failed by #{exception.class} #{exception}")
+ message.reply('Could not find that repository')
+ rescue StandardError => e
+ message.reply("Failed by #{e.class} #{e}")
end
+ def create
+ message.reply("Created #{pull_request.html_url}")
+ end
+
def pull_request
client.create_pull_request(repository, base, head, title, body)
end
def title
@@ -35,35 +44,35 @@
message[:from]
end
# e.g. alice
def from_user
- from.split("/").first
+ from.split('/').first
end
# e.g. test
def from_branch
- from.split(":").last
+ from.split(':').last
end
# e.g. bob/foo:master
def to
message[:to]
end
# e.g. bob/foo
def repository
- to.split(":").first
+ to.split(':').first
end
# e.g. alice:test
def head
"#{from_user}:#{from_branch}"
end
# e.g. master
def base
- to.split(":").last
+ to.split(':').last
end
end
end
end
end