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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c05898f2847f189f3c984ea0b7c457c0604565c303a4e993b8a8f0f0cc775123
4
- data.tar.gz: 7be76bdb1c69f2c4a8a19cd5fc2c3f89a1b910c0e81f8eac09bd094ec5a24352
3
+ metadata.gz: 2d25959af32deea019cda65a40a426fbe4a1f2855e72836c0751e0a825687376
4
+ data.tar.gz: e113acd322253daa69edfbd97f9c8bce0a33200f739cf3d080ad3cfde4119a40
5
5
  SHA512:
6
- metadata.gz: 7837c51e7f78bf656f00a9cea4b13c047818dd99f62a018a54b09cb733215f47425d1679042344fa7930c8f914d8db8cd7bfb240ddee51dbd55e3624a819b04a
7
- data.tar.gz: 0f394e3395f81189067d762c5504684fae33b3809d7f544a0380698bbcde0c2e67e3b4b890118a0924ff45038ff48680f99ad98e78c9d8851c7cb3036218282a
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 only one api:
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
- api_token = Base64.strict_encode64("#{options[:username]}:#{options[:password]}")
19
+ api_url = Helper::BitbucketCloudHelper.url(company_host_name: options[:company_host_name], repository_name: options[:repository_name], api: "pullrequests")
22
20
 
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}" }
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
- username: reviewer
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 = self.formatted_result(response)
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 usernames for the pull request. If no reviewers are passed, fails back to default ones",
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.show_message
12
- UI.message("Hello from the bitbucket_cloud plugin helper!")
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
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module BitbucketCloud
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  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.2.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-01-30 00:00:00.000000000 Z
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