Closed Style87 closed 3 years ago
Can you provide some code examples?
let response, page=1;
do {
try {
response = await bitbucketConn.repositories
.listBranches({
repo_slug: this._uuid,
workspace: this._workspaceUUID,
q: 'name~"release"',
page: page
});
} catch (e) {
let { message, error, headers, request, status } = e;
console.log(error);
console.log(request.url);
return false;
}
page++;
} while (response.data.next)
Results in
{type: "error", error: {…}}
error: {message: "Invalid page"}
type: "error"
__proto__: Object
https://api.bitbucket.org/2.0/repositories/{WORKSPACE}/{REPO_SLUG}/refs/branches?q=name~%22release%22&page=1
If I remove q: 'name~"release"'
or page: page
it works fine. I can get filtered results or paginated results but not filtered paginated results. Also for context the code above is run in a Repository class that knows it's uuid and it's workspace's uuid.
This is not an issue with this library.
If you do:
curl -s "https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches?q=name~%22issue%22&pagelen=1"
You'll see that see that if you include q
, then the next page's link Bitbucket returns is this:
"next": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches?q=name%7E%22issue%22&pagelen=1&page=67Fg"
But if you don't inlcude q
then it returns this:
"next": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches?pagelen=1&page=2"
Notice the value of page
is different. Without q
it's 2
, but with q
it's 67Fg
.
If you use q
and numerical page
value, then that error is acutally returned from the BitBucket's API:
So if you want to use the q
param and paginate, you'll have to:
page
param.page
value for the next pages by doing new URL(data.next).searchParams.get('page')
.I hope that helps.
@MunifTanjim, thanks a lot for the analysis and the code snippet. You're 100% correct and I have working code now. Secondary question is there somewhere I can donate some money to you?
Glad that it helped you.
Secondary question is there somewhere I can donate some money to you?
I'm not currently accepting any donation. But I really appreciate that you considered it. Thanks!
When calling
bitbucket.repositories.listBranches
if I pass both thepage
andq
parameters I get the errorInvalid page
. The call works fine when only thepage
orq
parameter is sent individually.