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