launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26081
[Merge] ~twom/launchpad:git-branch-picker-short-form-urls into launchpad:master
Tom Wardill has proposed merging ~twom/launchpad:git-branch-picker-short-form-urls into launchpad:master.
Commit message:
Allow short form owner default repository urls
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/396734
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:git-branch-picker-short-form-urls into launchpad:master.
diff --git a/lib/lp/code/browser/widgets/tests/test_gitrefwidget.py b/lib/lp/code/browser/widgets/tests/test_gitrefwidget.py
index 92c0569..98e223a 100644
--- a/lib/lp/code/browser/widgets/tests/test_gitrefwidget.py
+++ b/lib/lp/code/browser/widgets/tests/test_gitrefwidget.py
@@ -8,6 +8,7 @@ from testscenarios import (
load_tests_apply_scenarios,
WithScenarios,
)
+from zope.component import getUtility
from zope.formlib.interfaces import (
IBrowserWidget,
IInputWidget,
@@ -21,11 +22,13 @@ from zope.schema import ValidationError
from lp.app.validators import LaunchpadValidationError
from lp.code.browser.widgets.gitref import GitRefWidget
+from lp.code.interfaces.gitrepository import IGitRepositorySet
from lp.code.vocabularies.gitrepository import GitRepositoryVocabulary
from lp.services.beautifulsoup import BeautifulSoup
from lp.services.webapp.escaping import html_escape
from lp.services.webapp.servers import LaunchpadTestRequest
from lp.testing import (
+ person_logged_in,
TestCaseWithFactory,
verifyObject,
)
@@ -255,6 +258,22 @@ class TestGitRefWidget(WithScenarios, TestCaseWithFactory):
"There is no Git repository named '%s' registered in "
"Launchpad." % ref.repository_url)
+ def test_getInputValue_owner_default_short_form(self):
+ owner = self.factory.makePerson()
+ target = self.factory.makeProduct()
+ repo = self.factory.makeGitRepository(owner=owner, target=target)
+ [ref] = self.factory.makeGitRefs(repository=repo)
+ with person_logged_in(repo.owner):
+ getUtility(IGitRepositorySet).setDefaultRepositoryForOwner(
+ owner, target, repo, owner)
+ short_url = "~{}/{}".format(owner.name, target.name)
+ form = {
+ "field.git_ref.repository": short_url,
+ "field.git_ref.path": ref.path,
+ }
+ self.widget.request = LaunchpadTestRequest(form=form)
+ self.assertEqual(ref, self.widget.getInputValue())
+
def test_call(self):
# The __call__ method sets up the widgets.
markup = self.widget()
diff --git a/lib/lp/code/model/gitcollection.py b/lib/lp/code/model/gitcollection.py
index eef06f6..f9466a9 100644
--- a/lib/lp/code/model/gitcollection.py
+++ b/lib/lp/code/model/gitcollection.py
@@ -544,7 +544,8 @@ class GenericGitCollection:
path = URI(term).path.strip("/")
except InvalidURIError:
path = term
- return getUtility(IGitLookup).getByUniqueName(path)
+ result = getUtility(IGitLookup).getByPath(path)
+ return result[0]
def search(self, term):
"""See `IGitCollection`."""