Skip to content

fix(bitbucket): name a project when the workspace won't pick one - #131

Closed
HarshMN2345 wants to merge 10 commits into
mainfrom
fix/bitbucket-repository-project
Closed

fix(bitbucket): name a project when the workspace won't pick one#131
HarshMN2345 wants to merge 10 commits into
mainfrom
fix/bitbucket-repository-project

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

Creating a repository fails on some Bitbucket workspaces with:

Creating repository <name> failed with status code 400: You can't create repositories under this project

and the console reports only that the repository was not created.

Why

A Bitbucket repository belongs to a project — its own create form makes this explicit: "You must either select a project or create a new one." The adapter sends scm, name and is_private and no project, so Bitbucket picks the workspace default. That works where a workspace has one, which is why creation succeeds in CI and on most workspaces, and fails where it doesn't or where that default is restricted.

Change

Where Bitbucket's own error names the project as the objection, the workspace is asked for one and the create repeated with project.key. Any other failure — a name already taken, a credential without the scope to create anything — is reported unchanged, so this doesn't retry things that will not succeed.

GET /2.0/workspaces/{workspace}/projects returns values[].key; the first is used.

Not covered

The caller still can't choose which project. Doing that means carrying a project through createRepository() and offering a picker in the console, the way Bitbucket's form does — worth doing, but a larger change than unblocking creation.

A Bitbucket repository belongs to a project. Bitbucket names one itself
where the workspace has a default, which is why creating a repository has
worked, and refuses the repository where it doesn't -- leaving the console
reporting that the repository could not be created and nothing a user can do
about it.

The workspace is asked for a project and the create repeated with it, only
where Bitbucket said the project was what it objected to. A name already
taken, or a credential lacking the scope to create anything, is reported as
it was.
@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds optional Bitbucket project selection when creating a repository while preserving the shared three-argument adapter contract.

  • Adds project.key to the Bitbucket request when a concrete project key is supplied.
  • Adds live tests for explicit, omitted, and invalid project keys.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/Bitbucket.php Adds an optional Bitbucket-specific project key to repository-creation payloads without changing existing three-argument calls.
tests/VCS/Adapter/BitbucketTest.php Adds live coverage for default-project creation, explicit project assignment, and rejection of an unknown project.

Reviews (9): Last reviewed commit: "test(bitbucket): read the project key wh..." | Re-trigger Greptile

Comment thread src/VCS/Adapter/Git/Bitbucket.php Outdated
Bitbucket groups repositories under a project and asks for one when a
repository is created, which GitHub and GitLab have no equivalent of. The
caller can now name it, and the adapters that don't group repositories
ignore what they're given.
Choosing a project for the caller put the repository somewhere nobody asked
for, guessed from whichever the workspace listed first, and read the
provider's wording to decide when to guess. A workspace that wants a project
says so, and the caller now has a way to answer.
One test names the project the workspace already chose and reads it back off
the repository. The other names one the workspace doesn't hold and expects
the refusal, so a name that never left the adapter would fail it.
Comment thread src/VCS/Adapter/Git/Bitbucket.php
Comment thread src/VCS/Adapter/Git/Gitea.php Outdated
* @return array<mixed> Details of new repository
*/
public function createRepository(string $owner, string $repositoryName, bool $private): array
public function createRepository(string $owner, string $repositoryName, bool $private, string $project = ''): array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lets not add project to all adapters, unless we know it is a feature. If project is bitbucket specific concept, we need to keep it bitbucket only

Comment thread tests/VCS/Adapter/BitbucketTest.php
Comment thread src/VCS/Adapter/Git/Bitbucket.php
Comment on lines +49 to +51
// Projects are Bitbucket's alone, so they are reached off the adapter
// itself rather than through the shared contract
private Bitbucket $bitbucket;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lets try to make Appwrite PR. Curious what this casting will look like there, for bitbuket specific behaviour

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worried this will be trouble, but not sure. Maybe PHP has some magic to make it nice

@HarshMN2345

Copy link
Copy Markdown
Member Author

Not needed for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants