Class: Fastlane::Actions::CreatePullRequestAction
- Inherits:
-
Fastlane::Action
- Object
- Fastlane::Action
- Fastlane::Actions::CreatePullRequestAction
- Defined in:
- fastlane/lib/fastlane/actions/create_pull_request.rb
Constant Summary
Constants inherited from Fastlane::Action
Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES
Documentation collapse
- .author ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .output ⇒ Object
- .return_value ⇒ Object
Class Method Summary collapse
- .add_assignees(params, number) ⇒ Object
- .add_labels(params, number) ⇒ Object
- .add_milestone(params, number) ⇒ Object
- .add_reviewers(params, number) ⇒ Object
- .run(params) ⇒ Object
Methods inherited from Fastlane::Action
action_name, authors, deprecated_notes, details, lane_context, method_missing, other_action, return_type, sample_return_value, shell_out_should_use_bundle_exec?, step_text
Class Method Details
.add_assignees(params, number) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 77 def self.add_assignees(params, number) payload = { 'assignees' => params[:assignees] } GithubApiAction.run( server_url: params[:api_url], api_token: params[:api_token], api_bearer: params[:api_bearer], http_method: 'POST', path: "repos/#{params[:repo]}/issues/#{number}/assignees", body: payload, error_handlers: { '*' => proc do |result| UI.error("GitHub responded with #{result[:status]}: #{result[:body]}") return nil end } ) end |
.add_labels(params, number) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 57 def self.add_labels(params, number) payload = { 'labels' => params[:labels] } GithubApiAction.run( server_url: params[:api_url], api_token: params[:api_token], api_bearer: params[:api_bearer], http_method: 'PATCH', path: "repos/#{params[:repo]}/issues/#{number}", body: payload, error_handlers: { '*' => proc do |result| UI.error("GitHub responded with #{result[:status]}: #{result[:body]}") return nil end } ) end |
.add_milestone(params, number) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 122 def self.add_milestone(params, number) payload = {} if params[:milestone] payload["milestone"] = params[:milestone] end GithubApiAction.run( server_url: params[:api_url], api_token: params[:api_token], api_bearer: params[:api_bearer], http_method: 'PATCH', path: "repos/#{params[:repo]}/issues/#{number}", body: payload, error_handlers: { '*' => proc do |result| UI.error("GitHub responded with #{result[:status]}: #{result[:body]}") return nil end } ) end |
.add_reviewers(params, number) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 97 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], api_bearer: params[:api_bearer], 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 |
.author ⇒ Object
240 241 242 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 240 def self. ["seei", "tommeier", "marumemomo", "elneruda", "kagemiku"] end |
.available_options ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 159 def self. [ FastlaneCore::ConfigItem.new(key: :api_token, env_name: "GITHUB_PULL_REQUEST_API_TOKEN", description: "Personal API Token for GitHub - generate one at https://github.com/settings/tokens", sensitive: true, code_gen_sensitive: true, default_value: ENV["GITHUB_API_TOKEN"], default_value_dynamic: true, conflicting_options: [:api_bearer], optional: true), FastlaneCore::ConfigItem.new(key: :api_bearer, env_name: "GITHUB_PULL_REQUEST_API_BEARER", description: "Use a Bearer authorization token. Usually generated by Github Apps, e.g. GitHub Actions GITHUB_TOKEN environment variable", sensitive: true, code_gen_sensitive: true, conflicting_options: [:api_token], optional: true, default_value: nil), FastlaneCore::ConfigItem.new(key: :repo, env_name: "GITHUB_PULL_REQUEST_REPO", description: "The name of the repository you want to submit the pull request to", optional: false), FastlaneCore::ConfigItem.new(key: :title, env_name: "GITHUB_PULL_REQUEST_TITLE", description: "The title of the pull request", optional: false), FastlaneCore::ConfigItem.new(key: :body, env_name: "GITHUB_PULL_REQUEST_BODY", description: "The contents of the pull request", optional: true), FastlaneCore::ConfigItem.new(key: :draft, env_name: "GITHUB_PULL_REQUEST_DRAFT", description: "Indicates whether the pull request is a draft", type: Boolean, optional: true), FastlaneCore::ConfigItem.new(key: :labels, env_name: "GITHUB_PULL_REQUEST_LABELS", description: "The labels for the pull request", type: Array, optional: true), FastlaneCore::ConfigItem.new(key: :milestone, env_name: "GITHUB_PULL_REQUEST_MILESTONE", description: "The milestone ID (Integer) for the pull request", type: Numeric, optional: true), FastlaneCore::ConfigItem.new(key: :head, env_name: "GITHUB_PULL_REQUEST_HEAD", description: "The name of the branch where your changes are implemented (defaults to the current branch name)", default_value: Actions.git_branch, default_value_dynamic: true, optional: true), FastlaneCore::ConfigItem.new(key: :base, env_name: "GITHUB_PULL_REQUEST_BASE", description: "The name of the branch you want your changes pulled into (defaults to `master`)", default_value: 'master', optional: true), FastlaneCore::ConfigItem.new(key: :api_url, env_name: "GITHUB_PULL_REQUEST_API_URL", description: "The URL of GitHub API - used when the Enterprise (default to `https://api.github.com`)", code_gen_default_value: 'https://api.github.com', default_value: 'https://api.github.com', 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 |
.category ⇒ Object
266 267 268 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 266 def self.category :source_control end |
.description ⇒ Object
148 149 150 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 148 def self.description "This will create a new pull request on GitHub" end |
.example_code ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 252 def self.example_code [ 'create_pull_request( api_token: "secret", # optional, defaults to ENV["GITHUB_API_TOKEN"] repo: "fastlane/fastlane", title: "Amazing new feature", head: "my-feature", # optional, defaults to current branch name base: "master", # optional, defaults to "master" body: "Please pull this in!", # optional api_url: "http://yourdomain/api/v3" # optional, for GitHub Enterprise, defaults to "https://api.github.com" )' ] end |
.is_supported?(platform) ⇒ Boolean
244 245 246 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 244 def self.is_supported?(platform) return true end |
.output ⇒ Object
152 153 154 155 156 157 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 152 def self.output [ ['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 |
.return_value ⇒ Object
248 249 250 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 248 def self.return_value "The pull request URL when successful" end |
.run(params) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'fastlane/lib/fastlane/actions/create_pull_request.rb', line 9 def self.run(params) UI.("Creating new pull request from '#{params[:head]}' to branch '#{params[:base]}' of '#{params[:repo]}'") payload = { 'title' => params[:title], 'head' => params[:head], 'base' => params[:base] } payload['body'] = params[:body] if params[:body] payload['draft'] = params[:draft] if params[:draft] GithubApiAction.run( server_url: params[:api_url], api_token: params[:api_token], api_bearer: params[:api_bearer], 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}'") # Add labels to pull request 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] # Add a milestone to pull request add_milestone(params, number) if params[:milestone] 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 |