##// END OF EJS Templates
rcextensions: updated example
marcink -
r3389:1934b7a2 default
parent child Browse files
Show More
@@ -1,90 +1,91 b''
1 1 # -*- coding: utf-8 -*-
2 2 # Copyright (C) 2016-2019 RhodeCode GmbH
3 3 #
4 4 # This program is free software: you can redistribute it and/or modify
5 5 # it under the terms of the GNU Affero General Public License, version 3
6 6 # (only), as published by the Free Software Foundation.
7 7 #
8 8 # This program is distributed in the hope that it will be useful,
9 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 11 # GNU General Public License for more details.
12 12 #
13 13 # You should have received a copy of the GNU Affero General Public License
14 14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 15 #
16 16 # This program is dual-licensed. If you wish to learn more about the
17 17 # RhodeCode Enterprise Edition, including its added features, Support services,
18 18 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 19
20 20 """
21 21 us in hooks::
22 22
23 23 from .helpers import extract_pre_commits
24 24 # returns list of dicts with key-val fetched from extra fields
25 25 commit_list = extract_pre_commits.run(**kwargs)
26 26
27 27 """
28 28 import re
29 29 import collections
30 30 import json
31 31
32 32
33 33 def get_hg_commits(repo, refs):
34 34 commits = []
35 35 return commits
36 36
37 37
38 38 def get_git_commits(repo, refs):
39 39 commits = []
40 40
41 41 for data in refs:
42 42 # we should now extract commit data
43 43 old_rev = data['old_rev']
44 44 new_rev = data['new_rev']
45 45
46 46 if '00000000' in old_rev:
47 47 # new branch, we don't need to extract nothing
48 48 return commits
49 49
50 50 git_env = dict(data['git_env'])
51 # https://github.com/git/git/blob/master/Documentation/pretty-formats.txt
51 52 cmd = [
52 53 'log',
53 '--pretty=format:{"commit_id": "%H", "author": "%aN <%aE>", "date": "%ad", "message": "%f"}',
54 '--pretty=format:{"commit_id": "%H", "author": "%aN <%aE>", "date": "%ad", "message": "%s"}',
54 55 '{}...{}'.format(old_rev, new_rev)
55 56 ]
56 57
57 58 stdout, stderr = repo.run_git_command(cmd, extra_env=git_env)
58 59 for line in stdout.splitlines():
59 60 try:
60 61 data = json.loads(line)
61 62 commits.append(data)
62 63 except Exception:
63 64 print('Failed to load data from GIT line')
64 65
65 66 return commits
66 67
67 68
68 69 def run(*args, **kwargs):
69 70 from rhodecode.model.db import Repository
70 71
71 72 vcs_type = kwargs['scm']
72 73 # use temp name then the main one propagated
73 74 repo_name = kwargs.pop('REPOSITORY', None) or kwargs['repository']
74 75
75 76 repo = Repository.get_by_repo_name(repo_name)
76 77 vcs_repo = repo.scm_instance(cache=False)
77 78
78 79 commits = []
79 80
80 81 if vcs_type == 'git':
81 82 for rev_data in kwargs['commit_ids']:
82 83 new_environ = dict((k, v) for k, v in rev_data['git_env'])
83 84 commits = get_git_commits(vcs_repo, kwargs['commit_ids'])
84 85
85 86 if vcs_type == 'hg':
86 87 for rev_data in kwargs['commit_ids']:
87 88 new_environ = dict((k, v) for k, v in rev_data['hg_env'])
88 89 commits = get_hg_commits(vcs_repo, kwargs['commit_ids'])
89 90
90 91 return commits
General Comments 0
You need to be logged in to leave comments. Login now