Mercurial > kallithea
changeset 7185:586f80f48113
hooks: rename hooks to reflect what they are doing
The names of our hooks should reflect what they are doing.
So, since pre_push and pre_pull only handle the locking, rename
pre_push->push_lock_handling and pre_pull->pull_lock_handling.
This imply a database migration step which must be run as described in the
upgrade documentation.
Also rename db.Ui class variables.
author | domruf <dominikruf@gmail.com> |
---|---|
date | Sat, 25 Nov 2017 10:20:23 +0100 |
parents | 52d4bb85cbbd |
children | 79fd9b50bd3e |
files | kallithea/alembic/versions/a020f7044fd6_rename_hooks.py kallithea/controllers/admin/settings.py kallithea/lib/db_manage.py kallithea/lib/hooks.py kallithea/lib/middleware/simplegit.py kallithea/model/db.py |
diffstat | 6 files changed, 84 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kallithea/alembic/versions/a020f7044fd6_rename_hooks.py Sat Nov 25 10:20:23 2017 +0100 @@ -0,0 +1,61 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +"""rename hooks + +Revision ID: a020f7044fd6 +Revises: 9358dc3d6828 +Create Date: 2017-11-24 13:35:14.374000 + +""" + +# The following opaque hexadecimal identifiers ("revisions") are used +# by Alembic to track this migration script and its relations to others. +revision = 'a020f7044fd6' +down_revision = '9358dc3d6828' +branch_labels = None +depends_on = None + +from alembic import op +from kallithea.model.db import Ui +from sqlalchemy import Table, MetaData + +meta = MetaData() + + +def upgrade(): + meta.bind = op.get_bind() + ui = Table(Ui.__tablename__, meta, autoload=True) + + ui.update(values={ + 'ui_key': 'prechangegroup.push_lock_handling', + 'ui_value': 'python:kallithea.lib.hooks.push_lock_handling', + }).where(ui.c.ui_key == 'prechangegroup.pre_push').execute() + ui.update(values={ + 'ui_key': 'preoutgoing.pull_lock_handling', + 'ui_value': 'python:kallithea.lib.hooks.pull_lock_handling', + }).where(ui.c.ui_key == 'preoutgoing.pre_pull').execute() + + +def downgrade(): + meta.bind = op.get_bind() + ui = Table(Ui.__tablename__, meta, autoload=True) + + ui.update(values={ + 'ui_key': 'prechangegroup.pre_push', + 'ui_value': 'python:kallithea.lib.hooks.pre_push', + }).where(ui.c.ui_key == 'prechangegroup.push_lock_handling').execute() + ui.update(values={ + 'ui_key': 'preoutgoing.pre_pull', + 'ui_value': 'python:kallithea.lib.hooks.pre_pull', + }).where(ui.c.ui_key == 'preoutgoing.pull_lock_handling').execute()
--- a/kallithea/controllers/admin/settings.py Thu Oct 12 22:21:51 2017 +0200 +++ b/kallithea/controllers/admin/settings.py Sat Nov 25 10:20:23 2017 +0100 @@ -109,10 +109,10 @@ sett = Ui.get_by_key('hooks', Ui.HOOK_REPO_SIZE) sett.ui_active = form_result['hooks_changegroup_repo_size'] - sett = Ui.get_by_key('hooks', Ui.HOOK_PUSH) + sett = Ui.get_by_key('hooks', Ui.HOOK_PUSH_LOG) sett.ui_active = form_result['hooks_changegroup_push_logger'] - sett = Ui.get_by_key('hooks', Ui.HOOK_PULL) + sett = Ui.get_by_key('hooks', Ui.HOOK_PULL_LOG) sett.ui_active = form_result['hooks_outgoing_pull_logger'] ## EXTENSIONS
--- a/kallithea/lib/db_manage.py Thu Oct 12 22:21:51 2017 +0200 +++ b/kallithea/lib/db_manage.py Sat Nov 25 10:20:23 2017 +0100 @@ -257,26 +257,26 @@ hooks3 = Ui() hooks3.ui_section = 'hooks' - hooks3.ui_key = Ui.HOOK_PUSH + hooks3.ui_key = Ui.HOOK_PUSH_LOG hooks3.ui_value = 'python:kallithea.lib.hooks.log_push_action' self.sa.add(hooks3) hooks4 = Ui() hooks4.ui_section = 'hooks' - hooks4.ui_key = Ui.HOOK_PRE_PUSH - hooks4.ui_value = 'python:kallithea.lib.hooks.pre_push' + hooks4.ui_key = Ui.HOOK_PUSH_LOCK + hooks4.ui_value = 'python:kallithea.lib.hooks.push_lock_handling' self.sa.add(hooks4) hooks5 = Ui() hooks5.ui_section = 'hooks' - hooks5.ui_key = Ui.HOOK_PULL + hooks5.ui_key = Ui.HOOK_PULL_LOG hooks5.ui_value = 'python:kallithea.lib.hooks.log_pull_action' self.sa.add(hooks5) hooks6 = Ui() hooks6.ui_section = 'hooks' - hooks6.ui_key = Ui.HOOK_PRE_PULL - hooks6.ui_value = 'python:kallithea.lib.hooks.pre_pull' + hooks6.ui_key = Ui.HOOK_PULL_LOCK + hooks6.ui_value = 'python:kallithea.lib.hooks.pull_lock_handling' self.sa.add(hooks6) # enable largefiles
--- a/kallithea/lib/hooks.py Thu Oct 12 22:21:51 2017 +0200 +++ b/kallithea/lib/hooks.py Sat Nov 25 10:20:23 2017 +0100 @@ -86,7 +86,7 @@ ui.status(msg) -def pre_push(ui, repo, **kwargs): +def push_lock_handling(ui, repo, **kwargs): # pre push function, currently used to ban pushing when # repository is locked ex = _extract_extras() @@ -104,7 +104,7 @@ raise _http_ret -def pre_pull(ui, repo, **kwargs): +def pull_lock_handling(ui, repo, **kwargs): # pre pull function ... ex = _extract_extras() if ex.locked_by[0]: @@ -420,10 +420,10 @@ repo = repo.scm_instance_no_cache() if hook_type == 'pre': - pre_push(baseui, repo) + push_lock_handling(baseui, repo) # if push hook is enabled via web interface - elif hook_type == 'post' and _hooks.get(Ui.HOOK_PUSH): + elif hook_type == 'post' and _hooks.get(Ui.HOOK_PUSH_LOG): rev_data = [] for l in git_stdin_lines: old_rev, new_rev, ref = l.strip().split(' ')
--- a/kallithea/lib/middleware/simplegit.py Thu Oct 12 22:21:51 2017 +0200 +++ b/kallithea/lib/middleware/simplegit.py Sat Nov 25 10:20:23 2017 +0100 @@ -43,7 +43,7 @@ from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback, check_locking_state from kallithea.lib.utils import make_ui, is_valid_repo from kallithea.lib.exceptions import HTTPLockedRC -from kallithea.lib.hooks import pre_pull +from kallithea.lib.hooks import pull_lock_handling from kallithea.lib import auth_modules log = logging.getLogger(__name__) @@ -222,8 +222,8 @@ _hooks = dict(baseui.configitems('hooks')) or {} if action == 'pull': # stupid git, emulate pre-pull hook ! - pre_pull(ui=baseui, repo=_repo._repo) - if action == 'pull' and _hooks.get(Ui.HOOK_PULL): + pull_lock_handling(ui=baseui, repo=_repo._repo) + if action == 'pull' and _hooks.get(Ui.HOOK_PULL_LOG): log_pull_action(ui=baseui, repo=_repo._repo) def __inject_extras(self, repo_path, baseui, extras=None):
--- a/kallithea/model/db.py Thu Oct 12 22:21:51 2017 +0200 +++ b/kallithea/model/db.py Sat Nov 25 10:20:23 2017 +0100 @@ -351,10 +351,10 @@ HOOK_UPDATE = 'changegroup.update' HOOK_REPO_SIZE = 'changegroup.repo_size' - HOOK_PUSH = 'changegroup.push_logger' - HOOK_PRE_PUSH = 'prechangegroup.pre_push' - HOOK_PULL = 'outgoing.pull_logger' - HOOK_PRE_PULL = 'preoutgoing.pre_pull' + HOOK_PUSH_LOG = 'changegroup.push_logger' + HOOK_PUSH_LOCK = 'prechangegroup.push_lock_handling' + HOOK_PULL_LOG = 'outgoing.pull_logger' + HOOK_PULL_LOCK = 'preoutgoing.pull_lock_handling' ui_id = Column(Integer(), primary_key=True) ui_section = Column(String(255), nullable=False) @@ -380,8 +380,8 @@ def get_builtin_hooks(cls): q = cls.query() q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE, - cls.HOOK_PUSH, cls.HOOK_PRE_PUSH, - cls.HOOK_PULL, cls.HOOK_PRE_PULL])) + cls.HOOK_PUSH_LOG, cls.HOOK_PUSH_LOCK, + cls.HOOK_PULL_LOG, cls.HOOK_PULL_LOCK])) q = q.filter(cls.ui_section == 'hooks') return q.all() @@ -389,8 +389,8 @@ def get_custom_hooks(cls): q = cls.query() q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE, - cls.HOOK_PUSH, cls.HOOK_PRE_PUSH, - cls.HOOK_PULL, cls.HOOK_PRE_PULL])) + cls.HOOK_PUSH_LOG, cls.HOOK_PUSH_LOCK, + cls.HOOK_PULL_LOG, cls.HOOK_PULL_LOCK])) q = q.filter(cls.ui_section == 'hooks') return q.all()