fastlane/lib/fastlane/actions/create_pull_request.rb in fastlane-2.50.0.beta.20170731010002 vs fastlane/lib/fastlane/actions/create_pull_request.rb in fastlane-2.50.0

- old
+ new

@@ -4,38 +4,39 @@ CREATE_PULL_REQUEST_HTML_URL = :CREATE_PULL_REQUEST_HTML_URL end class CreatePullRequestAction < Action def self.run(params) - require 'excon' - require 'base64' - UI.message("Creating new pull request from '#{params[:head]}' to branch '#{params[:base]}' of '#{params[:repo]}'") - url = "#{params[:api_url]}/repos/#{params[:repo]}/pulls" - headers = { 'User-Agent' => 'fastlane-create_pull_request' } - headers['Authorization'] = "Basic #{Base64.strict_encode64(params[:api_token])}" if params[:api_token] - - data = { + payload = { 'title' => params[:title], 'head' => params[:head], 'base' => params[:base] } + payload['body'] = params[:body] if params[:body] - data['body'] = params[:body] if params[:body] - - response = Excon.post(url, headers: headers, body: data.to_json) - - if response[:status] == 201 - body = JSON.parse(response.body) - number = body['number'] - html_url = body['html_url'] + GithubApiAction.run( + server_url: params[:api_url], + api_token: params[:api_token], + http_method: 'POST', + path: "repos/#{params[:repo]}/pulls", + body: payload, + error_handlers: { + '*' => proc do |result| + UI.error("GitHub responded with #{result[:status]}: #{result[:body]}") + return nil + end + } + ) do |result| + json = result[:json] + number = json['number'] + html_url = json['html_url'] UI.success("Successfully created pull request ##{number}. You can see it at '#{html_url}'") Actions.lane_context[SharedValues::CREATE_PULL_REQUEST_HTML_URL] = html_url - elsif response[:status] != 200 - UI.error("GitHub responded with #{response[:status]}: #{response[:body]}") + return json end end ##################################################### # @!group Documentation @@ -89,14 +90,18 @@ optional: true) ] end def self.author - ["seei"] + ["seei", "tommeier"] end def self.is_supported?(platform) return true + end + + def self.return_value + "The parsed JSON when successful" end def self.example_code [ 'create_pull_request(