##// END OF EJS Templates
api: update pull method with possible specification of the url
marcink -
r2563:6477cf12 default
parent child Browse files
Show More
@@ -33,12 +33,14 b' class TestPull(object):'
33 33 def test_api_pull(self, backend):
34 34 r = backend.create_repo()
35 35 repo_name = r.repo_name
36 r.clone_uri = os.path.join(TESTS_TMP_PATH, backend.repo_name)
36 clone_uri = os.path.join(TESTS_TMP_PATH, backend.repo_name)
37 r.clone_uri = clone_uri
37 38
38 39 id_, params = build_data(self.apikey, 'pull', repoid=repo_name,)
39 40 response = api_call(self.app, params)
40
41 expected = {'msg': 'Pulled from `%s`' % (repo_name,),
41 msg = 'Pulled from url `%s` on repo `%s`' % (
42 clone_uri, repo_name)
43 expected = {'msg': msg,
42 44 'repository': repo_name}
43 45 assert_ok(id_, expected, given=response.body)
44 46
@@ -47,5 +49,5 b' class TestPull(object):'
47 49 self.apikey, 'pull', repoid=backend.repo_name)
48 50 response = api_call(self.app, params)
49 51
50 expected = 'Unable to pull changes from `%s`' % (backend.repo_name,)
52 expected = 'Unable to pull changes from `None`'
51 53 assert_error(id_, expected, given=response.body)
@@ -56,6 +56,9 b' class TestApiUpdateRepo(object):'
56 56 ({'clone_uri': ''},
57 57 {'clone_uri': ''}),
58 58
59 ({'push_uri': ''},
60 {'push_uri': ''}),
61
59 62 ({'landing_rev': 'rev:tip'},
60 63 {'landing_rev': ['rev', 'tip']}),
61 64
@@ -805,7 +805,8 b' def remove_field_from_repo(request, apiu'
805 805 def update_repo(
806 806 request, apiuser, repoid, repo_name=Optional(None),
807 807 owner=Optional(OAttr('apiuser')), description=Optional(''),
808 private=Optional(False), clone_uri=Optional(None),
808 private=Optional(False),
809 clone_uri=Optional(None), push_uri=Optional(None),
809 810 landing_rev=Optional('rev:tip'), fork_of=Optional(None),
810 811 enable_statistics=Optional(False),
811 812 enable_locking=Optional(False),
@@ -882,6 +883,9 b' def update_repo('
882 883 clone_uri=clone_uri
883 884 if not isinstance(clone_uri, Optional) else repo.clone_uri,
884 885
886 push_uri=push_uri
887 if not isinstance(push_uri, Optional) else repo.push_uri,
888
885 889 repo_landing_rev=landing_rev
886 890 if not isinstance(landing_rev, Optional) else repo._landing_revision,
887 891
@@ -1753,7 +1757,7 b' def revoke_user_group_permission(request'
1753 1757
1754 1758
1755 1759 @jsonrpc_method()
1756 def pull(request, apiuser, repoid):
1760 def pull(request, apiuser, repoid, remote_uri=Optional(None)):
1757 1761 """
1758 1762 Triggers a pull on the given repository from a remote location. You
1759 1763 can use this to keep remote repositories up-to-date.
@@ -1768,6 +1772,8 b' def pull(request, apiuser, repoid):'
1768 1772 :type apiuser: AuthUser
1769 1773 :param repoid: The repository name or repository ID.
1770 1774 :type repoid: str or int
1775 :param remote_uri: Optional remote URI to pass in for pull
1776 :type remote_uri: str
1771 1777
1772 1778 Example output:
1773 1779
@@ -1775,7 +1781,7 b' def pull(request, apiuser, repoid):'
1775 1781
1776 1782 id : <id_given_in_input>
1777 1783 result : {
1778 "msg": "Pulled from `<repository name>`"
1784 "msg": "Pulled from url `<remote_url>` on repo `<repository name>`"
1779 1785 "repository": "<repository name>"
1780 1786 }
1781 1787 error : null
@@ -1787,27 +1793,31 b' def pull(request, apiuser, repoid):'
1787 1793 id : <id_given_in_input>
1788 1794 result : null
1789 1795 error : {
1790 "Unable to pull changes from `<reponame>`"
1796 "Unable to push changes from `<remote_url>`"
1791 1797 }
1792 1798
1793 1799 """
1794 1800
1795 1801 repo = get_repo_or_error(repoid)
1802 remote_uri = Optional.extract(remote_uri)
1803 remote_uri_display = remote_uri or repo.clone_uri_hidden
1796 1804 if not has_superadmin_permission(apiuser):
1797 1805 _perms = ('repository.admin',)
1798 1806 validate_repo_permissions(apiuser, repoid, repo, _perms)
1799 1807
1800 1808 try:
1801 ScmModel().pull_changes(repo.repo_name, apiuser.username)
1809 ScmModel().pull_changes(
1810 repo.repo_name, apiuser.username, remote_uri=remote_uri)
1802 1811 return {
1803 'msg': 'Pulled from `%s`' % repo.repo_name,
1812 'msg': 'Pulled from url `%s` on repo `%s`' % (
1813 remote_uri_display, repo.repo_name),
1804 1814 'repository': repo.repo_name
1805 1815 }
1806 1816 except Exception:
1807 1817 log.exception("Exception occurred while trying to "
1808 1818 "pull changes from remote location")
1809 1819 raise JSONRPCError(
1810 'Unable to pull changes from `%s`' % repo.repo_name
1820 'Unable to pull changes from `%s`' % remote_uri_display
1811 1821 )
1812 1822
1813 1823
@@ -125,6 +125,7 b' class Fixture(object):'
125 125 'repo_name': None,
126 126 'repo_type': 'hg',
127 127 'clone_uri': '',
128 'push_uri': '',
128 129 'repo_group': '-1',
129 130 'repo_description': 'DESC',
130 131 'repo_private': False,
General Comments 0
You need to be logged in to leave comments. Login now