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