fastlane-plugin-bitbucket_cloud 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c67a44a51b40e1eca66f0e0d478dd94bc57dc765d1373b838e8b0d74f67a346b
4
+ data.tar.gz: e8bf1dd71648b723852afcc1aaf41200064c05d186af4aae94b6f80b2faabf77
5
+ SHA512:
6
+ metadata.gz: f51e2ed8c96c7bbeed313dc8fd8ce8ed5a04e308121448183666ae2b050b31ad040664742736b97615650f3f987a833c742d56a2a97c339c842d4f52f2c444e3
7
+ data.tar.gz: '094eba38fe354d5782f7205c409f0cc721674513e10ec6ccbfa7bfc37132c7fe850c72c6821a1dbad023593b334e77d8cc9f7066f87f3d3d4f1d47007d9e3c3f'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Luca Tagliabue <lu.tagliabue@reply.it>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # bitbucket-cloud plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-bitbucket-cloud)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-bitbucket`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin bitbucket-cloud
11
+ ```
12
+
13
+ ## About bitbucket-cloud
14
+
15
+ Wrapper of Bitbucket Cloud rest apis.
16
+
17
+ The aim of this plugin is to wrap the api listed in this [wiki](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication).
18
+
19
+ For now we suppor only one api:
20
+
21
+ - [Create pull request](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-post)
22
+
23
+
24
+ For each supported api there is a plugin action available:
25
+
26
+ - bitbucket_create_pull_request
27
+
28
+ ## Example
29
+
30
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test_create_pull_request`.
31
+
32
+ ## Run tests for this plugin
33
+
34
+ To run both the tests, and code style validation, run
35
+
36
+ ```
37
+ rake
38
+ ```
39
+
40
+ To automatically fix many of the styling issues, use
41
+ ```
42
+ rubocop -a
43
+ ```
44
+
45
+ ## Issues and Feedback
46
+
47
+ For any other issues and feedback about this plugin, please submit it to this repository.
48
+
49
+ ## Troubleshooting
50
+
51
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
52
+
53
+ ## Using _fastlane_ Plugins
54
+
55
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
56
+
57
+ ## About _fastlane_
58
+
59
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,217 @@
1
+ require 'fastlane/action'
2
+ require 'fastlane_core'
3
+ require_relative '../helper/bitbucket_cloud_helper'
4
+
5
+ module Fastlane
6
+ module Actions
7
+ module SharedValues
8
+ BITBUCKET_CREATE_PULL_REQUEST_RESULT = :BITBUCKET_CREATE_PULL_REQUEST_RESULT
9
+ end
10
+
11
+ class BitbucketCreatePullRequestAction < Action
12
+ def self.run(options)
13
+ require 'excon'
14
+
15
+ company_host_name = options[:company_host_name]
16
+ repository_name = options[:repository_name]
17
+ destination_branch = options[:destination_branch]
18
+ description = options[:description]
19
+ reviewers = options[:reviewers]
20
+
21
+ api_token = Base64.strict_encode64("#{options[:username]}:#{options[:password]}")
22
+
23
+ api_url = "https://api.bitbucket.org/2.0/repositories/#{company_host_name}/#{repository_name}/pullrequests"
24
+
25
+ headers = { "Content-Type": "application/json", Authorization: "Basic #{api_token}" }
26
+
27
+ payload = {
28
+ title: options[:title],
29
+ source: {
30
+ branch: {
31
+ name: options[:source_branch]
32
+ }
33
+ }
34
+ }
35
+
36
+ if destination_branch.instance_of?(NilClass)
37
+ destination_log = ""
38
+ else
39
+ destination_obj = {
40
+ branch: {
41
+ name: destination_branch
42
+ }
43
+ }
44
+ payload[:destination] = destination_obj
45
+ destination_log = " to '#{destination_branch}'"
46
+ end
47
+
48
+ if description.instance_of?(NilClass)
49
+ description_log = ""
50
+ else
51
+ payload[:description] = description
52
+ description_log = " and description '#{description}'"
53
+ end
54
+
55
+ unless reviewers.instance_of?(NilClass)
56
+ reviewers_obj = reviewers.map do |reviewer|
57
+ {
58
+ username: reviewer
59
+
60
+ }
61
+ end
62
+ payload[:reviewers] = reviewers_obj
63
+ end
64
+
65
+ payload = payload.to_json
66
+
67
+ UI.important("Plugin Bitbucket will create a new pull request from '#{options[:source_branch]}'#{destination_log} with title '#{options[:title]}'#{description_log}")
68
+
69
+ response = Excon.post(api_url, headers: headers, body: payload)
70
+
71
+ result = self.formatted_result(response)
72
+
73
+ UI.important("Plugin Bitbucket finished with result")
74
+ UI.important(result.to_s)
75
+
76
+ Actions.lane_context[SharedValues::BITBUCKET_CREATE_PULL_REQUEST_RESULT] = formatted_context_result(response)
77
+
78
+ if result[:status] != 201
79
+ error_message = "Plugin Bitbucket finished with error code #{result[:status]} #{result[:reason_phrase]}"
80
+ raise StandardError, error_message
81
+ end
82
+
83
+ UI.success("Successfully create a new Bitbucket pull request!")
84
+ return result
85
+ end
86
+
87
+ def self.formatted_result(response)
88
+ {
89
+ status: response[:status],
90
+ reason_phrase: response[:reason_phrase],
91
+ body: response.body || "",
92
+ json: self.parse_json(response.body) || {}
93
+ }
94
+ end
95
+
96
+ def self.formatted_context_result(response)
97
+ "Status code: #{response[:status]}, reason: #{response[:reason_phrase]}"
98
+ end
99
+
100
+ def self.parse_json(value)
101
+ require 'json'
102
+
103
+ JSON.parse(value)
104
+ rescue JSON::ParserError
105
+ nil
106
+ end
107
+
108
+ def self.description
109
+ "Create a new pull request inside your Bitbucket project"
110
+ end
111
+
112
+ def self.details
113
+ "Wrapper of Bitbucket cloud rest apis in order to make easy integration of Bitbucket CI inside fastlane workflow"
114
+ end
115
+
116
+ def self.authors
117
+ ["Luca Tagliabue"]
118
+ end
119
+
120
+ def self.available_options
121
+ [
122
+ FastlaneCore::ConfigItem.new(key: :username,
123
+ env_name: "FL_POST_BITBUCKET_PULL_REQUEST_USERNAME",
124
+ description: "Bitbucket username",
125
+ sensitive: true,
126
+ code_gen_sensitive: true,
127
+ is_string: true,
128
+ default_value: ENV.fetch("BITBUCKET_USERNAME", nil),
129
+ default_value_dynamic: true,
130
+ optional: false),
131
+ FastlaneCore::ConfigItem.new(key: :password,
132
+ env_name: "FL_POST_BITBUCKET_PULL_REQUEST_PASSWORD",
133
+ description: "Bitbucket password",
134
+ sensitive: true,
135
+ code_gen_sensitive: true,
136
+ is_string: true,
137
+ default_value: ENV.fetch("BITBUCKET_PASSWORD", nil),
138
+ default_value_dynamic: true,
139
+ optional: false),
140
+ FastlaneCore::ConfigItem.new(key: :company_host_name,
141
+ env_name: "FL_POST_BITBUCKET_PULL_REQUEST_COMPANY_HOST_NAME",
142
+ description: "Bitbucket company host name",
143
+ sensitive: true,
144
+ code_gen_sensitive: true,
145
+ is_string: true,
146
+ default_value: ENV.fetch("BITBUCKET_COMPANY_HOST_NAME", nil),
147
+ default_value_dynamic: true,
148
+ optional: false),
149
+ FastlaneCore::ConfigItem.new(key: :repository_name,
150
+ env_name: "FL_POST_BITBUCKET_PULL_REQUEST_REPOSITORY_NAME",
151
+ description: "Bitbucket repository name",
152
+ sensitive: true,
153
+ code_gen_sensitive: true,
154
+ is_string: true,
155
+ default_value: ENV.fetch("BITBUCKET_REPOSITORY_NAME", nil),
156
+ default_value_dynamic: true,
157
+ optional: false),
158
+ FastlaneCore::ConfigItem.new(key: :title,
159
+ env_name: "FL_POST_BITBUCKET_PULL_REQUEST_TITLE",
160
+ description: "Title of the pull request",
161
+ is_string: true,
162
+ optional: false),
163
+ FastlaneCore::ConfigItem.new(key: :description,
164
+ env_name: "FL_POST_BITBUCKET_PULL_REQUEST_DESCRIPTION",
165
+ description: "Description of the pull request",
166
+ is_string: true,
167
+ optional: true),
168
+ FastlaneCore::ConfigItem.new(key: :reviewers,
169
+ env_name: "FL_POST_BITBUCKET_PULL_REQUEST_REVIEWERS",
170
+ description: "List of reviewer's usernames for the pull request. If no reviewers are passed, fails back to default ones",
171
+ type: Array,
172
+ optional: true),
173
+ FastlaneCore::ConfigItem.new(key: :source_branch,
174
+ env_name: "FL_POST_BITBUCKET_PULL_REQUEST_SOURCE_BRANCH",
175
+ description: "Name of the source branch",
176
+ is_string: true,
177
+ optional: false),
178
+ FastlaneCore::ConfigItem.new(key: :destination_branch,
179
+ env_name: "FL_POST_BITBUCKET_PULL_REQUEST_DESTINATION_BRANCH",
180
+ description: "Name of the destination branch",
181
+ is_string: true,
182
+ optional: true)
183
+ ]
184
+ end
185
+
186
+ def self.output
187
+ [
188
+ ['BITBUCKET_CREATE_PULL_REQUEST_RESULT', 'The result of the bitbucket rest cloud api']
189
+ ]
190
+ end
191
+
192
+ def self.return_value
193
+ 'The result of the bitbucket rest cloud api'
194
+ end
195
+
196
+ def self.example_code
197
+ [
198
+ 'bitbucket_create_pull_request(
199
+ username: "YOUR_USERNAME_HERE",
200
+ password: "YOUR_PASSWORD_HERE",
201
+ company_host_name: "YOUR_COMPANY_HOST_HERE",
202
+ repository_name: "YOUR_REPOSITORY_NAME_HERE",
203
+ title: "PULL_REQUEST_TITLE_HERE",
204
+ description: "PULL_REQUEST_DESCRIPTION_HERE",
205
+ reviewers: ["FIRST_REVIEWER", "SECOND_REVIEWER"],
206
+ source_branch: "YOUR_SOURCE_BRANCH_HERE",
207
+ destination_branch: "YOUR_DESTINATION_BRANCH_HERE"
208
+ )'
209
+ ]
210
+ end
211
+
212
+ def self.is_supported?(platform)
213
+ true
214
+ end
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane_core/ui/ui'
2
+
3
+ module Fastlane
4
+ UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
5
+
6
+ module Helper
7
+ class BitbucketCloudHelper
8
+ # class methods that you define here become available in your action
9
+ # as `Helper::BitbucketCloudHelper.your_method`
10
+ #
11
+ def self.show_message
12
+ UI.message("Hello from the bitbucket_cloud plugin helper!")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module BitbucketCloud
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/bitbucket_cloud/version'
2
+
3
+ module Fastlane
4
+ module BitbucketCloud
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::BitbucketCloud.all_classes.each do |current|
15
+ require current
16
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-bitbucket_cloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luca Tagliabue
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: lu.tagliabue@reply.it
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - README.md
21
+ - lib/fastlane/plugin/bitbucket_cloud.rb
22
+ - lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb
23
+ - lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb
24
+ - lib/fastlane/plugin/bitbucket_cloud/version.rb
25
+ homepage:
26
+ licenses:
27
+ - MIT
28
+ metadata:
29
+ rubygems_mfa_required: 'true'
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '2.6'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.5.5
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Wrapper of Bitbucket cloud rest apis
49
+ test_files: []