Show More
@@ -22,7 +22,7 b' from rhodecode.lib import helpers as h' | |||
|
22 | 22 | from rhodecode.lib.utils2 import safe_int |
|
23 | 23 | |
|
24 | 24 | |
|
25 | def reviewer_as_json(user, reasons, mandatory): | |
|
25 | def reviewer_as_json(user, reasons=None, mandatory=False): | |
|
26 | 26 | """ |
|
27 | 27 | Returns json struct of a reviewer for frontend |
|
28 | 28 | |
@@ -33,7 +33,7 b' def reviewer_as_json(user, reasons, mand' | |||
|
33 | 33 | |
|
34 | 34 | return { |
|
35 | 35 | 'user_id': user.user_id, |
|
36 | 'reasons': reasons, | |
|
36 | 'reasons': reasons or [], | |
|
37 | 37 | 'mandatory': mandatory, |
|
38 | 38 | 'username': user.username, |
|
39 | 39 | 'firstname': user.firstname, |
@@ -318,6 +318,12 b' def includeme(config):' | |||
|
318 | 318 | config.add_subscriber(write_metadata_if_needed, ApplicationCreated) |
|
319 | 319 | config.add_subscriber(write_js_routes_if_enabled, ApplicationCreated) |
|
320 | 320 | |
|
321 | # events | |
|
322 | # TODO(marcink): this should be done when pyramid migration is finished | |
|
323 | # config.add_subscriber( | |
|
324 | # 'rhodecode.integrations.integrations_event_handler', | |
|
325 | # 'rhodecode.events.RhodecodeEvent') | |
|
326 | ||
|
321 | 327 | # Set the authorization policy. |
|
322 | 328 | authz_policy = ACLAuthorizationPolicy() |
|
323 | 329 | config.set_authorization_policy(authz_policy) |
@@ -18,6 +18,8 b'' | |||
|
18 | 18 | |
|
19 | 19 | import logging |
|
20 | 20 | from pyramid.threadlocal import get_current_registry |
|
21 | from rhodecode.events.base import RhodecodeEvent | |
|
22 | ||
|
21 | 23 | |
|
22 | 24 | log = logging.getLogger(__name__) |
|
23 | 25 | |
@@ -32,20 +34,21 b' def trigger(event, registry=None):' | |||
|
32 | 34 | # passing the registry as an argument to get rid of it. |
|
33 | 35 | registry = registry or get_current_registry() |
|
34 | 36 | registry.notify(event) |
|
35 | log.debug('event %s triggered', event) | |
|
37 | log.debug('event %s triggered using registry %s', event, registry) | |
|
36 | 38 | |
|
37 | 39 | # Until we can work around the problem that VCS operations do not have a |
|
38 | 40 | # pyramid context to work with, we send the events to integrations directly |
|
39 | 41 | |
|
40 | 42 | # Later it will be possible to use regular pyramid subscribers ie: |
|
41 | # config.add_subscriber(integrations_event_handler, RhodecodeEvent) | |
|
43 | # config.add_subscriber( | |
|
44 | # 'rhodecode.integrations.integrations_event_handler', | |
|
45 | # 'rhodecode.events.RhodecodeEvent') | |
|
46 | # trigger(event, request.registry) | |
|
47 | ||
|
42 | 48 | from rhodecode.integrations import integrations_event_handler |
|
43 | 49 | if isinstance(event, RhodecodeEvent): |
|
44 | 50 | integrations_event_handler(event) |
|
45 | 51 | |
|
46 | ||
|
47 | from rhodecode.events.base import RhodecodeEvent | |
|
48 | ||
|
49 | 52 | from rhodecode.events.user import ( # noqa |
|
50 | 53 | UserPreCreate, |
|
51 | 54 | UserPostCreate, |
@@ -33,12 +33,12 b' log = logging.getLogger(__name__)' | |||
|
33 | 33 | |
|
34 | 34 | class RhodecodeEvent(object): |
|
35 | 35 | """ |
|
36 |
Base event class for all Rhode |
|
|
36 | Base event class for all RhodeCode events | |
|
37 | 37 | """ |
|
38 | 38 | name = "RhodeCodeEvent" |
|
39 | 39 | |
|
40 | def __init__(self): | |
|
41 | self.request = get_current_request() | |
|
40 | def __init__(self, request=None): | |
|
41 | self.request = request or get_current_request() | |
|
42 | 42 | self.utc_timestamp = datetime.utcnow() |
|
43 | 43 | |
|
44 | 44 | @property |
@@ -80,9 +80,8 b' class RhodecodeEvent(object):' | |||
|
80 | 80 | def server_url(self): |
|
81 | 81 | default = '<no server_url available>' |
|
82 | 82 | if self.request: |
|
83 | from rhodecode.lib import helpers as h | |
|
84 | 83 | try: |
|
85 |
return |
|
|
84 | return self.request.route_url('home') | |
|
86 | 85 | except Exception: |
|
87 | 86 | log.exception('Failed to fetch URL for server') |
|
88 | 87 | return default |
@@ -41,6 +41,7 b' class PullRequestEvent(RepoEvent):' | |||
|
41 | 41 | data = super(PullRequestEvent, self).as_dict() |
|
42 | 42 | |
|
43 | 43 | commits = _commits_as_dict( |
|
44 | self, | |
|
44 | 45 | commit_ids=self.pullrequest.revisions, |
|
45 | 46 | repos=[self.pullrequest.source_repo] |
|
46 | 47 | ) |
@@ -27,10 +27,11 b' from rhodecode.lib.vcs.exceptions import' | |||
|
27 | 27 | log = logging.getLogger(__name__) |
|
28 | 28 | |
|
29 | 29 | |
|
30 | def _commits_as_dict(commit_ids, repos): | |
|
30 | def _commits_as_dict(event, commit_ids, repos): | |
|
31 | 31 | """ |
|
32 | 32 | Helper function to serialize commit_ids |
|
33 | 33 | |
|
34 | :param event: class calling this method | |
|
34 | 35 | :param commit_ids: commits to get |
|
35 | 36 | :param repos: list of repos to check |
|
36 | 37 | """ |
@@ -69,9 +70,9 b' def _commits_as_dict(commit_ids, repos):' | |||
|
69 | 70 | cs_data['mentions'] = extract_mentioned_users(cs_data['message']) |
|
70 | 71 | cs_data['reviewers'] = reviewers |
|
71 | 72 | cs_data['url'] = RepoModel().get_commit_url( |
|
72 | repo, cs_data['raw_id']) | |
|
73 | repo, cs_data['raw_id'], request=event.request) | |
|
73 | 74 | cs_data['permalink_url'] = RepoModel().get_commit_url( |
|
74 | repo, cs_data['raw_id'], permalink=True) | |
|
75 | repo, cs_data['raw_id'], request=event.request, permalink=True) | |
|
75 | 76 | urlified_message, issues_data = process_patterns( |
|
76 | 77 | cs_data['message'], repo.repo_name) |
|
77 | 78 | cs_data['issues'] = issues_data |
@@ -128,8 +129,10 b' class RepoEvent(RhodecodeEvent):' | |||
|
128 | 129 | 'repo_id': self.repo.repo_id, |
|
129 | 130 | 'repo_name': self.repo.repo_name, |
|
130 | 131 | 'repo_type': self.repo.repo_type, |
|
131 |
'url': RepoModel().get_url( |
|
|
132 | 'permalink_url': RepoModel().get_url(self.repo, permalink=True), | |
|
132 | 'url': RepoModel().get_url( | |
|
133 | self.repo, request=self.request), | |
|
134 | 'permalink_url': RepoModel().get_url( | |
|
135 | self.repo, request=self.request, permalink=True), | |
|
133 | 136 | 'extra_fields': extra_fields |
|
134 | 137 | } |
|
135 | 138 | }) |
@@ -248,7 +251,7 b' class RepoPushEvent(RepoVCSEvent):' | |||
|
248 | 251 | data['repo']['url'], branch_name) |
|
249 | 252 | |
|
250 | 253 | commits = _commits_as_dict( |
|
251 | commit_ids=self.pushed_commit_ids, repos=[self.repo]) | |
|
254 | self, commit_ids=self.pushed_commit_ids, repos=[self.repo]) | |
|
252 | 255 | |
|
253 | 256 | last_branch = None |
|
254 | 257 | for commit in reversed(commits): |
@@ -96,6 +96,9 b' class IntegrationModel(BaseModel):' | |||
|
96 | 96 | """ Send an event to an integration """ |
|
97 | 97 | handler = self.get_integration_handler(integration) |
|
98 | 98 | if handler: |
|
99 | log.debug( | |
|
100 | 'events: sending event %s on integration %s using handler %s', | |
|
101 | event, integration, handler) | |
|
99 | 102 | handler.send_event(event) |
|
100 | 103 | |
|
101 | 104 | def get_integrations(self, scope, IntegrationType=None): |
@@ -159,6 +159,9 b' class RepoModel(BaseModel):' | |||
|
159 | 159 | if not request: |
|
160 | 160 | request = get_current_request() |
|
161 | 161 | |
|
162 | if not request: | |
|
163 | return | |
|
164 | ||
|
162 | 165 | if permalink: |
|
163 | 166 | return request.route_url( |
|
164 | 167 | 'repo_summary', repo_name=safe_str(repo.repo_id)) |
@@ -170,6 +173,9 b' class RepoModel(BaseModel):' | |||
|
170 | 173 | if not request: |
|
171 | 174 | request = get_current_request() |
|
172 | 175 | |
|
176 | if not request: | |
|
177 | return | |
|
178 | ||
|
173 | 179 | if permalink: |
|
174 | 180 | return request.route_url( |
|
175 | 181 | 'repo_commit', repo_name=safe_str(repo.repo_id), |
General Comments 0
You need to be logged in to leave comments.
Login now