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