Skip to content
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

Allow SiteProfile to specify a default project namespace #2124

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion metecho/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def create_repository(
dependencies: Iterable[str],
template_repo_owner: str = None,
template_repo_name: str = None,
namespace: str = None,
):
"""
Given a local Metecho Project create and bootstrap the corresponding GitHub repository.
Expand Down Expand Up @@ -258,7 +259,7 @@ def create_repository(
"cci_version": cumulusci.__version__,
"project_name": project.repo_name,
"package_name": project.repo_name,
"package_namespace": None,
"package_namespace": namespace if namespace else None,
"api_version": runtime.universal_config.project__package__api_version,
"source_format": "sfdx",
"dependencies": [
Expand Down
19 changes: 19 additions & 0 deletions metecho/api/migrations/0119_siteprofile_project_namespace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.0.6 on 2023-05-25 13:54

from django.db import migrations
import sfdo_template_helpers.fields.string


class Migration(migrations.Migration):

dependencies = [
('api', '0118_project_deleted_at'),
]

operations = [
migrations.AddField(
model_name='siteprofile',
name='project_namespace',
field=sfdo_template_helpers.fields.string.StringField(blank=True, help_text='Namespace to be used for new Projects. Leave blank for no namespace.'),
),
]
8 changes: 8 additions & 0 deletions metecho/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class SiteProfile(TranslatableModel):
"Name of the GitHub repository to be used as a template for new Projects"
),
)
project_namespace = StringField(
blank=True,
help_text=_(
"Namespace to be used for new Projects. Leave blank for no namespace."
),
)

translations = TranslatedFields(
name=models.CharField(max_length=64),
Expand Down Expand Up @@ -460,6 +466,7 @@ def queue_create_repository(
dependencies: Iterable[str],
template_repo_owner: str = None,
template_repo_name: str = None,
namespace: str = None,
):
from .jobs import create_repository_job

Expand All @@ -469,6 +476,7 @@ def queue_create_repository(
dependencies=dependencies,
template_repo_owner=template_repo_owner,
template_repo_name=template_repo_name,
namespace=namespace,
)

def finalize_create_repository(self, *, error=None, user: User):
Expand Down
1 change: 1 addition & 0 deletions metecho/api/tests/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,7 @@ def test_ok(self, mocker, github_mocks, user_factory):
dependencies=["http://foo.com"],
template_repo_owner="owner",
template_repo_name="repo",
namespace="namespace",
)
project.refresh_from_db()

Expand Down
2 changes: 2 additions & 0 deletions metecho/api/tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def test_create(
site=Site.objects.get(),
template_repo_owner="orgname",
template_repo_name="reponame",
namespace="namespace",
)

create_repository_job = mocker.patch(
Expand Down Expand Up @@ -589,6 +590,7 @@ def test_create(
dependencies=["http://foo.com", "http://bar.com"],
template_repo_owner="orgname",
template_repo_name="reponame",
namespace="namespace",
)


Expand Down
2 changes: 1 addition & 1 deletion metecho/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def create(self, request):
dependencies=dependencies,
template_repo_owner=getattr(site_profile, "template_repo_owner", ""),
template_repo_name=getattr(site_profile, "template_repo_name", ""),
namespace=getattr(site_profile, "project_namespace", ""),
)
return Response(self.get_serializer(project).data)

Expand Down Expand Up @@ -559,7 +560,6 @@ class ScratchOrgViewSet(
filterset_class = ScratchOrgFilter

def get_queryset(self):

# All actions except log() act on active scratch orgs only
# getattr() check guards against DRF-Spectacular
if (
Expand Down