##// END OF EJS Templates
config: small updated to .ini files
config: small updated to .ini files

File last commit:

r3423:f8efae2b merge default
r4171:0e77716f default
Show More
extract_pre_commits.py
91 lines | 2.8 KiB | text/x-python | PythonLexer
rcextensions: new builtin rcextensions....
r3133 # -*- coding: utf-8 -*-
docs: updated copyrights to 2019
r3363 # Copyright (C) 2016-2019 RhodeCode GmbH
rcextensions: new builtin rcextensions....
r3133 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# 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 Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
"""
us in hooks::
from .helpers import extract_pre_commits
# returns list of dicts with key-val fetched from extra fields
commit_list = extract_pre_commits.run(**kwargs)
"""
import re
import collections
rcextensions: added example for validation of commit messages for git.
r3211 import json
rcextensions: new builtin rcextensions....
r3133
def get_hg_commits(repo, refs):
commits = []
return commits
def get_git_commits(repo, refs):
commits = []
rcextensions: added example for validation of commit messages for git.
r3211
for data in refs:
# we should now extract commit data
old_rev = data['old_rev']
new_rev = data['new_rev']
if '00000000' in old_rev:
# new branch, we don't need to extract nothing
return commits
git_env = dict(data['git_env'])
rcextensions: updated example and template override with more docs.
r3414 # https://github.com/git/git/blob/master/Documentation/pretty-formats.txt
rcextensions: added example for validation of commit messages for git.
r3211 cmd = [
'log',
rcextensions: updated example and template override with more docs.
r3414 '--pretty=format:{"commit_id": "%H", "author": "%aN <%aE>", "date": "%ad", "message": "%s"}',
rcextensions: added example for validation of commit messages for git.
r3211 '{}...{}'.format(old_rev, new_rev)
]
rcextensions: use extra_env to not override the default one inside vcsserver.
r3212 stdout, stderr = repo.run_git_command(cmd, extra_env=git_env)
rcextensions: added example for validation of commit messages for git.
r3211 for line in stdout.splitlines():
try:
data = json.loads(line)
commits.append(data)
except Exception:
print('Failed to load data from GIT line')
rcextensions: new builtin rcextensions....
r3133 return commits
def run(*args, **kwargs):
from rhodecode.model.db import Repository
vcs_type = kwargs['scm']
# use temp name then the main one propagated
repo_name = kwargs.pop('REPOSITORY', None) or kwargs['repository']
repo = Repository.get_by_repo_name(repo_name)
vcs_repo = repo.scm_instance(cache=False)
commits = []
if vcs_type == 'git':
rcextensions: added example for validation of commit messages for git.
r3211 for rev_data in kwargs['commit_ids']:
new_environ = dict((k, v) for k, v in rev_data['git_env'])
rcextensions: new builtin rcextensions....
r3133 commits = get_git_commits(vcs_repo, kwargs['commit_ids'])
if vcs_type == 'hg':
rcextensions: added example for validation of commit messages for git.
r3211 for rev_data in kwargs['commit_ids']:
new_environ = dict((k, v) for k, v in rev_data['hg_env'])
rcextensions: new builtin rcextensions....
r3133 commits = get_hg_commits(vcs_repo, kwargs['commit_ids'])
return commits