##// END OF EJS Templates
hooks: expose refs on push....
marcink -
r1755:329954e2 default
parent child Browse files
Show More
@@ -319,6 +319,7 b' class DbManage(object):'
319 (RhodeCodeUi.HOOK_PRE_PUSH, 'python:vcsserver.hooks.pre_push'),
319 (RhodeCodeUi.HOOK_PRE_PUSH, 'python:vcsserver.hooks.pre_push'),
320 (RhodeCodeUi.HOOK_PRETX_PUSH, 'python:vcsserver.hooks.pre_push'),
320 (RhodeCodeUi.HOOK_PRETX_PUSH, 'python:vcsserver.hooks.pre_push'),
321 (RhodeCodeUi.HOOK_PUSH, 'python:vcsserver.hooks.log_push_action'),
321 (RhodeCodeUi.HOOK_PUSH, 'python:vcsserver.hooks.log_push_action'),
322 (RhodeCodeUi.HOOK_PUSH_KEY, 'python:vcsserver.hooks.key_push'),
322
323
323 ]
324 ]
324
325
@@ -232,8 +232,20 b' def post_push(extras):'
232 # 2xx Codes don't raise exceptions
232 # 2xx Codes don't raise exceptions
233 output += _http_ret.title
233 output += _http_ret.title
234
234
235 if extras.new_refs:
236 tmpl = \
237 extras.server_url + '/' + \
238 extras.repository + \
239 "/pull-request/new?{ref_type}={ref_name}"
240 for branch_name in extras.new_refs['branches']:
241 output += 'RhodeCode: open pull request link: {}\n'.format(
242 tmpl.format(ref_type='branch', ref_name=branch_name))
243
244 for book_name in extras.new_refs['bookmarks']:
245 output += 'RhodeCode: open pull request link: {}\n'.format(
246 tmpl.format(ref_type='bookmark', ref_name=book_name))
247
235 output += 'RhodeCode: push completed\n'
248 output += 'RhodeCode: push completed\n'
236
237 return HookResponse(0, output)
249 return HookResponse(0, output)
238
250
239
251
@@ -428,6 +428,7 b' def config_data_from_db(clear_session=Tr'
428 if 'push' not in enabled_hook_classes:
428 if 'push' not in enabled_hook_classes:
429 skip_entries.append(('hooks', RhodeCodeUi.HOOK_PRE_PUSH))
429 skip_entries.append(('hooks', RhodeCodeUi.HOOK_PRE_PUSH))
430 skip_entries.append(('hooks', RhodeCodeUi.HOOK_PRETX_PUSH))
430 skip_entries.append(('hooks', RhodeCodeUi.HOOK_PRETX_PUSH))
431 skip_entries.append(('hooks', RhodeCodeUi.HOOK_PUSH_KEY))
431
432
432 config = [entry for entry in config if entry[:2] not in skip_entries]
433 config = [entry for entry in config if entry[:2] not in skip_entries]
433
434
@@ -52,7 +52,8 b' class SettingsModel(BaseModel):'
52 BUILTIN_HOOKS = (
52 BUILTIN_HOOKS = (
53 RhodeCodeUi.HOOK_REPO_SIZE, RhodeCodeUi.HOOK_PUSH,
53 RhodeCodeUi.HOOK_REPO_SIZE, RhodeCodeUi.HOOK_PUSH,
54 RhodeCodeUi.HOOK_PRE_PUSH, RhodeCodeUi.HOOK_PRETX_PUSH,
54 RhodeCodeUi.HOOK_PRE_PUSH, RhodeCodeUi.HOOK_PRETX_PUSH,
55 RhodeCodeUi.HOOK_PULL, RhodeCodeUi.HOOK_PRE_PULL)
55 RhodeCodeUi.HOOK_PULL, RhodeCodeUi.HOOK_PRE_PULL,
56 RhodeCodeUi.HOOK_PUSH_KEY,)
56 HOOKS_SECTION = 'hooks'
57 HOOKS_SECTION = 'hooks'
57
58
58 def __init__(self, sa=None, repo=None):
59 def __init__(self, sa=None, repo=None):
@@ -86,22 +86,24 b' HOOK_PUSH = db.RhodeCodeUi.HOOK_PUSH'
86 HOOK_PRE_PULL = db.RhodeCodeUi.HOOK_PRE_PULL
86 HOOK_PRE_PULL = db.RhodeCodeUi.HOOK_PRE_PULL
87 HOOK_PULL = db.RhodeCodeUi.HOOK_PULL
87 HOOK_PULL = db.RhodeCodeUi.HOOK_PULL
88 HOOK_REPO_SIZE = db.RhodeCodeUi.HOOK_REPO_SIZE
88 HOOK_REPO_SIZE = db.RhodeCodeUi.HOOK_REPO_SIZE
89 HOOK_PUSH_KEY = db.RhodeCodeUi.HOOK_PUSH_KEY
89
90
90 HG_HOOKS = frozenset(
91 HG_HOOKS = frozenset(
91 (HOOK_PRE_PULL, HOOK_PULL, HOOK_PRE_PUSH, HOOK_PRETX_PUSH, HOOK_PUSH,
92 (HOOK_PRE_PULL, HOOK_PULL, HOOK_PRE_PUSH, HOOK_PRETX_PUSH, HOOK_PUSH,
92 HOOK_REPO_SIZE))
93 HOOK_REPO_SIZE, HOOK_PUSH_KEY))
93
94
94
95
95 @pytest.mark.parametrize('disabled_hooks,expected_hooks', [
96 @pytest.mark.parametrize('disabled_hooks,expected_hooks', [
96 ([], HG_HOOKS),
97 ([], HG_HOOKS),
97 (HG_HOOKS, []),
98 (HG_HOOKS, []),
98
99
99 ([HOOK_PRE_PUSH, HOOK_PRETX_PUSH, HOOK_REPO_SIZE], [HOOK_PRE_PULL, HOOK_PULL, HOOK_PUSH]),
100 ([HOOK_PRE_PUSH, HOOK_PRETX_PUSH, HOOK_REPO_SIZE, HOOK_PUSH_KEY], [HOOK_PRE_PULL, HOOK_PULL, HOOK_PUSH]),
100
101
101 # When a pull/push hook is disabled, its pre-pull/push counterpart should
102 # When a pull/push hook is disabled, its pre-pull/push counterpart should
102 # be disabled too.
103 # be disabled too.
103 ([HOOK_PUSH], [HOOK_PRE_PULL, HOOK_PULL, HOOK_REPO_SIZE]),
104 ([HOOK_PUSH], [HOOK_PRE_PULL, HOOK_PULL, HOOK_REPO_SIZE]),
104 ([HOOK_PULL], [HOOK_PRE_PUSH, HOOK_PRETX_PUSH, HOOK_PUSH, HOOK_REPO_SIZE]),
105 ([HOOK_PULL], [HOOK_PRE_PUSH, HOOK_PRETX_PUSH, HOOK_PUSH, HOOK_REPO_SIZE,
106 HOOK_PUSH_KEY]),
105 ])
107 ])
106 def test_make_db_config_hg_hooks(pylonsapp, request, disabled_hooks,
108 def test_make_db_config_hg_hooks(pylonsapp, request, disabled_hooks,
107 expected_hooks):
109 expected_hooks):
@@ -131,6 +131,13 b' def _check_proper_git_push('
131 assert "Setting default branch" not in stderr
131 assert "Setting default branch" not in stderr
132
132
133
133
134 def _check_proper_hg_push(stdout, stderr, branch='default'):
135 assert 'pushing to' in stdout
136 assert 'searching for changes' in stdout
137
138 assert 'abort:' not in stderr
139
140
134 def _check_proper_clone(stdout, stderr, vcs):
141 def _check_proper_clone(stdout, stderr, vcs):
135 if vcs == 'hg':
142 if vcs == 'hg':
136 assert 'requesting all changes' in stdout
143 assert 'requesting all changes' in stdout
@@ -84,6 +84,9 b' class RcWebServer(object):'
84 _url = 'http://%(user)s:%(passwd)s@%(host)s/%(cloned_repo)s' % params
84 _url = 'http://%(user)s:%(passwd)s@%(host)s/%(cloned_repo)s' % params
85 return _url
85 return _url
86
86
87 def host_url(self):
88 return 'http://' + get_host_url(self.pylons_config)
89
87
90
88 @pytest.fixture(scope="module")
91 @pytest.fixture(scope="module")
89 def rcextensions(request, pylonsapp, tmpdir_factory):
92 def rcextensions(request, pylonsapp, tmpdir_factory):
@@ -34,6 +34,7 b' import time'
34 import pytest
34 import pytest
35
35
36 from rhodecode.lib.vcs.backends.git.repository import GitRepository
36 from rhodecode.lib.vcs.backends.git.repository import GitRepository
37 from rhodecode.lib.vcs.backends.hg.repository import MercurialRepository
37 from rhodecode.lib.vcs.nodes import FileNode
38 from rhodecode.lib.vcs.nodes import FileNode
38 from rhodecode.model.auth_token import AuthTokenModel
39 from rhodecode.model.auth_token import AuthTokenModel
39 from rhodecode.model.db import Repository, UserIpMap, CacheKey
40 from rhodecode.model.db import Repository, UserIpMap, CacheKey
@@ -42,7 +43,8 b' from rhodecode.model.user import UserMod'
42 from rhodecode.tests import (GIT_REPO, HG_REPO, TEST_USER_ADMIN_LOGIN)
43 from rhodecode.tests import (GIT_REPO, HG_REPO, TEST_USER_ADMIN_LOGIN)
43
44
44 from rhodecode.tests.other.vcs_operations import (
45 from rhodecode.tests.other.vcs_operations import (
45 Command, _check_proper_clone, _check_proper_git_push, _add_files_and_push,
46 Command, _check_proper_clone, _check_proper_git_push,
47 _check_proper_hg_push, _add_files_and_push,
46 HG_REPO_WITH_GROUP, GIT_REPO_WITH_GROUP)
48 HG_REPO_WITH_GROUP, GIT_REPO_WITH_GROUP)
47
49
48
50
@@ -396,7 +398,6 b' class TestVCSOperations(object):'
396 'hg clone', clone_url, tmpdir.strpath)
398 'hg clone', clone_url, tmpdir.strpath)
397 assert 'abort: authorization failed' in stderr
399 assert 'abort: authorization failed' in stderr
398
400
399
400 def test_clone_by_auth_token_with_scope(
401 def test_clone_by_auth_token_with_scope(
401 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
402 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
402 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
403 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
@@ -479,3 +480,176 b' def test_git_fetches_from_remote_reposit'
479 source_repo = backend_git['annotated-tag']
480 source_repo = backend_git['annotated-tag']
480 target_vcs_repo = backend_git.create_repo().scm_instance()
481 target_vcs_repo = backend_git.create_repo().scm_instance()
481 target_vcs_repo.fetch(rc_web_server.repo_clone_url(source_repo.repo_name))
482 target_vcs_repo.fetch(rc_web_server.repo_clone_url(source_repo.repo_name))
483
484
485 def test_git_push_shows_pull_request_refs(backend_git, rc_web_server, tmpdir):
486 """
487 test if remote info about refs is visible
488 """
489 empty_repo = backend_git.create_repo()
490
491 clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name)
492
493 cmd = Command(tmpdir.strpath)
494 cmd.execute('git clone', clone_url)
495
496 repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
497 repo.in_memory_commit.add(FileNode('readme.md', content='## Hello'))
498 repo.in_memory_commit.commit(
499 message='Commit on branch Master',
500 author='Automatic test',
501 branch='master')
502
503 repo_cmd = Command(repo.path)
504 stdout, stderr = repo_cmd.execute('git push --verbose origin master')
505 _check_proper_git_push(stdout, stderr, branch='master')
506
507 ref = '{}/{}/pull-request/new?branch=master'.format(
508 rc_web_server.host_url(), empty_repo.repo_name)
509 assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stderr
510 assert 'remote: RhodeCode: push completed' in stderr
511
512 # push on the same branch
513 repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
514 repo.in_memory_commit.add(FileNode('setup.py', content='print\n'))
515 repo.in_memory_commit.commit(
516 message='Commit2 on branch Master',
517 author='Automatic test2',
518 branch='master')
519
520 repo_cmd = Command(repo.path)
521 stdout, stderr = repo_cmd.execute('git push --verbose origin master')
522 _check_proper_git_push(stdout, stderr, branch='master')
523
524 assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stderr
525 assert 'remote: RhodeCode: push completed' in stderr
526
527 # new Branch
528 repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
529 repo.in_memory_commit.add(FileNode('feature1.py', content='## Hello world'))
530 repo.in_memory_commit.commit(
531 message='Commit on branch feature',
532 author='Automatic test',
533 branch='feature')
534
535 repo_cmd = Command(repo.path)
536 stdout, stderr = repo_cmd.execute('git push --verbose origin feature')
537 _check_proper_git_push(stdout, stderr, branch='feature')
538
539 ref = '{}/{}/pull-request/new?branch=feature'.format(
540 rc_web_server.host_url(), empty_repo.repo_name)
541 assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stderr
542 assert 'remote: RhodeCode: push completed' in stderr
543
544
545 def test_hg_push_shows_pull_request_refs(backend_hg, rc_web_server, tmpdir):
546 empty_repo = backend_hg.create_repo()
547
548 clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name)
549
550 cmd = Command(tmpdir.strpath)
551 cmd.execute('hg clone', clone_url)
552
553 repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
554 repo.in_memory_commit.add(FileNode(u'readme.md', content=u'## Hello'))
555 repo.in_memory_commit.commit(
556 message=u'Commit on branch default',
557 author=u'Automatic test',
558 branch='default')
559
560 repo_cmd = Command(repo.path)
561 repo_cmd.execute('hg checkout default')
562
563 stdout, stderr = repo_cmd.execute('hg push --verbose', clone_url)
564 _check_proper_hg_push(stdout, stderr, branch='default')
565
566 ref = '{}/{}/pull-request/new?branch=default'.format(
567 rc_web_server.host_url(), empty_repo.repo_name)
568 assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout
569 assert 'remote: RhodeCode: push completed' in stdout
570
571 # push on the same branch
572 repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
573 repo.in_memory_commit.add(FileNode(u'setup.py', content=u'print\n'))
574 repo.in_memory_commit.commit(
575 message=u'Commit2 on branch default',
576 author=u'Automatic test2',
577 branch=u'default')
578
579 repo_cmd = Command(repo.path)
580 repo_cmd.execute('hg checkout default')
581
582 stdout, stderr = repo_cmd.execute('hg push --verbose', clone_url)
583 _check_proper_hg_push(stdout, stderr, branch='default')
584
585 assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout
586 assert 'remote: RhodeCode: push completed' in stdout
587
588 # new Branch
589 repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
590 repo.in_memory_commit.add(FileNode(u'feature1.py', content=u'## Hello world'))
591 repo.in_memory_commit.commit(
592 message=u'Commit on branch feature',
593 author=u'Automatic test',
594 branch=u'feature')
595
596 repo_cmd = Command(repo.path)
597 repo_cmd.execute('hg checkout feature')
598
599 stdout, stderr = repo_cmd.execute('hg push --new-branch --verbose', clone_url)
600 _check_proper_hg_push(stdout, stderr, branch='feature')
601
602 ref = '{}/{}/pull-request/new?branch=feature'.format(
603 rc_web_server.host_url(), empty_repo.repo_name)
604 assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout
605 assert 'remote: RhodeCode: push completed' in stdout
606
607
608 def test_hg_push_shows_pull_request_refs_book(backend_hg, rc_web_server, tmpdir):
609 empty_repo = backend_hg.create_repo()
610
611 clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name)
612
613 cmd = Command(tmpdir.strpath)
614 cmd.execute('hg clone', clone_url)
615
616 repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
617 repo.in_memory_commit.add(FileNode(u'readme.md', content=u'## Hello'))
618 repo.in_memory_commit.commit(
619 message=u'Commit on branch default',
620 author=u'Automatic test',
621 branch='default')
622
623 repo_cmd = Command(repo.path)
624 repo_cmd.execute('hg checkout default')
625
626 stdout, stderr = repo_cmd.execute('hg push --verbose', clone_url)
627 _check_proper_hg_push(stdout, stderr, branch='default')
628
629 ref = '{}/{}/pull-request/new?branch=default'.format(
630 rc_web_server.host_url(), empty_repo.repo_name)
631 assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout
632 assert 'remote: RhodeCode: push completed' in stdout
633
634 # add bookmark
635 repo = MercurialRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
636 repo.in_memory_commit.add(FileNode(u'setup.py', content=u'print\n'))
637 repo.in_memory_commit.commit(
638 message=u'Commit2 on branch default',
639 author=u'Automatic test2',
640 branch=u'default')
641
642 repo_cmd = Command(repo.path)
643 repo_cmd.execute('hg checkout default')
644 repo_cmd.execute('hg bookmark feature2')
645 stdout, stderr = repo_cmd.execute('hg push -B feature2 --verbose', clone_url)
646 _check_proper_hg_push(stdout, stderr, branch='default')
647
648 ref = '{}/{}/pull-request/new?branch=default'.format(
649 rc_web_server.host_url(), empty_repo.repo_name)
650 assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout
651 ref = '{}/{}/pull-request/new?bookmark=feature2'.format(
652 rc_web_server.host_url(), empty_repo.repo_name)
653 assert 'remote: RhodeCode: open pull request link: {}'.format(ref) in stdout
654 assert 'remote: RhodeCode: push completed' in stdout
655 assert 'exporting bookmark feature2' in stdout
General Comments 0
You need to be logged in to leave comments. Login now