##// END OF EJS Templates
rcextensions: use extra_env to not override the default one inside vcsserver.
marcink -
r3212:28ab20dd default
parent child Browse files
Show More
@@ -1,90 +1,90 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2016-2018 RhodeCode GmbH
2 # Copyright (C) 2016-2018 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 cmd = [
51 cmd = [
52 'log',
52 'log',
53 '--pretty=format:{"commit_id": "%H", "author": "%aN <%aE>", "date": "%ad", "message": "%f"}',
53 '--pretty=format:{"commit_id": "%H", "author": "%aN <%aE>", "date": "%ad", "message": "%f"}',
54 '{}...{}'.format(old_rev, new_rev)
54 '{}...{}'.format(old_rev, new_rev)
55 ]
55 ]
56
56
57 stdout, stderr = repo.run_git_command(cmd, env=git_env)
57 stdout, stderr = repo.run_git_command(cmd, extra_env=git_env)
58 for line in stdout.splitlines():
58 for line in stdout.splitlines():
59 try:
59 try:
60 data = json.loads(line)
60 data = json.loads(line)
61 commits.append(data)
61 commits.append(data)
62 except Exception:
62 except Exception:
63 print('Failed to load data from GIT line')
63 print('Failed to load data from GIT line')
64
64
65 return commits
65 return commits
66
66
67
67
68 def run(*args, **kwargs):
68 def run(*args, **kwargs):
69 from rhodecode.model.db import Repository
69 from rhodecode.model.db import Repository
70
70
71 vcs_type = kwargs['scm']
71 vcs_type = kwargs['scm']
72 # use temp name then the main one propagated
72 # use temp name then the main one propagated
73 repo_name = kwargs.pop('REPOSITORY', None) or kwargs['repository']
73 repo_name = kwargs.pop('REPOSITORY', None) or kwargs['repository']
74
74
75 repo = Repository.get_by_repo_name(repo_name)
75 repo = Repository.get_by_repo_name(repo_name)
76 vcs_repo = repo.scm_instance(cache=False)
76 vcs_repo = repo.scm_instance(cache=False)
77
77
78 commits = []
78 commits = []
79
79
80 if vcs_type == 'git':
80 if vcs_type == 'git':
81 for rev_data in kwargs['commit_ids']:
81 for rev_data in kwargs['commit_ids']:
82 new_environ = dict((k, v) for k, v in rev_data['git_env'])
82 new_environ = dict((k, v) for k, v in rev_data['git_env'])
83 commits = get_git_commits(vcs_repo, kwargs['commit_ids'])
83 commits = get_git_commits(vcs_repo, kwargs['commit_ids'])
84
84
85 if vcs_type == 'hg':
85 if vcs_type == 'hg':
86 for rev_data in kwargs['commit_ids']:
86 for rev_data in kwargs['commit_ids']:
87 new_environ = dict((k, v) for k, v in rev_data['hg_env'])
87 new_environ = dict((k, v) for k, v in rev_data['hg_env'])
88 commits = get_hg_commits(vcs_repo, kwargs['commit_ids'])
88 commits = get_hg_commits(vcs_repo, kwargs['commit_ids'])
89
89
90 return commits
90 return commits
General Comments 0
You need to be logged in to leave comments. Login now