fastlane-plugin-bitbucket_cloud 0.2.0 → 0.3.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 +4 -4
- data/README.md +3 -2
- data/lib/fastlane/plugin/bitbucket_cloud/actions/bitbucket_create_pull_request.rb +4 -29
- 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: 6fa114b7562e3079e09ae0475e4155f70dd30836e5be01f9573091e4cc83d3da
|
4
|
+
data.tar.gz: 1dcbd6681d16e0ae580e6baeef769a130eedbc206944a966b1a97a259760f05a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83073039b4add829fbaec43b56b97879b67e18412658d965b82bcb4e846aadb53b595ae4e5087f960289c0048455d7c2eeb4dc6c7e9f083b626e8bc1df3de1e3
|
7
|
+
data.tar.gz: 345af27685c2dce6976f7fdc080d26bbcba15be777dca6cf15da046638a9b594758dae13dad8535447b6e86522e56bd3c47f609efcda8894d29ea5824235fbc5
|
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],
|
@@ -68,12 +64,12 @@ module Fastlane
|
|
68
64
|
|
69
65
|
response = Excon.post(api_url, headers: headers, body: payload)
|
70
66
|
|
71
|
-
result =
|
67
|
+
result = Helper::BitbucketCloudHelper.formatted_result(response)
|
72
68
|
|
73
69
|
UI.important("Plugin Bitbucket finished with result")
|
74
70
|
UI.important(result.to_s)
|
75
71
|
|
76
|
-
Actions.lane_context[SharedValues::BITBUCKET_CREATE_PULL_REQUEST_RESULT] = formatted_context_result(response)
|
72
|
+
Actions.lane_context[SharedValues::BITBUCKET_CREATE_PULL_REQUEST_RESULT] = Helper::BitbucketCloudHelper.formatted_context_result(response)
|
77
73
|
|
78
74
|
if result[:status] != 201
|
79
75
|
error_message = "Plugin Bitbucket finished with error code #{result[:status]} #{result[:reason_phrase]}"
|
@@ -84,27 +80,6 @@ module Fastlane
|
|
84
80
|
return result
|
85
81
|
end
|
86
82
|
|
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
83
|
def self.description
|
109
84
|
"Create a new pull request inside your Bitbucket project"
|
110
85
|
end
|
@@ -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.0
|
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
|