fastlane/lib/fastlane/actions/create_pull_request.rb in fastlane-2.138.0 vs fastlane/lib/fastlane/actions/create_pull_request.rb in fastlane-2.139.0
- old
+ new
@@ -1,9 +1,10 @@
module Fastlane
module Actions
module SharedValues
CREATE_PULL_REQUEST_HTML_URL = :CREATE_PULL_REQUEST_HTML_URL
+ CREATE_PULL_REQUEST_NUMBER = :CREATE_PULL_REQUEST_NUMBER
end
class CreatePullRequestAction < Action
def self.run(params)
UI.message("Creating new pull request from '#{params[:head]}' to branch '#{params[:base]}' of '#{params[:repo]}'")
@@ -37,11 +38,15 @@
add_labels(params, number) if params[:labels]
# Add assignees to pull request
add_assignees(params, number) if params[:assignees]
+ # Add reviewers to pull request
+ add_reviewers(params, number) if params[:reviewers] || params[:team_reviewers]
+
Actions.lane_context[SharedValues::CREATE_PULL_REQUEST_HTML_URL] = html_url
+ Actions.lane_context[SharedValues::CREATE_PULL_REQUEST_NUMBER] = number
return html_url
end
end
def self.add_labels(params, number)
@@ -80,21 +85,46 @@
end
}
)
end
+ def self.add_reviewers(params, number)
+ payload = {}
+ if params[:reviewers]
+ payload["reviewers"] = params[:reviewers]
+ end
+
+ if params[:team_reviewers]
+ payload["team_reviewers"] = params[:team_reviewers]
+ end
+ GithubApiAction.run(
+ server_url: params[:api_url],
+ api_token: params[:api_token],
+ http_method: 'POST',
+ path: "repos/#{params[:repo]}/pulls/#{number}/requested_reviewers",
+ body: payload,
+ error_handlers: {
+ '*' => proc do |result|
+ UI.error("GitHub responded with #{result[:status]}: #{result[:body]}")
+ return nil
+ end
+ }
+ )
+ end
+
#####################################################
# @!group Documentation
#####################################################
def self.description
"This will create a new pull request on GitHub"
end
def self.output
[
- ['CREATE_PULL_REQUEST_HTML_URL', 'The HTML URL to the created pull request']
+ ['CREATE_PULL_REQUEST_HTML_URL', 'The HTML URL to the created pull request'],
+ ['CREATE_PULL_REQUEST_NUMBER', 'The identifier number of the created pull request']
]
end
def self.available_options
[
@@ -150,15 +180,25 @@
optional: true),
FastlaneCore::ConfigItem.new(key: :assignees,
env_name: "GITHUB_PULL_REQUEST_ASSIGNEES",
description: "The assignees for the pull request",
type: Array,
+ optional: true),
+ FastlaneCore::ConfigItem.new(key: :reviewers,
+ env_name: "GITHUB_PULL_REQUEST_REVIEWERS",
+ description: "The reviewers (slug) for the pull request",
+ type: Array,
+ optional: true),
+ FastlaneCore::ConfigItem.new(key: :team_reviewers,
+ env_name: "GITHUB_PULL_REQUEST_TEAM_REVIEWERS",
+ description: "The team reviewers (slug) for the pull request",
+ type: Array,
optional: true)
]
end
def self.author
- ["seei", "tommeier", "marumemomo"]
+ ["seei", "tommeier", "marumemomo", "elneruda"]
end
def self.is_supported?(platform)
return true
end