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