launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25861
[Merge] ~pappacena/launchpad:ocirecipe-edit-git-instructions into launchpad:master
Thiago F. Pappacena has proposed merging ~pappacena/launchpad:ocirecipe-edit-git-instructions into launchpad:master with ~pappacena/launchpad:ocirecipe-git-instructions as a prerequisite.
Commit message:
Adding warnings for non-default git repository on OCI recipe edit view
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395300
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:ocirecipe-edit-git-instructions into launchpad:master.
diff --git a/lib/lp/oci/browser/ocirecipe.py b/lib/lp/oci/browser/ocirecipe.py
index 7019331..6fd0271 100644
--- a/lib/lp/oci/browser/ocirecipe.py
+++ b/lib/lp/oci/browser/ocirecipe.py
@@ -897,6 +897,35 @@ class OCIRecipeEditView(BaseOCIRecipeEditView, EnableProcessorsMixin,
)
custom_widget_git_ref = GitRefWidget
+ def setUpGitRefWidget(self):
+ """Setup GitRef widget indicating the user to use the default
+ oci project's git repository, if possible.
+ """
+ widget = self.widgets["git_ref"]
+ widget.setUpSubWidgets()
+ default_repo = self.context.oci_project.getDefaultGitRepository()
+ msg = None
+ 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.")
+ elif self.context.git_ref.repository != default_repo:
+ msg = (
+ "You are not using the default repository of this OCI project."
+ "<br/>Please, use <em>{repo_path}</em>.")
+ if msg:
+ oci_proj = self.context.oci_project
+ msg = msg.format(
+ oci_proj_url=canonical_url(oci_proj),
+ repo_path=oci_proj.getDefaultGitRepositoryPath())
+ self.widget_errors["git_ref"] = msg
+
+ def setUpWidgets(self):
+ """See `LaunchpadFormView`."""
+ super(OCIRecipeEditView, self).setUpWidgets()
+ self.setUpGitRefWidget()
+
def setUpFields(self):
"""See `LaunchpadFormView`."""
super(OCIRecipeEditView, self).setUpFields()
diff --git a/lib/lp/oci/browser/tests/test_ocirecipe.py b/lib/lp/oci/browser/tests/test_ocirecipe.py
index 296d74a..04faba0 100644
--- a/lib/lp/oci/browser/tests/test_ocirecipe.py
+++ b/lib/lp/oci/browser/tests/test_ocirecipe.py
@@ -656,6 +656,40 @@ class TestOCIRecipeEditView(OCIConfigHelperMixin, BaseTestOCIRecipeView):
login_person(self.person)
self.assertRecipeProcessors(recipe, ["386", "armhf"])
+ def test_edit_without_default_repo_for_ociproject(self):
+ self.setUpDistroSeries()
+ oci_project = self.factory.makeOCIProject(
+ registrant=self.person, pillar=self.distribution)
+ recipe = self.factory.makeOCIRecipe(
+ registrant=self.person, oci_project=oci_project)
+ with person_logged_in(self.person):
+ oci_project_url = canonical_url(oci_project)
+ browser = self.getViewBrowser(
+ recipe, view_name="+edit", 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_edit_repository_is_not_default_for_ociproject(self):
+ self.setUpDistroSeries()
+ oci_project = self.factory.makeOCIProject(
+ registrant=self.person, pillar=self.distribution)
+ recipe = self.factory.makeOCIRecipe(
+ registrant=self.person, oci_project=oci_project)
+ self.factory.makeGitRepository(
+ name=oci_project.name,
+ target=oci_project, owner=self.person, registrant=self.person)
+ with person_logged_in(self.person):
+ default_repo_path = oci_project.getDefaultGitRepositoryPath()
+ browser = self.getViewBrowser(
+ recipe, view_name="+edit", user=self.person)
+ error_message = (
+ 'You are not using the default repository of this OCI project.'
+ '<br/>Please, use <em>{repo}</em>').format(repo=default_repo_path)
+ self.assertIn(error_message, browser.contents)
+
class TestOCIRecipeDeleteView(BaseTestOCIRecipeView):
Follow ups