MunifTanjim / node-bitbucket

Bitbucket API client for Browser and Node.js
https://bitbucketjs.netlify.app
MIT License
106 stars 28 forks source link

listRepositories returns only public results #49

Closed liorke closed 4 years ago

liorke commented 4 years ago

Hi, trying to use the following method, but failed to retrieve any private repos, only public ones.

Trying to use the official API works well, so it looks like something might be wrong on the library side.

Is it a known issue? using v1.15.1 Oh, and what is "q" parameter means? what's the usage? no description in the documentation.

Thanks!

MunifTanjim commented 4 years ago

Hi @liorke,

Can you please run your script with DEBUG=bitbucket environment variable set and show me the output?

MunifTanjim commented 4 years ago

As far as I remember the q parameter was introduced to support this: https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering#querying

liorke commented 4 years ago

Hi @MunifTanjim , did what you asked, and this is the url the library generated: https://api.bitbucket.org/2.0/users/MY_USERNAME/repositories?access_token=SOME_ACCESS_TOKEN&pagelen=100&sort=updated_on which returned only public repositories.

notice that your endpoint is different from that one bitbucket.org/!api/2.0/repositories/MY_USERNAME which returns both public and private ones. any chance that might be the case?

MunifTanjim commented 4 years ago

Are you looking for this method: https://bitbucketjs.netlify.com/#api-repositories-repositories_listPublic ?

Reading through this discussion will help you in that case: https://github.com/MunifTanjim/node-bitbucket/issues/28

Let me know if you still have any confusion...

liorke commented 4 years ago

Hi @MunifTanjim, I read the discussion, but falied to understand how can it assist me. What I'm looking for is a way to fetch all the repos user have access to (public + private). Based on the following, I'm using the following code: let repos = await bitbucket.users.listRepositories({ page, pagelen, q, sort, username }) but gets in return only the public ones, which is partial result since I expected both public and private, as mentioned in the documentation:

All repositories owned by a user/team. This includes private repositories, but filtered down to the ones that the calling user has access to

any suggestions?

MunifTanjim commented 4 years ago

You are using users.listRepositories and it calls the /users/{username}/repositories endpoint.

did what you asked, and this is the url the library generated: https://api.bitbucket.org/2.0/users/MY_USERNAME/repositories?access_token=SOME_ACCESS_TOKEN&pagelen=100&sort=updated_on which returned only public repositories.

That's expected. If that api endpoint doesn't do what you want, this library can't help you with that.

notice that your endpoint is different from that one bitbucket.org/!api/2.0/repositories/MY_USERNAME which returns both public and private ones. any chance that might be the case?

If you want /repositories/MY_USERNAME endpoint, use respositories.list method. That will hit your desired endpoint.

liorke commented 4 years ago

Thank you @MunifTanjim , using respositories.list really solves the case. Although I would like to understand why using users.listRepositories doesn't good as well? As far as I understand the documentation, it says:

All repositories owned by a user/team. This includes private repositories, but filtered down to the ones that the calling user has access to

means, using this endpoint should have return both public and private ones, just like the second endpoint you suggested

MunifTanjim commented 4 years ago

Although I would like to understand why using users.listRepositories doesn't good as well?

Either it's a bug in Bitbucket's API or their documentation is wrong :man_shrugging: