Changeset - 25c51511c8eb
[Not reviewed]
default
0 6 1
Mads Kiilerich (mads) - 5 years ago 2021-01-11 00:23:20
mads@kiilerich.com
hooks: put repo_size and update hooks in kallithea namespace

Keep things separate.

Include missing migration steps for 642847355a10.
7 files changed with 69 insertions and 12 deletions:
0 comments (0 inline, 0 general)
kallithea/alembic/versions/7ba0d2cad930_hooks_migrate_internal_hooks_to_.py
Show inline comments
 
new file 100644
 
# 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/>.
 

	
 
"""hooks: migrate internal hooks to kallithea namespace
 

	
 
Revision ID: 7ba0d2cad930
 
Revises: f62826179f39
 
Create Date: 2021-01-11 00:10:13.576586
 

	
 
"""
 

	
 
# The following opaque hexadecimal identifiers ("revisions") are used
 
# by Alembic to track this migration script and its relations to others.
 
revision = '7ba0d2cad930'
 
down_revision = 'f62826179f39'
 
branch_labels = None
 
depends_on = None
 

	
 
from alembic import op
 
from sqlalchemy import MetaData, Table
 

	
 
from kallithea.model import db
 

	
 

	
 
meta = MetaData()
 

	
 

	
 
def upgrade():
 
    meta.bind = op.get_bind()
 
    ui = Table(db.Ui.__tablename__, meta, autoload=True)
 

	
 
    ui.update(values={
 
        'ui_key': 'changegroup.kallithea_update',
 
        'ui_value': 'python:',  # value in db isn't used
 
    }).where(ui.c.ui_key == 'changegroup.update').execute()
 
    ui.update(values={
 
        'ui_key': 'changegroup.kallithea_repo_size',
 
        'ui_value': 'python:',  # value in db isn't used
 
    }).where(ui.c.ui_key == 'changegroup.repo_size').execute()
 

	
 
    # 642847355a10 moved these hooks out of db - remove old entries
 
    ui.delete().where(ui.c.ui_key == 'changegroup.push_logger').execute()
 
    ui.delete().where(ui.c.ui_key == 'outgoing.pull_logger').execute()
 

	
 

	
 
def downgrade():
 
    pass
kallithea/bin/vcs_hooks.py
Show inline comments
 
@@ -48,7 +48,7 @@ log = logging.getLogger(__name__)
 
def repo_size(ui, repo, hooktype=None, **kwargs):
 
    """Show size of Mercurial repository.
 

	
 
    Called as Mercurial hook changegroup.repo_size after push.
 
    Called as Mercurial hook changegroup.kallithea_repo_size after push.
 
    """
 
    size_hg, size_root = get_scm_size('.hg', safe_str(repo.root))
 

	
 
@@ -69,7 +69,7 @@ def update(ui, repo, hooktype=None, **kw
 
    """Update repo after push. The equivalent to 'hg update' but using the same
 
    Mercurial as everything else.
 

	
 
    Called as Mercurial hook changegroup.update after push.
 
    Called as Mercurial hook changegroup.kallithea_update after push.
 
    """
 
    try:
 
        ui.pushbuffer(error=True, subproc=True)
kallithea/controllers/admin/settings.py
Show inline comments
 
@@ -100,10 +100,10 @@ class SettingsController(base.BaseContro
 

	
 
                # HOOKS
 
                sett = db.Ui.get_by_key('hooks', db.Ui.HOOK_UPDATE)
 
                sett.ui_active = form_result['hooks_changegroup_update']
 
                sett.ui_active = form_result['hooks_changegroup_kallithea_update']
 

	
 
                sett = db.Ui.get_by_key('hooks', db.Ui.HOOK_REPO_SIZE)
 
                sett.ui_active = form_result['hooks_changegroup_repo_size']
 
                sett.ui_active = form_result['hooks_changegroup_kallithea_repo_size']
 

	
 
                ## EXTENSIONS
 
                sett = db.Ui.get_or_create('extensions', 'largefiles')
kallithea/model/db.py
Show inline comments
 
@@ -330,8 +330,8 @@ class Ui(meta.Base, BaseDbModel):
 
        _table_args_default_dict,
 
    )
 

	
 
    HOOK_UPDATE = 'changegroup.update'
 
    HOOK_REPO_SIZE = 'changegroup.repo_size'
 
    HOOK_UPDATE = 'changegroup.kallithea_update'
 
    HOOK_REPO_SIZE = 'changegroup.kallithea_repo_size'
 

	
 
    ui_id = Column(Integer(), primary_key=True)
 
    ui_section = Column(String(255), nullable=False)
kallithea/model/forms.py
Show inline comments
 
@@ -384,8 +384,8 @@ def ApplicationUiSettingsForm():
 
            v.ValidPath(),
 
            v.UnicodeString(strip=True, min=1, not_empty=True)
 
        )
 
        hooks_changegroup_update = v.StringBoolean(if_missing=False)
 
        hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
 
        hooks_changegroup_kallithea_update = v.StringBoolean(if_missing=False)
 
        hooks_changegroup_kallithea_repo_size = v.StringBoolean(if_missing=False)
 

	
 
        extensions_largefiles = v.StringBoolean(if_missing=False)
 
        extensions_hggit = v.StringBoolean(if_missing=False)
kallithea/templates/admin/settings/settings_vcs.html
Show inline comments
 
@@ -5,13 +5,13 @@ ${h.form(url('admin_settings'), method='
 
                <div>
 
                    <div class="checkbox">
 
                        <label>
 
                            ${h.checkbox('hooks_changegroup_repo_size','True')}
 
                            ${h.checkbox('hooks_changegroup_kallithea_repo_size','True')}
 
                            ${_('Show repository size after push')}
 
                        </label>
 
                    </div>
 
                    <div class="checkbox">
 
                        <label>
 
                            ${h.checkbox('hooks_changegroup_update','True')}
 
                            ${h.checkbox('hooks_changegroup_kallithea_update','True')}
 
                            ${_('Update repository after push (hg update)')}
 
                        </label>
 
                    </div>
kallithea/tests/functional/test_admin_settings.py
Show inline comments
 
@@ -91,13 +91,13 @@ class TestAdminSettingsController(base.T
 
    def test_add_existing_builtin_hook(self):
 
        self.log_user()
 
        response = self.app.post(base.url('admin_settings_hooks'),
 
                                params=dict(new_hook_ui_key='changegroup.update',
 
                                params=dict(new_hook_ui_key='changegroup.kallithea_update',
 
                                            new_hook_ui_value='attempted_new_value',
 
                                            _session_csrf_secret_token=self.session_csrf_secret_token()))
 

	
 
        self.checkSessionFlash(response, 'Builtin hooks are read-only')
 
        response = response.follow()
 
        response.mustcontain('changegroup.update')
 
        response.mustcontain('changegroup.kallithea_update')
 

	
 
    def test_index_search(self):
 
        self.log_user()
0 comments (0 inline, 0 general)