fastlane-plugin-bitbucket_cloud 0.2.0 → 0.3.1
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 +4 -4
- data/README.md +3 -2
- data/lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb +6 -32
- data/lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_list_defaults_reviewers.rb +118 -0
- data/lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb +33 -2
- data/lib/fastlane/plugin/bitbucket_cloud/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d25959af32deea019cda65a40a426fbe4a1f2855e72836c0751e0a825687376
|
4
|
+
data.tar.gz: e113acd322253daa69edfbd97f9c8bce0a33200f739cf3d080ad3cfde4119a40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c2406fcf6ca1f2b36c3bf8be2e08c50e4ea82993245543524e6af3b3634139d80beb5f0d60f0ddeaff4ce16eccf8f3f068ed21bc28d8870f339fb2fc2bf403e
|
7
|
+
data.tar.gz: ea793b4bfc9c11a11448c575d50c7c225244c46165995c8af951b6e5673e512828cfe5e199e630c72965412152746de9e6c84584a048d3713d407887b5983b57
|
data/README.md
CHANGED
@@ -16,14 +16,15 @@ Wrapper of Bitbucket Cloud rest apis.
|
|
16
16
|
|
17
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
18
|
|
19
|
-
For now we suppor
|
19
|
+
For now we suppor the following apis:
|
20
20
|
|
21
21
|
- [Create pull request](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-post)
|
22
|
-
|
22
|
+
- [List default reviewers](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-default-reviewers-get)
|
23
23
|
|
24
24
|
For each supported api there is a plugin action available:
|
25
25
|
|
26
26
|
- bitbucket_create_pull_request
|
27
|
+
- bitbucket_list_default_reviewers
|
27
28
|
|
28
29
|
## Example
|
29
30
|
|
@@ -12,17 +12,13 @@ module Fastlane
|
|
12
12
|
def self.run(options)
|
13
13
|
require 'excon'
|
14
14
|
|
15
|
-
company_host_name = options[:company_host_name]
|
16
|
-
repository_name = options[:repository_name]
|
17
15
|
destination_branch = options[:destination_branch]
|
18
16
|
description = options[:description]
|
19
17
|
reviewers = options[:reviewers]
|
20
18
|
|
21
|
-
|
19
|
+
api_url = Helper::BitbucketCloudHelper.url(company_host_name: options[:company_host_name], repository_name: options[:repository_name], api: "pullrequests")
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
headers = { "Content-Type": "application/json", Authorization: "Basic #{api_token}" }
|
21
|
+
headers = Helper::BitbucketCloudHelper.headers(username: options[:username], password: options[:password])
|
26
22
|
|
27
23
|
payload = {
|
28
24
|
title: options[:title],
|
@@ -55,8 +51,7 @@ module Fastlane
|
|
55
51
|
unless reviewers.instance_of?(NilClass)
|
56
52
|
reviewers_obj = reviewers.map do |reviewer|
|
57
53
|
{
|
58
|
-
|
59
|
-
|
54
|
+
uuid: reviewer
|
60
55
|
}
|
61
56
|
end
|
62
57
|
payload[:reviewers] = reviewers_obj
|
@@ -68,12 +63,12 @@ module Fastlane
|
|
68
63
|
|
69
64
|
response = Excon.post(api_url, headers: headers, body: payload)
|
70
65
|
|
71
|
-
result =
|
66
|
+
result = Helper::BitbucketCloudHelper.formatted_result(response)
|
72
67
|
|
73
68
|
UI.important("Plugin Bitbucket finished with result")
|
74
69
|
UI.important(result.to_s)
|
75
70
|
|
76
|
-
Actions.lane_context[SharedValues::BITBUCKET_CREATE_PULL_REQUEST_RESULT] = formatted_context_result(response)
|
71
|
+
Actions.lane_context[SharedValues::BITBUCKET_CREATE_PULL_REQUEST_RESULT] = Helper::BitbucketCloudHelper.formatted_context_result(response)
|
77
72
|
|
78
73
|
if result[:status] != 201
|
79
74
|
error_message = "Plugin Bitbucket finished with error code #{result[:status]} #{result[:reason_phrase]}"
|
@@ -84,27 +79,6 @@ module Fastlane
|
|
84
79
|
return result
|
85
80
|
end
|
86
81
|
|
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
82
|
def self.description
|
109
83
|
"Create a new pull request inside your Bitbucket project"
|
110
84
|
end
|
@@ -167,7 +141,7 @@ module Fastlane
|
|
167
141
|
optional: true),
|
168
142
|
FastlaneCore::ConfigItem.new(key: :reviewers,
|
169
143
|
env_name: "FL_POST_BITBUCKET_PULL_REQUEST_REVIEWERS",
|
170
|
-
description: "List of reviewer's
|
144
|
+
description: "List of reviewer's uuids for the pull request. If no reviewers are passed, fails back to default ones",
|
171
145
|
type: Array,
|
172
146
|
optional: true),
|
173
147
|
FastlaneCore::ConfigItem.new(key: :source_branch,
|
@@ -0,0 +1,118 @@
|
|
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_LIST_DEFAULT_REVIEWERS_RESULT = :BITBUCKET_LIST_DEFAULT_REVIEWERS_RESULT
|
9
|
+
end
|
10
|
+
|
11
|
+
class BitbucketListDefaultReviewersAction < Action
|
12
|
+
def self.run(options)
|
13
|
+
require 'excon'
|
14
|
+
|
15
|
+
api_url = Helper::BitbucketCloudHelper.url(company_host_name: options[:company_host_name], repository_name: options[:repository_name], api: "default-reviewers")
|
16
|
+
|
17
|
+
headers = Helper::BitbucketCloudHelper.headers(username: options[:username], password: options[:password])
|
18
|
+
|
19
|
+
UI.important("Plugin Bitbucket will list all defaults reviewers")
|
20
|
+
|
21
|
+
response = Excon.get(api_url, headers: headers)
|
22
|
+
|
23
|
+
result = Helper::BitbucketCloudHelper.formatted_result(response)
|
24
|
+
|
25
|
+
UI.important("Plugin Bitbucket finished with result")
|
26
|
+
UI.important(result.to_s)
|
27
|
+
|
28
|
+
Actions.lane_context[SharedValues::BITBUCKET_LIST_DEFAULT_REVIEWERS_RESULT] = Helper::BitbucketCloudHelper.formatted_context_result(response)
|
29
|
+
|
30
|
+
if result[:status] != 200
|
31
|
+
error_message = "Plugin Bitbucket finished with error code #{result[:status]} #{result[:reason_phrase]}"
|
32
|
+
raise StandardError, error_message
|
33
|
+
end
|
34
|
+
|
35
|
+
UI.success("Successfully list all default reviewers!")
|
36
|
+
return result
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.description
|
40
|
+
"List of all defaults reviewers of pull requests"
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.details
|
44
|
+
"Wrapper of Bitbucket cloud rest apis in order to make easy integration of Bitbucket CI inside fastlane workflow"
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.authors
|
48
|
+
["Luca Tagliabue"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.available_options
|
52
|
+
[
|
53
|
+
FastlaneCore::ConfigItem.new(key: :username,
|
54
|
+
env_name: "FL_POST_BITBUCKET_PULL_REQUEST_USERNAME",
|
55
|
+
description: "Bitbucket username",
|
56
|
+
sensitive: true,
|
57
|
+
code_gen_sensitive: true,
|
58
|
+
is_string: true,
|
59
|
+
default_value: ENV.fetch("BITBUCKET_USERNAME", nil),
|
60
|
+
default_value_dynamic: true,
|
61
|
+
optional: false),
|
62
|
+
FastlaneCore::ConfigItem.new(key: :password,
|
63
|
+
env_name: "FL_POST_BITBUCKET_PULL_REQUEST_PASSWORD",
|
64
|
+
description: "Bitbucket password",
|
65
|
+
sensitive: true,
|
66
|
+
code_gen_sensitive: true,
|
67
|
+
is_string: true,
|
68
|
+
default_value: ENV.fetch("BITBUCKET_PASSWORD", nil),
|
69
|
+
default_value_dynamic: true,
|
70
|
+
optional: false),
|
71
|
+
FastlaneCore::ConfigItem.new(key: :company_host_name,
|
72
|
+
env_name: "FL_POST_BITBUCKET_PULL_REQUEST_COMPANY_HOST_NAME",
|
73
|
+
description: "Bitbucket company host name",
|
74
|
+
sensitive: true,
|
75
|
+
code_gen_sensitive: true,
|
76
|
+
is_string: true,
|
77
|
+
default_value: ENV.fetch("BITBUCKET_COMPANY_HOST_NAME", nil),
|
78
|
+
default_value_dynamic: true,
|
79
|
+
optional: false),
|
80
|
+
FastlaneCore::ConfigItem.new(key: :repository_name,
|
81
|
+
env_name: "FL_POST_BITBUCKET_PULL_REQUEST_REPOSITORY_NAME",
|
82
|
+
description: "Bitbucket repository name",
|
83
|
+
sensitive: true,
|
84
|
+
code_gen_sensitive: true,
|
85
|
+
is_string: true,
|
86
|
+
default_value: ENV.fetch("BITBUCKET_REPOSITORY_NAME", nil),
|
87
|
+
default_value_dynamic: true,
|
88
|
+
optional: false)
|
89
|
+
]
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.output
|
93
|
+
[
|
94
|
+
['BITBUCKET_LIST_DEFAULT_REVIEWERS_RESULT', 'The result of the bitbucket rest cloud api']
|
95
|
+
]
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.return_value
|
99
|
+
'The result of the bitbucket rest cloud api'
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.example_code
|
103
|
+
[
|
104
|
+
'bitbucket_list_default_reviewers(
|
105
|
+
username: "YOUR_USERNAME_HERE",
|
106
|
+
password: "YOUR_PASSWORD_HERE",
|
107
|
+
company_host_name: "YOUR_COMPANY_HOST_HERE",
|
108
|
+
repository_name: "YOUR_REPOSITORY_NAME_HERE"
|
109
|
+
)'
|
110
|
+
]
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.is_supported?(platform)
|
114
|
+
true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -8,8 +8,39 @@ module Fastlane
|
|
8
8
|
# class methods that you define here become available in your action
|
9
9
|
# as `Helper::BitbucketCloudHelper.your_method`
|
10
10
|
#
|
11
|
-
def self.
|
12
|
-
|
11
|
+
def self.url(options)
|
12
|
+
company_host_name = options[:company_host_name]
|
13
|
+
repository_name = options[:repository_name]
|
14
|
+
api = options[:api]
|
15
|
+
|
16
|
+
"https://api.bitbucket.org/2.0/repositories/#{company_host_name}/#{repository_name}/#{api}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.headers(options)
|
20
|
+
api_token = Base64.strict_encode64("#{options[:username]}:#{options[:password]}")
|
21
|
+
|
22
|
+
{ "Content-Type": "application/json", Authorization: "Basic #{api_token}" }
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.formatted_result(response)
|
26
|
+
{
|
27
|
+
status: response[:status],
|
28
|
+
reason_phrase: response[:reason_phrase],
|
29
|
+
body: response.body || "",
|
30
|
+
json: self.parse_json(response.body) || {}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.formatted_context_result(response)
|
35
|
+
"Status code: #{response[:status]}, reason: #{response[:reason_phrase]}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.parse_json(value)
|
39
|
+
require 'json'
|
40
|
+
|
41
|
+
JSON.parse(value)
|
42
|
+
rescue JSON::ParserError
|
43
|
+
nil
|
13
44
|
end
|
14
45
|
end
|
15
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastlane-plugin-bitbucket_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Tagliabue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: lu.tagliabue@reply.it
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- README.md
|
21
21
|
- lib/fastlane/plugin/bitbucket_cloud.rb
|
22
22
|
- lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb
|
23
|
+
- lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_list_defaults_reviewers.rb
|
23
24
|
- lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb
|
24
25
|
- lib/fastlane/plugin/bitbucket_cloud/version.rb
|
25
26
|
homepage: https://github.com/lukluca/fastlane-plugin-bitbucket-cloud
|