From 1963b415a88a7b026462ddb50285ba631f3033d5 Mon Sep 17 00:00:00 2001 From: Igor Matos Date: Tue, 10 May 2022 10:23:36 -0300 Subject: [PATCH] STEM-2986: add length parameter on fetch PR --- fastlane/Fastfile | 3 ++- .../bitbucket_fetch_pull_requests_action.rb | 17 +++++++++++------ ...bitbucket_list_comments_first_page_action.rb | 10 +++++----- .../plugin/bitbucket/helper/bitbucket_helper.rb | 4 ++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 07f3c30..2ca9b4d 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -57,7 +57,8 @@ lane :test do project_key: 'my-project', repo_slug: 'my-repo', basic_creds: "username:password", - status: "OPENED" + status: "OPENED", + length: 10 ) bitbucket_request_changes( diff --git a/lib/fastlane/plugin/bitbucket/actions/bitbucket_fetch_pull_requests_action.rb b/lib/fastlane/plugin/bitbucket/actions/bitbucket_fetch_pull_requests_action.rb index 77ec338..39ad60d 100644 --- a/lib/fastlane/plugin/bitbucket/actions/bitbucket_fetch_pull_requests_action.rb +++ b/lib/fastlane/plugin/bitbucket/actions/bitbucket_fetch_pull_requests_action.rb @@ -15,13 +15,12 @@ def self.run(params) base_url = 'https://api.bitbucket.org' end - if params[:state] then - query_params = { state: params[:state] } - else - query_params = { } - end + state = params[:state] ? params[:state] : "OPEN" + length = params[:length] ? params[:length] : 10 + + query_params = { state: state, pagelen: length } - Helper::BitbucketHelper.fetch_pull_requests(auth_header, base_url, params[:project_key], params[:repo_slug], query_params) + Helper::BitbucketHelper.fetch_pull_requests(auth_header, base_url, params[:project_key], params[:repo_slug], query_params) end def self.description @@ -86,6 +85,12 @@ def self.available_options description: "Filter pull requests by state, e.g: OPEN, MERGED or DECLINED", optional: true, type: String + ), + FastlaneCore::ConfigItem.new( + key: :length, + description: "The max number of pull requests per page to retrieve. Maximum of 100, minimum of 10", + type: Integer, + optional: true ) ] end diff --git a/lib/fastlane/plugin/bitbucket/actions/bitbucket_list_comments_first_page_action.rb b/lib/fastlane/plugin/bitbucket/actions/bitbucket_list_comments_first_page_action.rb index 5552d3a..d9b8d53 100644 --- a/lib/fastlane/plugin/bitbucket/actions/bitbucket_list_comments_first_page_action.rb +++ b/lib/fastlane/plugin/bitbucket/actions/bitbucket_list_comments_first_page_action.rb @@ -15,13 +15,13 @@ def self.run(params) base_url = 'https://api.bitbucket.org' end - if params[:lenght] then - lenght = params[:lenght] + if params[:length] then + length = params[:length] else - lenght = 100 + length = 100 end - Helper::BitbucketHelper.list_pull_request_comments(auth_header, base_url, params[:project_key], params[:repo_slug], params[:request_id], lenght) + Helper::BitbucketHelper.list_pull_request_comments(auth_header, base_url, params[:project_key], params[:repo_slug], params[:request_id], length) end def self.description @@ -87,7 +87,7 @@ def self.available_options optional: false ), FastlaneCore::ConfigItem.new( - key: :lenght, + key: :length, description: "The max number of comments per page to retrieve. Maximum of 100, minimum of 10", type: Integer, optional: true diff --git a/lib/fastlane/plugin/bitbucket/helper/bitbucket_helper.rb b/lib/fastlane/plugin/bitbucket/helper/bitbucket_helper.rb index 84f1cc0..20ab9d3 100644 --- a/lib/fastlane/plugin/bitbucket/helper/bitbucket_helper.rb +++ b/lib/fastlane/plugin/bitbucket/helper/bitbucket_helper.rb @@ -167,9 +167,9 @@ def self.comment_pull_request(access_header, baseurl, project_key, repo_slug, re }) end - def self.list_pull_request_comments(access_header, baseurl, project_key, repo_slug, request_id, lenght) + def self.list_pull_request_comments(access_header, baseurl, project_key, repo_slug, request_id, length) uri = URI.parse("#{baseurl}/2.0/repositories/#{project_key}/#{repo_slug}/pullrequests/#{request_id}/comments") - prresp = self.perform_get(uri, access_header, { pagelen: lenght }) + prresp = self.perform_get(uri, access_header, { pagelen: length }) data = JSON.parse(prresp.body) data end