-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore(eco): Adds a new organization create CLI command #111765
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
Merged
GabeVillalobos
merged 1 commit into
master
from
worktree-add-organization-create-cli-command
Mar 30, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import click | ||
|
|
||
| from sentry.runner.decorators import configuration | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.option("--name", required=True, help="Organization name.") | ||
| @click.option( | ||
| "--slug", | ||
| default=None, | ||
| help="URL-friendly slug. Derived from name if omitted.", | ||
| ) | ||
| @click.option("--owner-email", required=True, help="Email of the organization owner.") | ||
| @click.option( | ||
| "--no-default-team", | ||
| default=False, | ||
| is_flag=True, | ||
| help="Skip creating a default team.", | ||
| ) | ||
| @configuration | ||
| def createorg( | ||
| name: str, | ||
| slug: str | None, | ||
| owner_email: str, | ||
| no_default_team: bool, | ||
| ) -> None: | ||
| "Create a new organization." | ||
|
|
||
| from sentry.services.organization.model import ( | ||
| OrganizationOptions, | ||
| OrganizationProvisioningOptions, | ||
| PostProvisionOptions, | ||
| ) | ||
| from sentry.services.organization.provisioning import ( | ||
| OrganizationProvisioningException, | ||
| organization_provisioning_service, | ||
| ) | ||
|
|
||
| provision_args = OrganizationProvisioningOptions( | ||
| provision_options=OrganizationOptions( | ||
| name=name, | ||
| slug=slug or name, | ||
| owning_email=owner_email, | ||
| create_default_team=not no_default_team, | ||
| ), | ||
| post_provision_options=PostProvisionOptions(), | ||
| ) | ||
|
|
||
| try: | ||
| rpc_org = organization_provisioning_service.provision_organization_in_cell( | ||
| provisioning_options=provision_args, | ||
| ) | ||
| except OrganizationProvisioningException as e: | ||
| raise click.ClickException(str(e)) | ||
|
|
||
| click.echo(f"Organization created: {rpc_org.name} (slug: {rpc_org.slug}, id: {rpc_org.id})") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| from sentry.models.organization import Organization | ||
| from sentry.models.organizationmember import OrganizationMember | ||
| from sentry.models.team import Team | ||
| from sentry.runner.commands.createorg import createorg | ||
| from sentry.testutils.cases import CliTestCase | ||
|
|
||
|
|
||
| class CreateOrgTest(CliTestCase): | ||
| command = createorg | ||
|
|
||
| def test_basic_create(self) -> None: | ||
| rv = self.invoke("--name=Test Org", "--slug=test-org", "--owner-email=owner@example.com") | ||
| assert rv.exit_code == 0, rv.output | ||
| assert "test-org" in rv.output | ||
|
|
||
| org = Organization.objects.get(slug="test-org") | ||
| assert org.name == "Test Org" | ||
| assert OrganizationMember.objects.filter( | ||
| organization=org, email="owner@example.com" | ||
| ).exists() | ||
| assert Team.objects.filter(organization=org).exists() | ||
|
|
||
| def test_slug_defaults_to_name(self) -> None: | ||
| rv = self.invoke("--name=My Organization", "--owner-email=owner@example.com") | ||
| assert rv.exit_code == 0, rv.output | ||
|
|
||
| assert Organization.objects.filter(slug="my-organization").exists() | ||
|
|
||
| def test_no_default_team(self) -> None: | ||
| rv = self.invoke( | ||
| "--name=No Team Org", | ||
| "--slug=no-team-org", | ||
| "--owner-email=owner@example.com", | ||
| "--no-default-team", | ||
| ) | ||
| assert rv.exit_code == 0, rv.output | ||
|
|
||
| org = Organization.objects.get(slug="no-team-org") | ||
| assert not Team.objects.filter(organization=org).exists() | ||
|
|
||
| def test_missing_name(self) -> None: | ||
| rv = self.invoke("--slug=test-org", "--owner-email=owner@example.com") | ||
| assert rv.exit_code != 0 | ||
|
|
||
| def test_missing_owner_email(self) -> None: | ||
| rv = self.invoke("--name=Test Org", "--slug=test-org") | ||
| assert rv.exit_code != 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omg, TIL about this decorator, all my commands call
sentry.runner.configure()as the import/line, this is helpful