Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitbucket list files fix #154

Merged
merged 2 commits into from
Feb 22, 2022
Merged

Conversation

mohitg0795
Copy link
Contributor

@mohitg0795 mohitg0795 commented Feb 21, 2022

Currently, we only return first page of list files for bitbucket. It doesn't respect the incoming page number argument.

Bitbucket works on URL based pagination. Thus, added support if incoming page request has url, then it should be used, otherwise first page response will be returned.

@@ -83,6 +83,10 @@ func (s *contentService) Delete(ctx context.Context, repo, path string, params *

func (s *contentService) List(ctx context.Context, repo, path, ref string, opts scm.ListOptions) ([]*scm.ContentInfo, *scm.Response, error) {
endpoint := fmt.Sprintf("/2.0/repositories/%s/src/%s/%s?%s", repo, ref, path, encodeListOptions(opts))
if opts.URL != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, if you look at the encodeListOptions function it allows the user to pass through a page number https://github.com/mohitg0795/go-scm/blob/21de0f1a1424e92ac3a2c34aa26519a9f1f464d2/scm/driver/bitbucket/util.go#L27

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't get respected for bitbucket. Bitbucket doesn't support page number based pagination. It only supports url based pagination. Whatever page number you may pass, it will always provide you first page of output.

Thus, not tinkering with current logic, I just added support for url based pagination. If someone provides page url, then it overrides everything and it is used to parse the results.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you provide an example of the url you would pass.
i am extremely hesitant to merge this kind of change. as the URL parameter ignores all other parameters. at this point it would be better to use a simple http request.
this makes using bitbucket totally different to other git providers, meaning end users will miss this nuance.
We are having a team meeting later and will discuss this PR then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a sample URL.
mockNextPageUri := "https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/master/packages/activity?pageLen=3&page=RPfL"

Also, I've tested it by integrating with bitbucket realtime and got this URL during that process.

Further, I'm not tampering any behaviour. I'm just enhancing current support and infact fixing current behaviour. There's no page num based support for bitbucket. It results into HTTP 500 if you pass any page number except 0. You can further read on bitbucket documentation around this API. It only supports URL based pagination. It returns next page complete URL when we try to fetch 0th page and consequently it just works recursively in same way for other pages.

Let me know if we need to come on a call to finalize on this change. Appreciate your help. Thanks.

Copy link
Member

@bradrydzewski bradrydzewski Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tphoney unlike GitHub or GitLab, Bitbucket does not support passing page numbers as query parameters for all endpoints; some endpoints require an after query parameter while others require an encoded page query parameter that is not an integer. Because pagination is not uniform across endpoints, Bitbucket includes the next url in the response body. The Bitbucket driver supports passing in this next url to list functions so that it can be used to fetch the next page in the resultset, regardless of how pagination is implemented. You can see an example here:

https://github.com/drone/go-scm/blob/master/scm/driver/bitbucket/repo.go#L99:L101
https://github.com/drone/go-scm/blob/master/scm/driver/bitbucket/testdata/repos.json#L109

In some cases the page and pagelen query parameters should work just fine (I am not sure about this particular endpoint). However, using the next url is guaranteed to always work, which means there is no harm in allowing this form of pagination for all Bitbucket list endpoints.

@tphoney
Copy link
Contributor

tphoney commented Feb 22, 2022

After the team review, this is the best solution available. Due to bitbucket.

@tphoney tphoney merged commit d3dd72e into drone:master Feb 22, 2022
@tphoney tphoney added the bug label Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants