# HG changeset patch # User Marcin Kuzminski # Date 2018-02-13 17:31:43 # Node ID 6477cf12d3b5c804326a11767fdc1c0999b67c99 # Parent 25341b46bd7e2712d9b77e1784e8c5d04a9ff4ab api: update pull method with possible specification of the url diff --git a/rhodecode/api/tests/test_pull.py b/rhodecode/api/tests/test_pull.py --- a/rhodecode/api/tests/test_pull.py +++ b/rhodecode/api/tests/test_pull.py @@ -33,12 +33,14 @@ class TestPull(object): def test_api_pull(self, backend): r = backend.create_repo() repo_name = r.repo_name - r.clone_uri = os.path.join(TESTS_TMP_PATH, backend.repo_name) + clone_uri = os.path.join(TESTS_TMP_PATH, backend.repo_name) + r.clone_uri = clone_uri id_, params = build_data(self.apikey, 'pull', repoid=repo_name,) response = api_call(self.app, params) - - expected = {'msg': 'Pulled from `%s`' % (repo_name,), + msg = 'Pulled from url `%s` on repo `%s`' % ( + clone_uri, repo_name) + expected = {'msg': msg, 'repository': repo_name} assert_ok(id_, expected, given=response.body) @@ -47,5 +49,5 @@ class TestPull(object): self.apikey, 'pull', repoid=backend.repo_name) response = api_call(self.app, params) - expected = 'Unable to pull changes from `%s`' % (backend.repo_name,) + expected = 'Unable to pull changes from `None`' assert_error(id_, expected, given=response.body) diff --git a/rhodecode/api/tests/test_update_repo.py b/rhodecode/api/tests/test_update_repo.py --- a/rhodecode/api/tests/test_update_repo.py +++ b/rhodecode/api/tests/test_update_repo.py @@ -56,6 +56,9 @@ class TestApiUpdateRepo(object): ({'clone_uri': ''}, {'clone_uri': ''}), + ({'push_uri': ''}, + {'push_uri': ''}), + ({'landing_rev': 'rev:tip'}, {'landing_rev': ['rev', 'tip']}), diff --git a/rhodecode/api/views/repo_api.py b/rhodecode/api/views/repo_api.py --- a/rhodecode/api/views/repo_api.py +++ b/rhodecode/api/views/repo_api.py @@ -805,7 +805,8 @@ def remove_field_from_repo(request, apiu def update_repo( request, apiuser, repoid, repo_name=Optional(None), owner=Optional(OAttr('apiuser')), description=Optional(''), - private=Optional(False), clone_uri=Optional(None), + private=Optional(False), + clone_uri=Optional(None), push_uri=Optional(None), landing_rev=Optional('rev:tip'), fork_of=Optional(None), enable_statistics=Optional(False), enable_locking=Optional(False), @@ -882,6 +883,9 @@ def update_repo( clone_uri=clone_uri if not isinstance(clone_uri, Optional) else repo.clone_uri, + push_uri=push_uri + if not isinstance(push_uri, Optional) else repo.push_uri, + repo_landing_rev=landing_rev if not isinstance(landing_rev, Optional) else repo._landing_revision, @@ -1753,7 +1757,7 @@ def revoke_user_group_permission(request @jsonrpc_method() -def pull(request, apiuser, repoid): +def pull(request, apiuser, repoid, remote_uri=Optional(None)): """ Triggers a pull on the given repository from a remote location. You can use this to keep remote repositories up-to-date. @@ -1768,6 +1772,8 @@ def pull(request, apiuser, repoid): :type apiuser: AuthUser :param repoid: The repository name or repository ID. :type repoid: str or int + :param remote_uri: Optional remote URI to pass in for pull + :type remote_uri: str Example output: @@ -1775,7 +1781,7 @@ def pull(request, apiuser, repoid): id : result : { - "msg": "Pulled from ``" + "msg": "Pulled from url `` on repo ``" "repository": "" } error : null @@ -1787,27 +1793,31 @@ def pull(request, apiuser, repoid): id : result : null error : { - "Unable to pull changes from ``" + "Unable to push changes from ``" } """ repo = get_repo_or_error(repoid) + remote_uri = Optional.extract(remote_uri) + remote_uri_display = remote_uri or repo.clone_uri_hidden if not has_superadmin_permission(apiuser): _perms = ('repository.admin',) validate_repo_permissions(apiuser, repoid, repo, _perms) try: - ScmModel().pull_changes(repo.repo_name, apiuser.username) + ScmModel().pull_changes( + repo.repo_name, apiuser.username, remote_uri=remote_uri) return { - 'msg': 'Pulled from `%s`' % repo.repo_name, + 'msg': 'Pulled from url `%s` on repo `%s`' % ( + remote_uri_display, repo.repo_name), 'repository': repo.repo_name } except Exception: log.exception("Exception occurred while trying to " "pull changes from remote location") raise JSONRPCError( - 'Unable to pull changes from `%s`' % repo.repo_name + 'Unable to pull changes from `%s`' % remote_uri_display ) diff --git a/rhodecode/tests/fixture.py b/rhodecode/tests/fixture.py --- a/rhodecode/tests/fixture.py +++ b/rhodecode/tests/fixture.py @@ -125,6 +125,7 @@ class Fixture(object): 'repo_name': None, 'repo_type': 'hg', 'clone_uri': '', + 'push_uri': '', 'repo_group': '-1', 'repo_description': 'DESC', 'repo_private': False,