← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:ocirecipe-git-instructions into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:ocirecipe-git-instructions into launchpad:master with ~pappacena/launchpad:ociproject-git-instructions as a prerequisite.

Commit message:
Showing warning msg about oci recipe default repository

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395253
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:ocirecipe-git-instructions into launchpad:master.
diff --git a/lib/lp/oci/browser/ocirecipe.py b/lib/lp/oci/browser/ocirecipe.py
index f18779d..7019331 100644
--- a/lib/lp/oci/browser/ocirecipe.py
+++ b/lib/lp/oci/browser/ocirecipe.py
@@ -773,10 +773,28 @@ class OCIRecipeAddView(LaunchpadFormView, EnableProcessorsMixin,
             "architectures are restricted and may only be enabled or "
             "disabled by administrators.")
 
+    def setUpGitRefWidget(self):
+        """Setup GitRef widget indicating the user to use the default
+        oci project's git repository, if possible.
+        """
+        path = self.context.getDefaultGitRepositoryPath()
+        widget = self.widgets["git_ref"]
+        widget.setUpSubWidgets()
+        widget.repository_widget.setRenderedValue(path)
+        default_repo = self.context.getDefaultGitRepository()
+        if default_repo is None:
+            msg = (
+                "The git repository for this OCI project was not created yet."
+                "<br/>Check the <a href='{oci_proj_url}'>OCI project's page"
+                "</a> for instructions on how to create it.")
+            msg = msg.format(oci_proj_url=canonical_url(self.context))
+            self.widget_errors["git_ref"] = msg
+
     def setUpWidgets(self):
         """See `LaunchpadFormView`."""
         super(OCIRecipeAddView, self).setUpWidgets()
         self.widgets["processors"].widget_class = "processors"
+        self.setUpGitRefWidget()
 
     @property
     def cancel_url(self):
@@ -924,6 +942,7 @@ class OCIRecipeEditView(BaseOCIRecipeEditView, EnableProcessorsMixin,
                         data["processors"].append(processor)
         self.validateBuildArgs(data)
 
+
 class OCIRecipeDeleteView(BaseOCIRecipeEditView):
     """View for deleting OCI recipes."""
 
diff --git a/lib/lp/oci/browser/tests/test_ocirecipe.py b/lib/lp/oci/browser/tests/test_ocirecipe.py
index e22665d..296d74a 100644
--- a/lib/lp/oci/browser/tests/test_ocirecipe.py
+++ b/lib/lp/oci/browser/tests/test_ocirecipe.py
@@ -301,6 +301,39 @@ class TestOCIRecipeAddView(BaseTestOCIRecipeView):
         self.assertContentEqual(
             ["386", "amd64"], [proc.name for proc in recipe.processors])
 
+    def test_create_new_recipe_no_default_repo_warning(self):
+        self.setUpDistroSeries()
+        oci_project = self.factory.makeOCIProject(pillar=self.distribution)
+        with admin_logged_in():
+            oci_project_url = canonical_url(oci_project)
+        browser = self.getViewBrowser(
+            oci_project, view_name="+new-recipe", user=self.person)
+        error_message = (
+            'The git repository for this OCI project was not created yet.<br/>'
+            "Check the <a href='{url}'>OCI project's page</a> for "
+            'instructions on how to create it.').format(url=oci_project_url)
+        self.assertIn(error_message, browser.contents)
+
+    def test_create_new_recipe_with_default_repo_already_created(self):
+        self.setUpDistroSeries()
+        oci_project = self.factory.makeOCIProject(pillar=self.distribution)
+        owner = oci_project.registrant
+        self.factory.makeGitRepository(
+            name=oci_project.name,
+            target=oci_project, owner=owner, registrant=owner)
+        with admin_logged_in():
+            default_repo_path = oci_project.getDefaultGitRepositoryPath()
+        browser = self.getViewBrowser(
+            oci_project, view_name="+new-recipe", user=self.person)
+        error_message = (
+            'The git repository for this OCI project was not created yet.')
+        self.assertNotIn(error_message, browser.contents)
+        self.assertThat(browser.contents, soupmatchers.HTMLContains(
+            soupmatchers.Tag(
+                'Repository pre-filled', 'input', attrs={
+                    "id": "field.git_ref.repository",
+                    "value": default_repo_path})))
+
 
 class TestOCIRecipeAdminView(BaseTestOCIRecipeView):
 

Follow ups