Class: Fastlane::Actions::BitbucketCreatePullRequestAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::BitbucketCreatePullRequestAction
- Defined in:
- lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb
Class Method Summary collapse
- .authors ⇒ Object
-
.available_options ⇒ Object
rubocop:disable Metrics/MethodLength.
-
.description ⇒ Object
rubocop:enable Metrics/MethodLength.
- .details ⇒ Object
-
.example_code ⇒ Object
rubocop:disable Metrics/MethodLength.
-
.is_supported?(_platform) ⇒ Boolean
rubocop:enable Metrics/MethodLength.
- .output ⇒ Object
- .return_value ⇒ Object
-
.run(options) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
.verify_option(options) ⇒ Object
rubocop:enable Metrics/MethodLength.
Class Method Details
.authors ⇒ Object
91 92 93 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 91 def self. ['Luca Tagliabue'] end |
.available_options ⇒ Object
rubocop:disable Metrics/MethodLength
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 96 def self. [ FastlaneCore::ConfigItem.new(key: :username, env_name: 'FL_POST_BITBUCKET_PULL_REQUEST_USERNAME', description: 'Bitbucket username', sensitive: true, type: String, optional: false, verify_block: ->(value) { verify_option(key: 'username', value: value) }), FastlaneCore::ConfigItem.new(key: :password, env_name: 'FL_POST_BITBUCKET_PULL_REQUEST_PASSWORD', description: 'Bitbucket password', sensitive: true, type: String, optional: false, verify_block: ->(value) { verify_option(key: 'password', value: value) }), FastlaneCore::ConfigItem.new(key: :company_host_name, env_name: 'FL_POST_BITBUCKET_PULL_REQUEST_COMPANY_HOST_NAME', description: 'Bitbucket company host name', sensitive: true, type: String, optional: false, verify_block: ->(value) { verify_option(key: 'company_host_name', value: value) }), FastlaneCore::ConfigItem.new(key: :repository_name, env_name: 'FL_POST_BITBUCKET_PULL_REQUEST_REPOSITORY_NAME', description: 'Bitbucket repository name', sensitive: true, type: String, optional: false, verify_block: ->(value) { verify_option(key: 'repository_name', value: value) }), FastlaneCore::ConfigItem.new(key: :title, env_name: 'FL_POST_BITBUCKET_PULL_REQUEST_TITLE', description: 'Title of the pull request', type: String, optional: false, verify_block: ->(value) { verify_option(key: 'title', value: value) }), FastlaneCore::ConfigItem.new(key: :description, env_name: 'FL_POST_BITBUCKET_PULL_REQUEST_DESCRIPTION', description: 'Description of the pull request', type: String, optional: true), FastlaneCore::ConfigItem.new(key: :reviewers, env_name: 'FL_POST_BITBUCKET_PULL_REQUEST_REVIEWERS', description: "List of reviewer's uuids for the pull request. If no reviewers are passed, fails back to default ones", type: Array, optional: true), FastlaneCore::ConfigItem.new(key: :source_branch, env_name: 'FL_POST_BITBUCKET_PULL_REQUEST_SOURCE_BRANCH', description: 'Name of the source branch', type: String, optional: false), FastlaneCore::ConfigItem.new(key: :destination_branch, env_name: 'FL_POST_BITBUCKET_PULL_REQUEST_DESTINATION_BRANCH', description: 'Name of the destination branch', type: String, optional: true) ] end |
.description ⇒ Object
rubocop:enable Metrics/MethodLength
83 84 85 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 83 def self.description 'Create a new pull request inside your Bitbucket project' end |
.details ⇒ Object
87 88 89 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 87 def self.details 'Wrapper of Bitbucket cloud rest apis in order to make easy integration of Bitbucket CI inside fastlane workflow' end |
.example_code ⇒ Object
rubocop:disable Metrics/MethodLength
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 171 def self.example_code [ 'bitbucket_create_pull_request( username: "YOUR_USERNAME_HERE", password: "YOUR_PASSWORD_HERE", company_host_name: "YOUR_COMPANY_HOST_HERE", repository_name: "YOUR_REPOSITORY_NAME_HERE", title: "PULL_REQUEST_TITLE_HERE", description: "PULL_REQUEST_DESCRIPTION_HERE", reviewers: ["FIRST_REVIEWER", "SECOND_REVIEWER"], source_branch: "YOUR_SOURCE_BRANCH_HERE", destination_branch: "YOUR_DESTINATION_BRANCH_HERE" )' ] end |
.is_supported?(_platform) ⇒ Boolean
rubocop:enable Metrics/MethodLength
188 189 190 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 188 def self.is_supported?(_platform) true end |
.output ⇒ Object
160 161 162 163 164 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 160 def self.output [ ['BITBUCKET_CREATE_PULL_REQUEST_RESULT', 'The result of the bitbucket pullrequests cloud api'] ] end |
.return_value ⇒ Object
166 167 168 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 166 def self.return_value 'The result of the bitbucket pullrequests cloud api' end |
.run(options) ⇒ Object
rubocop:disable Metrics/MethodLength
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 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 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 15 def self.run() require 'excon' destination_branch = [:destination_branch] description = [:description] reviewers = [:reviewers] api_url = Helper::BitbucketCloudHelper.url(company_host_name: [:company_host_name], repository_name: [:repository_name], api: 'pullrequests') headers = Helper::BitbucketCloudHelper.headers(username: [:username], password: [:password]) payload = { title: [:title], source: { branch: { name: [:source_branch] } } } if destination_branch.instance_of?(NilClass) destination_log = '' else destination_obj = { branch: { name: destination_branch } } payload[:destination] = destination_obj destination_log = " to '#{destination_branch}'" end if description.instance_of?(NilClass) description_log = '' else payload[:description] = description description_log = " and description '#{description}'" end unless reviewers.instance_of?(NilClass) reviewers_obj = reviewers.map do |reviewer| { uuid: reviewer } end payload[:reviewers] = reviewers_obj end payload = payload.to_json UI.important("Plugin Bitbucket will create a new pull request from '#{[:source_branch]}'#{destination_log} with title '#{[:title]}'#{description_log}") response = Excon.post(api_url, headers: headers, body: payload) result = Helper::BitbucketCloudHelper.formatted_result(response) UI.important('Plugin Bitbucket finished with result') UI.important(result.to_s) Actions.lane_context[SharedValues::BITBUCKET_CREATE_PULL_REQUEST_RESULT] = Helper::BitbucketCloudHelper.formatted_context_result(response) Helper::BitbucketCloudHelper.check_result(result: result, status: 201) UI.success('Successfully create a new Bitbucket pull request!') result end |
.verify_option(options) ⇒ Object
rubocop:enable Metrics/MethodLength
156 157 158 |
# File 'lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb', line 156 def self.verify_option() UI.user_error!("No value found for '#{[:key]}'") if [:value].to_s.empty? end |