Skip to content

Commit

Permalink
Merge pull request #5 from natura-cosmeticos/STEM-2986-pagelen-on-fet…
Browse files Browse the repository at this point in the history
…ch-prs-action

STEM-2986: add parameter pagelen on fetch PRs action
  • Loading branch information
dbnaza authored May 10, 2022
2 parents da53c2c + 1963b41 commit e55b259
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/fastlane/plugin/bitbucket/helper/bitbucket_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e55b259

Please sign in to comment.