##// END OF EJS Templates
vcs: Do not trigger external hook in case of actions on shadow respositories.
Martin Bornhold -
r900:3895c836 default
parent child Browse files
Show More
@@ -38,6 +38,13 b' from rhodecode.model.db import Repositor'
38 HookResponse = collections.namedtuple('HookResponse', ('status', 'output'))
38 HookResponse = collections.namedtuple('HookResponse', ('status', 'output'))
39
39
40
40
41 def is_shadow_repo(extras):
42 """
43 Returns ``True`` if this is an action executed against a shadow repository.
44 """
45 return extras['is_shadow_repo']
46
47
41 def _get_scm_size(alias, root_path):
48 def _get_scm_size(alias, root_path):
42
49
43 if not alias.startswith('.'):
50 if not alias.startswith('.'):
@@ -85,7 +92,6 b' def pre_push(extras):'
85 """
92 """
86 usr = User.get_by_username(extras.username)
93 usr = User.get_by_username(extras.username)
87
94
88
89 output = ''
95 output = ''
90 if extras.locked_by[0] and usr.user_id != int(extras.locked_by[0]):
96 if extras.locked_by[0] and usr.user_id != int(extras.locked_by[0]):
91 locked_by = User.get(extras.locked_by[0]).username
97 locked_by = User.get(extras.locked_by[0]).username
@@ -100,11 +106,12 b' def pre_push(extras):'
100 else:
106 else:
101 raise _http_ret
107 raise _http_ret
102
108
103 # Calling hooks after checking the lock, for consistent behavior
109 # Propagate to external components. This is done after checking the
110 # lock, for consistent behavior.
111 if not is_shadow_repo(extras):
104 pre_push_extension(repo_store_path=Repository.base_path(), **extras)
112 pre_push_extension(repo_store_path=Repository.base_path(), **extras)
105
113 events.trigger(events.RepoPrePushEvent(
106 events.trigger(events.RepoPrePushEvent(repo_name=extras.repository,
114 repo_name=extras.repository, extras=extras))
107 extras=extras))
108
115
109 return HookResponse(0, output)
116 return HookResponse(0, output)
110
117
@@ -130,10 +137,12 b' def pre_pull(extras):'
130 else:
137 else:
131 raise _http_ret
138 raise _http_ret
132
139
133 # Calling hooks after checking the lock, for consistent behavior
140 # Propagate to external components. This is done after checking the
141 # lock, for consistent behavior.
142 if not is_shadow_repo(extras):
134 pre_pull_extension(**extras)
143 pre_pull_extension(**extras)
135 events.trigger(events.RepoPrePullEvent(repo_name=extras.repository,
144 events.trigger(events.RepoPrePullEvent(
136 extras=extras))
145 repo_name=extras.repository, extras=extras))
137
146
138 return HookResponse(0, output)
147 return HookResponse(0, output)
139
148
@@ -144,14 +153,15 b' def post_pull(extras):'
144 action = 'pull'
153 action = 'pull'
145 action_logger(user, action, extras.repository, extras.ip, commit=True)
154 action_logger(user, action, extras.repository, extras.ip, commit=True)
146
155
147 events.trigger(events.RepoPullEvent(repo_name=extras.repository,
156 # Propagate to external components.
148 extras=extras))
157 if not is_shadow_repo(extras):
149 # extension hook call
150 post_pull_extension(**extras)
158 post_pull_extension(**extras)
159 events.trigger(events.RepoPullEvent(
160 repo_name=extras.repository, extras=extras))
151
161
152 output = ''
162 output = ''
153 # make lock is a tri state False, True, None. We only make lock on True
163 # make lock is a tri state False, True, None. We only make lock on True
154 if extras.make_lock is True:
164 if extras.make_lock is True and not is_shadow_repo(extras):
155 Repository.lock(Repository.get_by_repo_name(extras.repository),
165 Repository.lock(Repository.get_by_repo_name(extras.repository),
156 user.user_id,
166 user.user_id,
157 lock_reason=Repository.LOCK_PULL)
167 lock_reason=Repository.LOCK_PULL)
@@ -179,19 +189,20 b' def post_push(extras):'
179 action_logger(
189 action_logger(
180 extras.username, action, extras.repository, extras.ip, commit=True)
190 extras.username, action, extras.repository, extras.ip, commit=True)
181
191
182 events.trigger(events.RepoPushEvent(repo_name=extras.repository,
192 # Propagate to external components.
183 pushed_commit_ids=commit_ids,
193 if not is_shadow_repo(extras):
184 extras=extras))
185
186 # extension hook call
187 post_push_extension(
194 post_push_extension(
188 repo_store_path=Repository.base_path(),
195 repo_store_path=Repository.base_path(),
189 pushed_revs=commit_ids,
196 pushed_revs=commit_ids,
190 **extras)
197 **extras)
198 events.trigger(events.RepoPushEvent(
199 repo_name=extras.repository,
200 pushed_commit_ids=commit_ids,
201 extras=extras))
191
202
192 output = ''
203 output = ''
193 # make lock is a tri state False, True, None. We only release lock on False
204 # make lock is a tri state False, True, None. We only release lock on False
194 if extras.make_lock is False:
205 if extras.make_lock is False and not is_shadow_repo(extras):
195 Repository.unlock(Repository.get_by_repo_name(extras.repository))
206 Repository.unlock(Repository.get_by_repo_name(extras.repository))
196 msg = 'Released lock on repo `%s`\n' % extras.repository
207 msg = 'Released lock on repo `%s`\n' % extras.repository
197 output += msg
208 output += msg
General Comments 0
You need to be logged in to leave comments. Login now