Show More
@@ -1,165 +1,162 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2018 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import webob |
|
22 | 22 | from pyramid.threadlocal import get_current_request |
|
23 | 23 | |
|
24 | 24 | from rhodecode import events |
|
25 | 25 | from rhodecode.lib import hooks_base |
|
26 | 26 | from rhodecode.lib import utils2 |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | def _get_rc_scm_extras(username, repo_name, repo_alias, action): |
|
30 | 30 | # TODO: johbo: Replace by vcs_operation_context and remove fully |
|
31 | 31 | from rhodecode.lib.base import vcs_operation_context |
|
32 | 32 | check_locking = action in ('pull', 'push') |
|
33 | 33 | |
|
34 | 34 | request = get_current_request() |
|
35 | 35 | |
|
36 | 36 | # default |
|
37 | 37 | dummy_environ = webob.Request.blank('').environ |
|
38 | 38 | try: |
|
39 | 39 | environ = request.environ or dummy_environ |
|
40 | 40 | except TypeError: |
|
41 | 41 | # we might use this outside of request context |
|
42 | 42 | environ = dummy_environ |
|
43 | 43 | |
|
44 | 44 | extras = vcs_operation_context( |
|
45 | 45 | environ, repo_name, username, action, repo_alias, check_locking) |
|
46 | 46 | return utils2.AttributeDict(extras) |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | def trigger_post_push_hook( |
|
50 | 50 | username, action, repo_name, repo_alias, commit_ids): |
|
51 | 51 | """ |
|
52 | 52 | Triggers push action hooks |
|
53 | 53 | |
|
54 | 54 | :param username: username who pushes |
|
55 | 55 | :param action: push/push_local/push_remote |
|
56 | 56 | :param repo_name: name of repo |
|
57 | 57 | :param repo_alias: the type of SCM repo |
|
58 | 58 | :param commit_ids: list of commit ids that we pushed |
|
59 | 59 | """ |
|
60 | if repo_alias not in ('hg', 'git'): | |
|
61 | return | |
|
62 | ||
|
63 | 60 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, action) |
|
64 | 61 | extras.commit_ids = commit_ids |
|
65 | 62 | hooks_base.post_push(extras) |
|
66 | 63 | |
|
67 | 64 | |
|
68 | 65 | def trigger_log_create_pull_request_hook(username, repo_name, repo_alias, |
|
69 | 66 | pull_request): |
|
70 | 67 | """ |
|
71 | 68 | Triggers create pull request action hooks |
|
72 | 69 | |
|
73 | 70 | :param username: username who creates the pull request |
|
74 | 71 | :param repo_name: name of target repo |
|
75 | 72 | :param repo_alias: the type of SCM target repo |
|
76 | 73 | :param pull_request: the pull request that was created |
|
77 | 74 | """ |
|
78 | 75 | if repo_alias not in ('hg', 'git'): |
|
79 | 76 | return |
|
80 | 77 | |
|
81 | 78 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
82 | 79 | 'create_pull_request') |
|
83 | 80 | events.trigger(events.PullRequestCreateEvent(pull_request)) |
|
84 | 81 | extras.update(pull_request.get_api_data()) |
|
85 | 82 | hooks_base.log_create_pull_request(**extras) |
|
86 | 83 | |
|
87 | 84 | |
|
88 | 85 | def trigger_log_merge_pull_request_hook(username, repo_name, repo_alias, |
|
89 | 86 | pull_request): |
|
90 | 87 | """ |
|
91 | 88 | Triggers merge pull request action hooks |
|
92 | 89 | |
|
93 | 90 | :param username: username who creates the pull request |
|
94 | 91 | :param repo_name: name of target repo |
|
95 | 92 | :param repo_alias: the type of SCM target repo |
|
96 | 93 | :param pull_request: the pull request that was merged |
|
97 | 94 | """ |
|
98 | 95 | if repo_alias not in ('hg', 'git'): |
|
99 | 96 | return |
|
100 | 97 | |
|
101 | 98 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
102 | 99 | 'merge_pull_request') |
|
103 | 100 | events.trigger(events.PullRequestMergeEvent(pull_request)) |
|
104 | 101 | extras.update(pull_request.get_api_data()) |
|
105 | 102 | hooks_base.log_merge_pull_request(**extras) |
|
106 | 103 | |
|
107 | 104 | |
|
108 | 105 | def trigger_log_close_pull_request_hook(username, repo_name, repo_alias, |
|
109 | 106 | pull_request): |
|
110 | 107 | """ |
|
111 | 108 | Triggers close pull request action hooks |
|
112 | 109 | |
|
113 | 110 | :param username: username who creates the pull request |
|
114 | 111 | :param repo_name: name of target repo |
|
115 | 112 | :param repo_alias: the type of SCM target repo |
|
116 | 113 | :param pull_request: the pull request that was closed |
|
117 | 114 | """ |
|
118 | 115 | if repo_alias not in ('hg', 'git'): |
|
119 | 116 | return |
|
120 | 117 | |
|
121 | 118 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
122 | 119 | 'close_pull_request') |
|
123 | 120 | events.trigger(events.PullRequestCloseEvent(pull_request)) |
|
124 | 121 | extras.update(pull_request.get_api_data()) |
|
125 | 122 | hooks_base.log_close_pull_request(**extras) |
|
126 | 123 | |
|
127 | 124 | |
|
128 | 125 | def trigger_log_review_pull_request_hook(username, repo_name, repo_alias, |
|
129 | 126 | pull_request): |
|
130 | 127 | """ |
|
131 | 128 | Triggers review status change pull request action hooks |
|
132 | 129 | |
|
133 | 130 | :param username: username who creates the pull request |
|
134 | 131 | :param repo_name: name of target repo |
|
135 | 132 | :param repo_alias: the type of SCM target repo |
|
136 | 133 | :param pull_request: the pull request that review status changed |
|
137 | 134 | """ |
|
138 | 135 | if repo_alias not in ('hg', 'git'): |
|
139 | 136 | return |
|
140 | 137 | |
|
141 | 138 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
142 | 139 | 'review_pull_request') |
|
143 | 140 | events.trigger(events.PullRequestReviewEvent(pull_request)) |
|
144 | 141 | extras.update(pull_request.get_api_data()) |
|
145 | 142 | hooks_base.log_review_pull_request(**extras) |
|
146 | 143 | |
|
147 | 144 | |
|
148 | 145 | def trigger_log_update_pull_request_hook(username, repo_name, repo_alias, |
|
149 | 146 | pull_request): |
|
150 | 147 | """ |
|
151 | 148 | Triggers update pull request action hooks |
|
152 | 149 | |
|
153 | 150 | :param username: username who creates the pull request |
|
154 | 151 | :param repo_name: name of target repo |
|
155 | 152 | :param repo_alias: the type of SCM target repo |
|
156 | 153 | :param pull_request: the pull request that was updated |
|
157 | 154 | """ |
|
158 | 155 | if repo_alias not in ('hg', 'git'): |
|
159 | 156 | return |
|
160 | 157 | |
|
161 | 158 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
162 | 159 | 'update_pull_request') |
|
163 | 160 | events.trigger(events.PullRequestUpdateEvent(pull_request)) |
|
164 | 161 | extras.update(pull_request.get_api_data()) |
|
165 | 162 | hooks_base.log_update_pull_request(**extras) |
General Comments 0
You need to be logged in to leave comments.
Login now