launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #21312
[Merge] lp:~cjwatson/launchpad/git-export-getRefByPath into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/git-export-getRefByPath into lp:launchpad.
Commit message:
Export IGitRepository.getRefByPath.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1654537 in Launchpad itself: "No way to get a git_ref from the API"
https://bugs.launchpad.net/launchpad/+bug/1654537
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/git-export-getRefByPath/+merge/314360
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/git-export-getRefByPath into lp:launchpad.
=== modified file 'lib/lp/_schema_circular_imports.py'
--- lib/lp/_schema_circular_imports.py 2016-12-02 13:01:53 +0000
+++ lib/lp/_schema_circular_imports.py 2017-01-09 18:44:27 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Update the interface schema values due to circular imports.
@@ -512,6 +512,7 @@
patch_entry_return_type(IGitRepository, 'subscribe', IGitSubscription)
patch_entry_return_type(IGitRepository, 'getSubscription', IGitSubscription)
patch_reference_property(IGitRepository, 'code_import', ICodeImport)
+patch_entry_return_type(IGitRepository, 'getRefByPath', IGitRef)
patch_collection_property(
IGitRepository, '_api_landing_targets', IBranchMergeProposal)
patch_collection_property(
=== modified file 'lib/lp/code/interfaces/gitrepository.py'
--- lib/lp/code/interfaces/gitrepository.py 2016-11-11 14:57:42 +0000
+++ lib/lp/code/interfaces/gitrepository.py 2017-01-09 18:44:27 +0000
@@ -1,4 +1,4 @@
-# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
+# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Git repository interfaces."""
@@ -265,6 +265,12 @@
# Really ICodeImport, patched in _schema_circular_imports.py.
schema=Interface))
+ @operation_parameters(
+ path=TextLine(title=_("A string to look up as a path.")))
+ # Really IGitRef, patched in _schema_circular_imports.py.
+ @operation_returns_entry(Interface)
+ @export_read_operation()
+ @operation_for_version("devel")
def getRefByPath(path):
"""Look up a single reference in this repository by path.
=== modified file 'lib/lp/code/model/tests/test_gitrepository.py'
--- lib/lp/code/model/tests/test_gitrepository.py 2016-11-11 14:57:42 +0000
+++ lib/lp/code/model/tests/test_gitrepository.py 2017-01-09 18:44:27 +0000
@@ -1,4 +1,4 @@
-# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
+# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for Git repositories."""
@@ -2682,6 +2682,32 @@
with person_logged_in(ANONYMOUS):
self.assertEqual(owner_db, repository_db.owner)
+ def test_getRefByPath(self):
+ repository_db = self.factory.makeGitRepository()
+ ref_dbs = self.factory.makeGitRefs(
+ repository=repository_db, paths=[u"refs/heads/a", u"refs/heads/b"])
+ repository_url = api_url(repository_db)
+ ref_urls = [api_url(ref_db) for ref_db in ref_dbs]
+ webservice = webservice_for_person(
+ repository_db.owner, permission=OAuthPermission.READ_PUBLIC)
+ webservice.default_api_version = "devel"
+ for path, expected_ref_url in (
+ ("a", ref_urls[0]),
+ ("refs/heads/a", ref_urls[0]),
+ ("b", ref_urls[1]),
+ ("refs/heads/b", ref_urls[1]),
+ ):
+ response = webservice.named_get(
+ repository_url, "getRefByPath", path=path)
+ self.assertEqual(200, response.status)
+ self.assertEqual(
+ webservice.getAbsoluteUrl(expected_ref_url),
+ response.jsonBody()["self_link"])
+ response = webservice.named_get(
+ repository_url, "getRefByPath", path="c")
+ self.assertEqual(200, response.status)
+ self.assertIsNone(response.jsonBody())
+
def test_subscribe(self):
# A user can subscribe to a repository.
repository_db = self.factory.makeGitRepository()
Follow ups