Class: Fastlane::Actions::CreatePullRequestAction
- Inherits:
-
Fastlane::Action
- Object
- Fastlane::Action
- Fastlane::Actions::CreatePullRequestAction
- Defined in:
- lib/fastlane/actions/create_pull_request.rb
Constant Summary
Constants inherited from Fastlane::Action
Fastlane::Action::AVAILABLE_CATEGORIES
Documentation collapse
- .author ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
Class Method Summary collapse
Methods inherited from Fastlane::Action
action_name, authors, details, lane_context, method_missing, other_action, output, return_value, sample_return_value, sh, step_text
Class Method Details
.author ⇒ Object
91 92 93 |
# File 'lib/fastlane/actions/create_pull_request.rb', line 91 def self. ["seei"] end |
.available_options ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fastlane/actions/create_pull_request.rb', line 48 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", is_string: true, optional: false), 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", is_string: true, optional: false), FastlaneCore::ConfigItem.new(key: :title, env_name: "GITHUB_PULL_REQUEST_TITLE", description: "The title of the pull request", is_string: true, optional: false), FastlaneCore::ConfigItem.new(key: :body, env_name: "GITHUB_PULL_REQUEST_BODY", description: "The contents of the pull request", is_string: true, 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)", is_string: true, default_value: Actions.git_branch, 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`)", is_string: true, 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`)", is_string: true, default_value: 'https://api.github.com', optional: true) ] end |
.category ⇒ Object
113 114 115 |
# File 'lib/fastlane/actions/create_pull_request.rb', line 113 def self.category :source_control end |
.description ⇒ Object
44 45 46 |
# File 'lib/fastlane/actions/create_pull_request.rb', line 44 def self.description "This will create a new pull request on GitHub" end |
.example_code ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fastlane/actions/create_pull_request.rb', line 99 def self.example_code [ 'create_pull_request( api_token: ENV["GITHUB_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
95 96 97 |
# File 'lib/fastlane/actions/create_pull_request.rb', line 95 def self.is_supported?(platform) return true end |
.run(params) ⇒ Object
8 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 |
# File 'lib/fastlane/actions/create_pull_request.rb', line 8 def self.run(params) require 'excon' require 'base64' UI.("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 = { 'title' => params[:title], 'head' => params[:head], 'base' => params[:base] } 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'] 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]}") end end |