Merge lp:~cjwatson/launchpad/git-export-getRefByPath into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18309
Proposed branch: lp:~cjwatson/launchpad/git-export-getRefByPath
Merge into: lp:launchpad
Diff against target: 83 lines (+36/-3)
3 files modified
lib/lp/_schema_circular_imports.py (+2/-1)
lib/lp/code/interfaces/gitrepository.py (+7/-1)
lib/lp/code/model/tests/test_gitrepository.py (+27/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-export-getRefByPath
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+314360@code.launchpad.net

Commit message

Export IGitRepository.getRefByPath.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/_schema_circular_imports.py'
2--- lib/lp/_schema_circular_imports.py 2016-12-02 13:01:53 +0000
3+++ lib/lp/_schema_circular_imports.py 2017-01-09 18:44:27 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Update the interface schema values due to circular imports.
10@@ -512,6 +512,7 @@
11 patch_entry_return_type(IGitRepository, 'subscribe', IGitSubscription)
12 patch_entry_return_type(IGitRepository, 'getSubscription', IGitSubscription)
13 patch_reference_property(IGitRepository, 'code_import', ICodeImport)
14+patch_entry_return_type(IGitRepository, 'getRefByPath', IGitRef)
15 patch_collection_property(
16 IGitRepository, '_api_landing_targets', IBranchMergeProposal)
17 patch_collection_property(
18
19=== modified file 'lib/lp/code/interfaces/gitrepository.py'
20--- lib/lp/code/interfaces/gitrepository.py 2016-11-11 14:57:42 +0000
21+++ lib/lp/code/interfaces/gitrepository.py 2017-01-09 18:44:27 +0000
22@@ -1,4 +1,4 @@
23-# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
24+# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
25 # GNU Affero General Public License version 3 (see the file LICENSE).
26
27 """Git repository interfaces."""
28@@ -265,6 +265,12 @@
29 # Really ICodeImport, patched in _schema_circular_imports.py.
30 schema=Interface))
31
32+ @operation_parameters(
33+ path=TextLine(title=_("A string to look up as a path.")))
34+ # Really IGitRef, patched in _schema_circular_imports.py.
35+ @operation_returns_entry(Interface)
36+ @export_read_operation()
37+ @operation_for_version("devel")
38 def getRefByPath(path):
39 """Look up a single reference in this repository by path.
40
41
42=== modified file 'lib/lp/code/model/tests/test_gitrepository.py'
43--- lib/lp/code/model/tests/test_gitrepository.py 2016-11-11 14:57:42 +0000
44+++ lib/lp/code/model/tests/test_gitrepository.py 2017-01-09 18:44:27 +0000
45@@ -1,4 +1,4 @@
46-# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
47+# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
48 # GNU Affero General Public License version 3 (see the file LICENSE).
49
50 """Tests for Git repositories."""
51@@ -2682,6 +2682,32 @@
52 with person_logged_in(ANONYMOUS):
53 self.assertEqual(owner_db, repository_db.owner)
54
55+ def test_getRefByPath(self):
56+ repository_db = self.factory.makeGitRepository()
57+ ref_dbs = self.factory.makeGitRefs(
58+ repository=repository_db, paths=[u"refs/heads/a", u"refs/heads/b"])
59+ repository_url = api_url(repository_db)
60+ ref_urls = [api_url(ref_db) for ref_db in ref_dbs]
61+ webservice = webservice_for_person(
62+ repository_db.owner, permission=OAuthPermission.READ_PUBLIC)
63+ webservice.default_api_version = "devel"
64+ for path, expected_ref_url in (
65+ ("a", ref_urls[0]),
66+ ("refs/heads/a", ref_urls[0]),
67+ ("b", ref_urls[1]),
68+ ("refs/heads/b", ref_urls[1]),
69+ ):
70+ response = webservice.named_get(
71+ repository_url, "getRefByPath", path=path)
72+ self.assertEqual(200, response.status)
73+ self.assertEqual(
74+ webservice.getAbsoluteUrl(expected_ref_url),
75+ response.jsonBody()["self_link"])
76+ response = webservice.named_get(
77+ repository_url, "getRefByPath", path="c")
78+ self.assertEqual(200, response.status)
79+ self.assertIsNone(response.jsonBody())
80+
81 def test_subscribe(self):
82 # A user can subscribe to a repository.
83 repository_db = self.factory.makeGitRepository()