[Launchpad-reviewers] [Merge] ~pappacena/launchpad:ocirecipe-edit-git-instructions into launchpad:master
The proposal to merge ~pappacena/launchpad:ocirecipe-edit-git-instructions into launchpad:master has been updated. Status: Approved => Merged For more details, see: https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395300 -- Your team Launchpad code reviewers is subscribed to branch ~pappacena/launchpad:ocirecipe-git-instructions. ___ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp
[Launchpad-reviewers] [Merge] ~pappacena/launchpad:ocirecipe-edit-git-instructions into launchpad:master
The proposal to merge ~pappacena/launchpad:ocirecipe-edit-git-instructions into launchpad:master has been updated. Status: Needs review => Approved For more details, see: https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395300 -- Your team Launchpad code reviewers is subscribed to branch ~pappacena/launchpad:ocirecipe-git-instructions. ___ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp
Re: [Launchpad-reviewers] [Merge] ~pappacena/launchpad:ocirecipe-edit-git-instructions into launchpad:master
Diff comments: > diff --git a/lib/lp/oci/browser/ocirecipe.py b/lib/lp/oci/browser/ocirecipe.py > index acf83cf..464f1e9 100644 > --- a/lib/lp/oci/browser/ocirecipe.py > +++ b/lib/lp/oci/browser/ocirecipe.py > @@ -898,6 +901,37 @@ 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. > +""" > +oci_proj = self.context.oci_project > +widget = self.widgets["git_ref"] > +widget.setUpSubWidgets() > +msg = None > +if self.context.git_ref.namespace.target != self.context.oci_project: > +msg = ("This recipe's git repository is not in the " > + "correct namespace.") > +default_repo = > oci_proj.getDefaultGitRepository(self.context.owner) > +if default_repo: > +link = GitRepositoryFormatterAPI(default_repo).link('') > +msg += "Please, consider using %s." % link Ok! > +else: > +msg += ( > +"Check the OCI project page > " > +"for instructions on how to create it correctly.") > +if msg: > +msg = structured(msg.format( > +oci_proj_url=canonical_url(oci_proj), > +repo_path=oci_proj.getDefaultGitRepositoryPath( > +self.context.owner))) > +self.widget_errors["git_ref"] = msg.escapedtext Fixing it. > + > +def setUpWidgets(self): > +"""See `LaunchpadFormView`.""" > +super(OCIRecipeEditView, self).setUpWidgets() > +self.setUpGitRefWidget() > + > def setUpFields(self): > """See `LaunchpadFormView`.""" > super(OCIRecipeEditView, self).setUpFields() -- https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395300 Your team Launchpad code reviewers is subscribed to branch ~pappacena/launchpad:ocirecipe-git-instructions. ___ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp
Re: [Launchpad-reviewers] [Merge] ~pappacena/launchpad:ocirecipe-edit-git-instructions into launchpad:master
Review: Approve Diff comments: > diff --git a/lib/lp/oci/browser/ocirecipe.py b/lib/lp/oci/browser/ocirecipe.py > index acf83cf..464f1e9 100644 > --- a/lib/lp/oci/browser/ocirecipe.py > +++ b/lib/lp/oci/browser/ocirecipe.py > @@ -898,6 +901,37 @@ 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. > +""" > +oci_proj = self.context.oci_project > +widget = self.widgets["git_ref"] > +widget.setUpSubWidgets() > +msg = None > +if self.context.git_ref.namespace.target != self.context.oci_project: > +msg = ("This recipe's git repository is not in the " > + "correct namespace.") > +default_repo = > oci_proj.getDefaultGitRepository(self.context.owner) > +if default_repo: > +link = GitRepositoryFormatterAPI(default_repo).link('') > +msg += "Please, consider using %s." % link I think I'd drop the "Please," from this, and add "instead" at the end. > +else: > +msg += ( > +"Check the OCI project page > " > +"for instructions on how to create it correctly.") > +if msg: > +msg = structured(msg.format( > +oci_proj_url=canonical_url(oci_proj), > +repo_path=oci_proj.getDefaultGitRepositoryPath( > +self.context.owner))) > +self.widget_errors["git_ref"] = msg.escapedtext As in https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395253, this isn't using structured() quite right. > + > +def setUpWidgets(self): > +"""See `LaunchpadFormView`.""" > +super(OCIRecipeEditView, self).setUpWidgets() > +self.setUpGitRefWidget() > + > def setUpFields(self): > """See `LaunchpadFormView`.""" > super(OCIRecipeEditView, self).setUpFields() -- https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395300 Your team Launchpad code reviewers is subscribed to branch ~pappacena/launchpad:ocirecipe-git-instructions. ___ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp
[Launchpad-reviewers] [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." +"Check the OCI project's page" +" 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." +"Please, use {repo_path}.") +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.' +"Check the OCI project's page 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.' +'Please, use {repo}').format(repo=default_repo_path) +self.assertIn(error_message, browser.contents) + class TestOCIRecipeDeleteView(BaseTestOCIRecipeView): ___ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp