##// 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 def test_api_pull(self, backend):
33 def test_api_pull(self, backend):
34 r = backend.create_repo()
34 r = backend.create_repo()
35 repo_name = r.repo_name
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 id_, params = build_data(self.apikey, 'pull', repoid=repo_name,)
39 id_, params = build_data(self.apikey, 'pull', repoid=repo_name,)
39 response = api_call(self.app, params)
40 response = api_call(self.app, params)
40
41 msg = 'Pulled from url `%s` on repo `%s`' % (
41 expected = {'msg': 'Pulled from `%s`' % (repo_name,),
42 clone_uri, repo_name)
43 expected = {'msg': msg,
42 'repository': repo_name}
44 'repository': repo_name}
43 assert_ok(id_, expected, given=response.body)
45 assert_ok(id_, expected, given=response.body)
44
46
@@ -47,5 +49,5 b' class TestPull(object):'
47 self.apikey, 'pull', repoid=backend.repo_name)
49 self.apikey, 'pull', repoid=backend.repo_name)
48 response = api_call(self.app, params)
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 assert_error(id_, expected, given=response.body)
53 assert_error(id_, expected, given=response.body)
@@ -56,6 +56,9 b' class TestApiUpdateRepo(object):'
56 ({'clone_uri': ''},
56 ({'clone_uri': ''},
57 {'clone_uri': ''}),
57 {'clone_uri': ''}),
58
58
59 ({'push_uri': ''},
60 {'push_uri': ''}),
61
59 ({'landing_rev': 'rev:tip'},
62 ({'landing_rev': 'rev:tip'},
60 {'landing_rev': ['rev', 'tip']}),
63 {'landing_rev': ['rev', 'tip']}),
61
64
@@ -805,7 +805,8 b' def remove_field_from_repo(request, apiu'
805 def update_repo(
805 def update_repo(
806 request, apiuser, repoid, repo_name=Optional(None),
806 request, apiuser, repoid, repo_name=Optional(None),
807 owner=Optional(OAttr('apiuser')), description=Optional(''),
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 landing_rev=Optional('rev:tip'), fork_of=Optional(None),
810 landing_rev=Optional('rev:tip'), fork_of=Optional(None),
810 enable_statistics=Optional(False),
811 enable_statistics=Optional(False),
811 enable_locking=Optional(False),
812 enable_locking=Optional(False),
@@ -882,6 +883,9 b' def update_repo('
882 clone_uri=clone_uri
883 clone_uri=clone_uri
883 if not isinstance(clone_uri, Optional) else repo.clone_uri,
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 repo_landing_rev=landing_rev
889 repo_landing_rev=landing_rev
886 if not isinstance(landing_rev, Optional) else repo._landing_revision,
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 @jsonrpc_method()
1759 @jsonrpc_method()
1756 def pull(request, apiuser, repoid):
1760 def pull(request, apiuser, repoid, remote_uri=Optional(None)):
1757 """
1761 """
1758 Triggers a pull on the given repository from a remote location. You
1762 Triggers a pull on the given repository from a remote location. You
1759 can use this to keep remote repositories up-to-date.
1763 can use this to keep remote repositories up-to-date.
@@ -1768,6 +1772,8 b' def pull(request, apiuser, repoid):'
1768 :type apiuser: AuthUser
1772 :type apiuser: AuthUser
1769 :param repoid: The repository name or repository ID.
1773 :param repoid: The repository name or repository ID.
1770 :type repoid: str or int
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 Example output:
1778 Example output:
1773
1779
@@ -1775,7 +1781,7 b' def pull(request, apiuser, repoid):'
1775
1781
1776 id : <id_given_in_input>
1782 id : <id_given_in_input>
1777 result : {
1783 result : {
1778 "msg": "Pulled from `<repository name>`"
1784 "msg": "Pulled from url `<remote_url>` on repo `<repository name>`"
1779 "repository": "<repository name>"
1785 "repository": "<repository name>"
1780 }
1786 }
1781 error : null
1787 error : null
@@ -1787,27 +1793,31 b' def pull(request, apiuser, repoid):'
1787 id : <id_given_in_input>
1793 id : <id_given_in_input>
1788 result : null
1794 result : null
1789 error : {
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 repo = get_repo_or_error(repoid)
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 if not has_superadmin_permission(apiuser):
1804 if not has_superadmin_permission(apiuser):
1797 _perms = ('repository.admin',)
1805 _perms = ('repository.admin',)
1798 validate_repo_permissions(apiuser, repoid, repo, _perms)
1806 validate_repo_permissions(apiuser, repoid, repo, _perms)
1799
1807
1800 try:
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 return {
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 'repository': repo.repo_name
1814 'repository': repo.repo_name
1805 }
1815 }
1806 except Exception:
1816 except Exception:
1807 log.exception("Exception occurred while trying to "
1817 log.exception("Exception occurred while trying to "
1808 "pull changes from remote location")
1818 "pull changes from remote location")
1809 raise JSONRPCError(
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 'repo_name': None,
125 'repo_name': None,
126 'repo_type': 'hg',
126 'repo_type': 'hg',
127 'clone_uri': '',
127 'clone_uri': '',
128 'push_uri': '',
128 'repo_group': '-1',
129 'repo_group': '-1',
129 'repo_description': 'DESC',
130 'repo_description': 'DESC',
130 'repo_private': False,
131 'repo_private': False,
General Comments 0
You need to be logged in to leave comments. Login now