如何通过Bitbucket Server API获取用户拥有的所有仓库?
I get your frustration here—Bitbucket Server's API doesn't have a direct filter on the repos endpoint for user-owned repositories, and unlike some other platforms, it doesn't have a clear "owner" field tied directly to repositories. Let's break down how to work around this:
The Core Issue: Bitbucket Server's Permission Model
Bitbucket Server structures repositories under Projects, and user access is managed via permission grants rather than an explicit "owner" attribute. So to find repositories a user "owns" (we'll define this as having admin-level access, since that's the closest to ownership), we need to leverage the permissions API instead.
Step 1: Fetch the User's Repository Permissions
Use the users/{username}/permissions/repos endpoint to get all repositories the user has access to, along with their permission level:
curl -s -u YOUR-USERNAME:YOUR-PASSWORD -X GET https://bitbucket-server.domain.com/bitbucket/rest/api/1.0/users/TARGET-USERNAME/permissions/repos | jq '.values[]'
Each entry in the response will include a repository object with all the details you need (slug, name, links, etc.), plus the permission field indicating the user's access level (e.g., REPO_ADMIN, REPO_WRITE, REPO_READ).
Step 2: Filter for "Owner-Level" Repositories
If you want to narrow it down to repositories where the user has full control (the closest equivalent to "owning"), filter for REPO_ADMIN permissions with jq:
curl -s -u YOUR-USERNAME:YOUR-PASSWORD -X GET https://bitbucket-server.domain.com/bitbucket/rest/api/1.0/users/TARGET-USERNAME/permissions/repos | jq '.values[] | select(.permission == "REPO_ADMIN") | .repository'
Why Your Original Approach Didn't Work
The repos?name=apr-util call you tried only filters repositories by their name—it doesn't account for user permissions or association. That's why it returned a repository matching the name, but no user-related context.
内容的提问来源于stack exchange,提问作者Chris F

