Show More
@@ -18,13 +18,10 b'' | |||||
18 |
|
18 | |||
19 | import logging |
|
19 | import logging | |
20 |
|
20 | |||
21 |
from rhodecode.events.base import |
|
21 | from rhodecode.events.base import RhodeCodeIntegrationEvent, RhodecodeEvent | |
22 | RhodeCodeIntegrationEvent, |
|
|||
23 | RhodecodeEvent |
|
|||
24 | ) |
|
|||
25 |
|
22 | |||
26 | from rhodecode.events.base import ( # pragma: no cover |
|
23 | from rhodecode.events.base import ( # pragma: no cover | |
27 | FtsBuild |
|
24 | FtsBuild, | |
28 | ) |
|
25 | ) | |
29 |
|
26 | |||
30 | from rhodecode.events.user import ( # pragma: no cover |
|
27 | from rhodecode.events.user import ( # pragma: no cover | |
@@ -37,11 +34,16 b' from rhodecode.events.user import ( # p' | |||||
37 |
|
34 | |||
38 | from rhodecode.events.repo import ( # pragma: no cover |
|
35 | from rhodecode.events.repo import ( # pragma: no cover | |
39 | RepoEvent, |
|
36 | RepoEvent, | |
40 |
RepoCommitCommentEvent, |
|
37 | RepoCommitCommentEvent, | |
41 | RepoPreCreateEvent, RepoCreateEvent, |
|
38 | RepoCommitCommentEditEvent, | |
42 |
RepoPre |
|
39 | RepoPreCreateEvent, | |
43 | RepoPrePushEvent, RepoPushEvent, |
|
40 | RepoCreateEvent, | |
44 | RepoPrePullEvent, RepoPullEvent, |
|
41 | RepoPreDeleteEvent, | |
|
42 | RepoDeleteEvent, | |||
|
43 | RepoPrePushEvent, | |||
|
44 | RepoPushEvent, | |||
|
45 | RepoPrePullEvent, | |||
|
46 | RepoPullEvent, | |||
45 | ) |
|
47 | ) | |
46 |
|
48 | |||
47 | from rhodecode.events.repo_group import ( # pragma: no cover |
|
49 | from rhodecode.events.repo_group import ( # pragma: no cover | |
@@ -77,12 +79,13 b' def trigger(event, registry=None):' | |||||
77 | from pyramid.threadlocal import get_current_registry |
|
79 | from pyramid.threadlocal import get_current_registry | |
78 |
|
80 | |||
79 | event_name = event.__class__ |
|
81 | event_name = event.__class__ | |
80 |
log.debug( |
|
82 | log.debug("event %s sent for execution", event_name) | |
81 | registry = registry or get_current_registry() |
|
83 | registry = registry or get_current_registry() | |
82 | registry.notify(event) |
|
84 | registry.notify(event) | |
83 |
log.debug( |
|
85 | log.debug("event %s triggered using registry %s", event_name, registry) | |
84 |
|
86 | |||
85 | # Send the events to integrations directly |
|
87 | # Send the events to integrations directly | |
86 | from rhodecode.integrations import integrations_event_handler |
|
88 | from rhodecode.integrations import integrations_event_handler | |
|
89 | ||||
87 | if isinstance(event, RhodeCodeIntegrationEvent): |
|
90 | if isinstance(event, RhodeCodeIntegrationEvent): | |
88 | integrations_event_handler(event) |
|
91 | integrations_event_handler(event) |
@@ -26,10 +26,7 b' from rhodecode.lib.utils2 import Attribu' | |||||
26 |
|
26 | |||
27 |
|
27 | |||
28 | # this is a user object to be used for events caused by the system (eg. shell) |
|
28 | # this is a user object to be used for events caused by the system (eg. shell) | |
29 | SYSTEM_USER = AttributeDict(dict( |
|
29 | SYSTEM_USER = AttributeDict(dict(username="__SYSTEM__", user_id="__SYSTEM_ID__")) | |
30 | username='__SYSTEM__', |
|
|||
31 | user_id='__SYSTEM_ID__' |
|
|||
32 | )) |
|
|||
33 |
|
30 | |||
34 | log = logging.getLogger(__name__) |
|
31 | log = logging.getLogger(__name__) | |
35 |
|
32 | |||
@@ -38,16 +35,18 b' class RhodecodeEvent(object):' | |||||
38 | """ |
|
35 | """ | |
39 | Base event class for all RhodeCode events |
|
36 | Base event class for all RhodeCode events | |
40 | """ |
|
37 | """ | |
|
38 | ||||
41 | name = "RhodeCodeEvent" |
|
39 | name = "RhodeCodeEvent" | |
42 |
no_url_set = |
|
40 | no_url_set = "<no server_url available>" | |
43 |
|
41 | |||
44 | def __init__(self, request=None, actor=None): |
|
42 | def __init__(self, request=None, actor=None, context=None): | |
45 | self._request = request |
|
43 | self._request = request | |
46 | self._actor = actor |
|
44 | self._actor = actor | |
|
45 | self._context = context | |||
47 | self.utc_timestamp = datetime.datetime.utcnow() |
|
46 | self.utc_timestamp = datetime.datetime.utcnow() | |
48 |
|
47 | |||
49 | def __repr__(self): |
|
48 | def __repr__(self): | |
50 |
return |
|
49 | return f"<{self.__class__.__name__}:(name={self.name}, context={self._context})>" | |
51 |
|
50 | |||
52 | def get_request(self): |
|
51 | def get_request(self): | |
53 | if self._request: |
|
52 | if self._request: | |
@@ -63,11 +62,11 b' class RhodecodeEvent(object):' | |||||
63 | if not self.request: |
|
62 | if not self.request: | |
64 | return |
|
63 | return | |
65 |
|
64 | |||
66 |
user = getattr(self.request, |
|
65 | user = getattr(self.request, "user", None) | |
67 | if user: |
|
66 | if user: | |
68 | return user |
|
67 | return user | |
69 |
|
68 | |||
70 |
api_user = getattr(self.request, |
|
69 | api_user = getattr(self.request, "rpc_user", None) | |
71 | if api_user: |
|
70 | if api_user: | |
72 | return api_user |
|
71 | return api_user | |
73 |
|
72 | |||
@@ -80,15 +79,17 b' class RhodecodeEvent(object):' | |||||
80 | return self._actor |
|
79 | return self._actor | |
81 |
|
80 | |||
82 | auth_user = self.auth_user |
|
81 | auth_user = self.auth_user | |
83 |
log.debug( |
|
82 | log.debug("Got integration actor: %s", auth_user) | |
84 | if isinstance(auth_user, AuthUser): |
|
83 | if isinstance(auth_user, AuthUser): | |
85 | instance = auth_user.get_instance() |
|
84 | instance = auth_user.get_instance() | |
86 | # we can't find this DB user... |
|
85 | # we can't find this DB user... | |
87 | if not instance: |
|
86 | if not instance: | |
88 |
return AttributeDict( |
|
87 | return AttributeDict( | |
|
88 | dict( | |||
89 | username=auth_user.username, |
|
89 | username=auth_user.username, | |
90 | user_id=auth_user.user_id, |
|
90 | user_id=auth_user.user_id, | |
91 |
|
|
91 | ) | |
|
92 | ) | |||
92 | elif auth_user: |
|
93 | elif auth_user: | |
93 | return auth_user |
|
94 | return auth_user | |
94 | return SYSTEM_USER |
|
95 | return SYSTEM_USER | |
@@ -98,29 +99,26 b' class RhodecodeEvent(object):' | |||||
98 | auth_user = self.auth_user |
|
99 | auth_user = self.auth_user | |
99 | if auth_user: |
|
100 | if auth_user: | |
100 | return auth_user.ip_addr |
|
101 | return auth_user.ip_addr | |
101 |
return |
|
102 | return "<no ip available>" | |
102 |
|
103 | |||
103 | @property |
|
104 | @property | |
104 | def server_url(self): |
|
105 | def server_url(self): | |
105 | if self.request: |
|
106 | if self.request: | |
106 | try: |
|
107 | try: | |
107 |
return self.request.route_url( |
|
108 | return self.request.route_url("home") | |
108 | except Exception: |
|
109 | except Exception: | |
109 |
log.exception( |
|
110 | log.exception("Failed to fetch URL for server") | |
110 | return self.no_url_set |
|
111 | return self.no_url_set | |
111 |
|
112 | |||
112 | return self.no_url_set |
|
113 | return self.no_url_set | |
113 |
|
114 | |||
114 | def as_dict(self): |
|
115 | def as_dict(self): | |
115 | data = { |
|
116 | data = { | |
116 |
|
|
117 | "name": self.name, | |
117 |
|
|
118 | "utc_timestamp": self.utc_timestamp, | |
118 |
|
|
119 | "actor_ip": self.actor_ip, | |
119 | 'actor': { |
|
120 | "actor": {"username": self.actor.username, "user_id": self.actor.user_id}, | |
120 |
|
|
121 | "server_url": self.server_url, | |
121 | 'user_id': self.actor.user_id |
|
|||
122 | }, |
|
|||
123 | 'server_url': self.server_url |
|
|||
124 | } |
|
122 | } | |
125 | return data |
|
123 | return data | |
126 |
|
124 | |||
@@ -129,13 +127,14 b' class RhodeCodeIntegrationEvent(Rhodecod' | |||||
129 | """ |
|
127 | """ | |
130 | Special subclass for Integration events |
|
128 | Special subclass for Integration events | |
131 | """ |
|
129 | """ | |
132 | description = '' |
|
130 | ||
|
131 | description = "" | |||
133 |
|
132 | |||
134 |
|
133 | |||
135 | class FtsBuild(RhodecodeEvent): |
|
134 | class FtsBuild(RhodecodeEvent): | |
136 | """ |
|
135 | """ | |
137 | This event will be triggered when FTS Build is triggered |
|
136 | This event will be triggered when FTS Build is triggered | |
138 | """ |
|
137 | """ | |
139 | name = 'fts-build' |
|
|||
140 | display_name = 'Start FTS Build' |
|
|||
141 |
|
138 | |||
|
139 | name = "fts-build" | |||
|
140 | display_name = "Start FTS Build" |
@@ -24,20 +24,23 b' class IUserRegistered(Interface):' | |||||
24 | An event type that is emitted whenever a new user registers a user |
|
24 | An event type that is emitted whenever a new user registers a user | |
25 | account. |
|
25 | account. | |
26 | """ |
|
26 | """ | |
27 | user = Attribute('The user object.') |
|
27 | ||
28 | session = Attribute('The session while processing the register form post.') |
|
28 | user = Attribute("The user object.") | |
|
29 | session = Attribute("The session while processing the register form post.") | |||
29 |
|
30 | |||
30 |
|
31 | |||
31 | class IUserPreCreate(Interface): |
|
32 | class IUserPreCreate(Interface): | |
32 | """ |
|
33 | """ | |
33 | An event type that is emitted before a new user object is created. |
|
34 | An event type that is emitted before a new user object is created. | |
34 | """ |
|
35 | """ | |
35 | user_data = Attribute('Data used to create the new user') |
|
36 | ||
|
37 | user_data = Attribute("Data used to create the new user") | |||
36 |
|
38 | |||
37 |
|
39 | |||
38 | class IUserPreUpdate(Interface): |
|
40 | class IUserPreUpdate(Interface): | |
39 | """ |
|
41 | """ | |
40 | An event type that is emitted before a user object is updated. |
|
42 | An event type that is emitted before a user object is updated. | |
41 | """ |
|
43 | """ | |
42 | user = Attribute('The not yet updated user object') |
|
44 | ||
43 |
user |
|
45 | user = Attribute("The not yet updated user object") | |
|
46 | user_data = Attribute("Data used to update the user") |
@@ -19,7 +19,7 b'' | |||||
19 | import logging |
|
19 | import logging | |
20 |
|
20 | |||
21 | from rhodecode.translation import lazy_ugettext |
|
21 | from rhodecode.translation import lazy_ugettext | |
22 |
from rhodecode.events.repo import |
|
22 | from rhodecode.events.repo import RepoEvent, _commits_as_dict, _issues_as_dict | |
23 |
|
23 | |||
24 | log = logging.getLogger(__name__) |
|
24 | log = logging.getLogger(__name__) | |
25 |
|
25 | |||
@@ -30,45 +30,44 b' class PullRequestEvent(RepoEvent):' | |||||
30 |
|
30 | |||
31 | :param pullrequest: a :class:`PullRequest` instance |
|
31 | :param pullrequest: a :class:`PullRequest` instance | |
32 | """ |
|
32 | """ | |
33 | name = 'pullrequest-event' |
|
33 | ||
34 | display_name = lazy_ugettext('pullrequest generic event') |
|
34 | name = "pullrequest-event" | |
35 | description = lazy_ugettext('All events within a context of a pull request') |
|
35 | display_name = lazy_ugettext("pullrequest generic event") | |
|
36 | description = lazy_ugettext("All events within a context of a pull request") | |||
36 |
|
37 | |||
37 | def __init__(self, pullrequest): |
|
38 | def __init__(self, pullrequest, context=None): | |
38 | super().__init__(pullrequest.target_repo) |
|
39 | super().__init__(pullrequest.target_repo, context=context) | |
39 | self.pullrequest = pullrequest |
|
40 | self.pullrequest = pullrequest | |
|
41 | self.context = self._context | |||
40 |
|
42 | |||
41 | def as_dict(self): |
|
43 | def as_dict(self): | |
42 | from rhodecode.lib.utils2 import md5_safe |
|
44 | from rhodecode.lib.utils2 import md5_safe | |
43 | from rhodecode.model.pull_request import PullRequestModel |
|
45 | from rhodecode.model.pull_request import PullRequestModel | |
|
46 | ||||
44 | data = super().as_dict() |
|
47 | data = super().as_dict() | |
45 |
|
48 | |||
46 | commits = _commits_as_dict( |
|
49 | commits = _commits_as_dict(self, commit_ids=self.pullrequest.revisions, repos=[self.pullrequest.source_repo]) | |
47 | self, |
|
|||
48 | commit_ids=self.pullrequest.revisions, |
|
|||
49 | repos=[self.pullrequest.source_repo] |
|
|||
50 | ) |
|
|||
51 | issues = _issues_as_dict(commits) |
|
50 | issues = _issues_as_dict(commits) | |
52 | # calculate hashes of all commits for unique identifier of commits |
|
51 | # calculate hashes of all commits for unique identifier of commits | |
53 | # inside that pull request |
|
52 | # inside that pull request | |
54 |
commits_hash = md5_safe( |
|
53 | commits_hash = md5_safe(":".join(x.get("raw_id", "") for x in commits)) | |
55 |
|
54 | |||
56 |
data.update( |
|
55 | data.update( | |
57 |
|
|
56 | { | |
58 |
|
|
57 | "pullrequest": { | |
59 | 'issues': issues, |
|
58 | "title": self.pullrequest.title, | |
60 | 'pull_request_id': self.pullrequest.pull_request_id, |
|
59 | "issues": issues, | |
61 | 'url': PullRequestModel().get_url( |
|
60 | "pull_request_id": self.pullrequest.pull_request_id, | |
62 | self.pullrequest, request=self.request), |
|
61 | "url": PullRequestModel().get_url(self.pullrequest, request=self.request), | |
63 |
|
|
62 | "permalink_url": PullRequestModel().get_url(self.pullrequest, request=self.request, permalink=True), | |
64 |
self.pullrequest, request=self.request |
|
63 | "shadow_url": PullRequestModel().get_shadow_clone_url(self.pullrequest, request=self.request), | |
65 | 'shadow_url': PullRequestModel().get_shadow_clone_url( |
|
64 | "status": self.pullrequest.calculated_review_status(), | |
66 | self.pullrequest, request=self.request), |
|
65 | "commits_uid": commits_hash, | |
67 | 'status': self.pullrequest.calculated_review_status(), |
|
66 | "commits": commits, | |
68 | 'commits_uid': commits_hash, |
|
67 | }, | |
69 |
|
|
68 | "context": self.context, | |
70 | } |
|
69 | } | |
71 |
|
|
70 | ) | |
72 | return data |
|
71 | return data | |
73 |
|
72 | |||
74 |
|
73 | |||
@@ -77,9 +76,10 b' class PullRequestCreateEvent(PullRequest' | |||||
77 | An instance of this class is emitted as an :term:`event` after a pull |
|
76 | An instance of this class is emitted as an :term:`event` after a pull | |
78 | request is created. |
|
77 | request is created. | |
79 | """ |
|
78 | """ | |
80 | name = 'pullrequest-create' |
|
79 | ||
81 |
|
|
80 | name = "pullrequest-create" | |
82 |
d |
|
81 | display_name = lazy_ugettext("pullrequest created") | |
|
82 | description = lazy_ugettext("Event triggered after pull request was created") | |||
83 |
|
83 | |||
84 |
|
84 | |||
85 | class PullRequestCloseEvent(PullRequestEvent): |
|
85 | class PullRequestCloseEvent(PullRequestEvent): | |
@@ -87,9 +87,10 b' class PullRequestCloseEvent(PullRequestE' | |||||
87 | An instance of this class is emitted as an :term:`event` after a pull |
|
87 | An instance of this class is emitted as an :term:`event` after a pull | |
88 | request is closed. |
|
88 | request is closed. | |
89 | """ |
|
89 | """ | |
90 | name = 'pullrequest-close' |
|
90 | ||
91 |
|
|
91 | name = "pullrequest-close" | |
92 |
d |
|
92 | display_name = lazy_ugettext("pullrequest closed") | |
|
93 | description = lazy_ugettext("Event triggered after pull request was closed") | |||
93 |
|
94 | |||
94 |
|
95 | |||
95 | class PullRequestUpdateEvent(PullRequestEvent): |
|
96 | class PullRequestUpdateEvent(PullRequestEvent): | |
@@ -97,9 +98,10 b' class PullRequestUpdateEvent(PullRequest' | |||||
97 | An instance of this class is emitted as an :term:`event` after a pull |
|
98 | An instance of this class is emitted as an :term:`event` after a pull | |
98 | request's commits have been updated. |
|
99 | request's commits have been updated. | |
99 | """ |
|
100 | """ | |
100 | name = 'pullrequest-update' |
|
101 | ||
101 | display_name = lazy_ugettext('pullrequest commits updated') |
|
102 | name = "pullrequest-update" | |
102 |
d |
|
103 | display_name = lazy_ugettext("pullrequest commits updated") | |
|
104 | description = lazy_ugettext("Event triggered after pull requests was updated") | |||
103 |
|
105 | |||
104 |
|
106 | |||
105 | class PullRequestReviewEvent(PullRequestEvent): |
|
107 | class PullRequestReviewEvent(PullRequestEvent): | |
@@ -107,13 +109,13 b' class PullRequestReviewEvent(PullRequest' | |||||
107 | An instance of this class is emitted as an :term:`event` after a pull |
|
109 | An instance of this class is emitted as an :term:`event` after a pull | |
108 | request review has changed. A status defines new status of review. |
|
110 | request review has changed. A status defines new status of review. | |
109 | """ |
|
111 | """ | |
110 | name = 'pullrequest-review' |
|
|||
111 | display_name = lazy_ugettext('pullrequest review changed') |
|
|||
112 | description = lazy_ugettext('Event triggered after a review status of a ' |
|
|||
113 | 'pull requests has changed to other.') |
|
|||
114 |
|
112 | |||
115 | def __init__(self, pullrequest, status): |
|
113 | name = "pullrequest-review" | |
116 | super().__init__(pullrequest) |
|
114 | display_name = lazy_ugettext("pullrequest review changed") | |
|
115 | description = lazy_ugettext("Event triggered after a review status of a pull requests has changed to other.") | |||
|
116 | ||||
|
117 | def __init__(self, pullrequest, status, context=None): | |||
|
118 | super().__init__(pullrequest, context=context) | |||
117 | self.status = status |
|
119 | self.status = status | |
118 |
|
120 | |||
119 |
|
121 | |||
@@ -122,10 +124,10 b' class PullRequestMergeEvent(PullRequestE' | |||||
122 | An instance of this class is emitted as an :term:`event` after a pull |
|
124 | An instance of this class is emitted as an :term:`event` after a pull | |
123 | request is merged. |
|
125 | request is merged. | |
124 | """ |
|
126 | """ | |
125 | name = 'pullrequest-merge' |
|
127 | ||
126 |
|
|
128 | name = "pullrequest-merge" | |
127 | description = lazy_ugettext('Event triggered after a successful merge operation ' |
|
129 | display_name = lazy_ugettext("pullrequest merged") | |
128 | 'was executed on a pull request') |
|
130 | description = lazy_ugettext("Event triggered after a successful merge operation was executed on a pull request") | |
129 |
|
131 | |||
130 |
|
132 | |||
131 | class PullRequestCommentEvent(PullRequestEvent): |
|
133 | class PullRequestCommentEvent(PullRequestEvent): | |
@@ -133,37 +135,39 b' class PullRequestCommentEvent(PullReques' | |||||
133 | An instance of this class is emitted as an :term:`event` after a pull |
|
135 | An instance of this class is emitted as an :term:`event` after a pull | |
134 | request comment is created. |
|
136 | request comment is created. | |
135 | """ |
|
137 | """ | |
136 | name = 'pullrequest-comment' |
|
|||
137 | display_name = lazy_ugettext('pullrequest commented') |
|
|||
138 | description = lazy_ugettext('Event triggered after a comment was made on a code ' |
|
|||
139 | 'in the pull request') |
|
|||
140 |
|
138 | |||
141 |
|
|
139 | name = "pullrequest-comment" | |
142 | super().__init__(pullrequest) |
|
140 | display_name = lazy_ugettext("pullrequest commented") | |
|
141 | description = lazy_ugettext("Event triggered after a comment was made on a code in the pull request") | |||
|
142 | ||||
|
143 | def __init__(self, pullrequest, comment, context=None): | |||
|
144 | super().__init__(pullrequest, context=context) | |||
143 | self.comment = comment |
|
145 | self.comment = comment | |
144 |
|
146 | |||
145 | def as_dict(self): |
|
147 | def as_dict(self): | |
146 | from rhodecode.model.comment import CommentsModel |
|
148 | from rhodecode.model.comment import CommentsModel | |
|
149 | ||||
147 | data = super().as_dict() |
|
150 | data = super().as_dict() | |
148 |
|
151 | |||
149 | status = None |
|
152 | status = None | |
150 | if self.comment.status_change: |
|
153 | if self.comment.status_change: | |
151 | status = self.comment.review_status |
|
154 | status = self.comment.review_status | |
152 |
|
155 | |||
153 |
data.update( |
|
156 | data.update( | |
154 |
|
|
157 | { | |
155 |
|
|
158 | "comment": { | |
156 |
|
|
159 | "status": status, | |
157 |
|
|
160 | "text": self.comment.text, | |
158 |
|
|
161 | "type": self.comment.comment_type, | |
159 |
|
|
162 | "file": self.comment.f_path, | |
160 |
|
|
163 | "line": self.comment.line_no, | |
161 | 'url': CommentsModel().get_url( |
|
164 | "version": self.comment.last_version, | |
162 | self.comment, request=self.request), |
|
165 | "url": CommentsModel().get_url(self.comment, request=self.request), | |
163 |
|
|
166 | "permalink_url": CommentsModel().get_url(self.comment, request=self.request, permalink=True), | |
164 | self.comment, request=self.request, permalink=True), |
|
167 | }, | |
|
168 | "context": self.context, | |||
165 | } |
|
169 | } | |
166 |
|
|
170 | ) | |
167 | return data |
|
171 | return data | |
168 |
|
172 | |||
169 |
|
173 | |||
@@ -172,10 +176,10 b' class PullRequestCommentEditEvent(PullRe' | |||||
172 | An instance of this class is emitted as an :term:`event` after a pull |
|
176 | An instance of this class is emitted as an :term:`event` after a pull | |
173 | request comment is edited. |
|
177 | request comment is edited. | |
174 | """ |
|
178 | """ | |
175 | name = 'pullrequest-comment-edit' |
|
179 | ||
176 |
|
|
180 | name = "pullrequest-comment-edit" | |
177 | description = lazy_ugettext('Event triggered after a comment was edited on a code ' |
|
181 | display_name = lazy_ugettext("pullrequest comment edited") | |
178 | 'in the pull request') |
|
182 | description = lazy_ugettext("Event triggered after a comment was edited on a code in the pull request") | |
179 |
|
183 | |||
180 | def __init__(self, pullrequest, comment): |
|
184 | def __init__(self, pullrequest, comment): | |
181 | super().__init__(pullrequest) |
|
185 | super().__init__(pullrequest) | |
@@ -183,24 +187,26 b' class PullRequestCommentEditEvent(PullRe' | |||||
183 |
|
187 | |||
184 | def as_dict(self): |
|
188 | def as_dict(self): | |
185 | from rhodecode.model.comment import CommentsModel |
|
189 | from rhodecode.model.comment import CommentsModel | |
|
190 | ||||
186 | data = super().as_dict() |
|
191 | data = super().as_dict() | |
187 |
|
192 | |||
188 | status = None |
|
193 | status = None | |
189 | if self.comment.status_change: |
|
194 | if self.comment.status_change: | |
190 | status = self.comment.review_status |
|
195 | status = self.comment.review_status | |
191 |
|
196 | |||
192 |
data.update( |
|
197 | data.update( | |
193 |
|
|
198 | { | |
194 |
|
|
199 | "comment": { | |
195 |
|
|
200 | "status": status, | |
196 |
|
|
201 | "text": self.comment.text, | |
197 |
|
|
202 | "type": self.comment.comment_type, | |
198 |
|
|
203 | "file": self.comment.f_path, | |
199 |
|
|
204 | "line": self.comment.line_no, | |
200 | 'url': CommentsModel().get_url( |
|
205 | "version": self.comment.last_version, | |
201 | self.comment, request=self.request), |
|
206 | "url": CommentsModel().get_url(self.comment, request=self.request), | |
202 |
|
|
207 | "permalink_url": CommentsModel().get_url(self.comment, request=self.request, permalink=True), | |
203 | self.comment, request=self.request, permalink=True), |
|
208 | }, | |
|
209 | "context": self.context | |||
204 | } |
|
210 | } | |
205 |
|
|
211 | ) | |
206 | return data |
|
212 | return data |
@@ -37,12 +37,11 b' def _commits_as_dict(event, commit_ids, ' | |||||
37 | :param repos: a list of repos to check |
|
37 | :param repos: a list of repos to check | |
38 | """ |
|
38 | """ | |
39 | from rhodecode.lib.utils2 import extract_mentioned_users |
|
39 | from rhodecode.lib.utils2 import extract_mentioned_users | |
40 | from rhodecode.lib.helpers import ( |
|
40 | from rhodecode.lib.helpers import urlify_commit_message, process_patterns, chop_at_smart | |
41 | urlify_commit_message, process_patterns, chop_at_smart) |
|
|||
42 | from rhodecode.model.repo import RepoModel |
|
41 | from rhodecode.model.repo import RepoModel | |
43 |
|
42 | |||
44 | if not repos: |
|
43 | if not repos: | |
45 |
raise Exception( |
|
44 | raise Exception("no repo defined") | |
46 |
|
45 | |||
47 | if not isinstance(repos, (tuple, list)): |
|
46 | if not isinstance(repos, (tuple, list)): | |
48 | repos = [repos] |
|
47 | repos = [repos] | |
@@ -63,37 +62,31 b' def _commits_as_dict(event, commit_ids, ' | |||||
63 | try: |
|
62 | try: | |
64 | # use copy of needed_commits since we modify it while iterating |
|
63 | # use copy of needed_commits since we modify it while iterating | |
65 | for commit_id in list(needed_commits): |
|
64 | for commit_id in list(needed_commits): | |
66 |
if commit_id.startswith( |
|
65 | if commit_id.startswith("tag=>"): | |
67 | raw_id = commit_id[5:] |
|
66 | raw_id = commit_id[5:] | |
68 | cs_data = { |
|
67 | cs_data = { | |
69 |
|
|
68 | "raw_id": commit_id, | |
70 |
|
|
69 | "short_id": commit_id, | |
71 |
|
|
70 | "branch": None, | |
72 |
|
|
71 | "git_ref_change": "tag_add", | |
73 | 'author': event.actor.full_contact, |
|
72 | "message": f"Added new tag {raw_id}", | |
74 | 'date': datetime.datetime.now(), |
|
73 | "author": event.actor.full_contact, | |
75 |
|
|
74 | "date": datetime.datetime.now(), | |
76 |
|
|
75 | "refs": {"branches": [], "bookmarks": [], "tags": []}, | |
77 | 'bookmarks': [], |
|
|||
78 | 'tags': [] |
|
|||
79 | } |
|
|||
80 | } |
|
76 | } | |
81 | commits.append(cs_data) |
|
77 | commits.append(cs_data) | |
82 |
|
78 | |||
83 |
elif commit_id.startswith( |
|
79 | elif commit_id.startswith("delete_branch=>"): | |
84 | raw_id = commit_id[15:] |
|
80 | raw_id = commit_id[15:] | |
85 | cs_data = { |
|
81 | cs_data = { | |
86 |
|
|
82 | "raw_id": commit_id, | |
87 |
|
|
83 | "short_id": commit_id, | |
88 |
|
|
84 | "branch": None, | |
89 |
|
|
85 | "git_ref_change": "branch_delete", | |
90 | 'author': event.actor.full_contact, |
|
86 | "message": f"Deleted branch {raw_id}", | |
91 | 'date': datetime.datetime.now(), |
|
87 | "author": event.actor.full_contact, | |
92 |
|
|
88 | "date": datetime.datetime.now(), | |
93 |
|
|
89 | "refs": {"branches": [], "bookmarks": [], "tags": []}, | |
94 | 'bookmarks': [], |
|
|||
95 | 'tags': [] |
|
|||
96 | } |
|
|||
97 | } |
|
90 | } | |
98 | commits.append(cs_data) |
|
91 | commits.append(cs_data) | |
99 |
|
92 | |||
@@ -104,40 +97,35 b' def _commits_as_dict(event, commit_ids, ' | |||||
104 | continue # maybe its in next repo |
|
97 | continue # maybe its in next repo | |
105 |
|
98 | |||
106 | cs_data = cs.__json__() |
|
99 | cs_data = cs.__json__() | |
107 |
cs_data[ |
|
100 | cs_data["refs"] = cs._get_refs() | |
108 |
|
101 | |||
109 |
cs_data[ |
|
102 | cs_data["mentions"] = extract_mentioned_users(cs_data["message"]) | |
110 |
cs_data[ |
|
103 | cs_data["reviewers"] = reviewers | |
111 |
cs_data[ |
|
104 | cs_data["url"] = RepoModel().get_commit_url(repo, cs_data["raw_id"], request=event.request) | |
112 | repo, cs_data['raw_id'], request=event.request) |
|
105 | cs_data["permalink_url"] = RepoModel().get_commit_url( | |
113 | cs_data['permalink_url'] = RepoModel().get_commit_url( |
|
106 | repo, cs_data["raw_id"], request=event.request, permalink=True | |
114 | repo, cs_data['raw_id'], request=event.request, |
|
107 | ) | |
115 | permalink=True) |
|
108 | urlified_message, issues_data, errors = process_patterns(cs_data["message"], repo.repo_name) | |
116 | urlified_message, issues_data, errors = process_patterns( |
|
109 | cs_data["issues"] = issues_data | |
117 |
|
|
110 | cs_data["message_html"] = urlify_commit_message(cs_data["message"], repo.repo_name) | |
118 | cs_data['issues'] = issues_data |
|
111 | cs_data["message_html_title"] = chop_at_smart(cs_data["message"], "\n", suffix_if_chopped="...") | |
119 | cs_data['message_html'] = urlify_commit_message( |
|
|||
120 | cs_data['message'], repo.repo_name) |
|
|||
121 | cs_data['message_html_title'] = chop_at_smart( |
|
|||
122 | cs_data['message'], '\n', suffix_if_chopped='...') |
|
|||
123 | commits.append(cs_data) |
|
112 | commits.append(cs_data) | |
124 |
|
113 | |||
125 | needed_commits.remove(commit_id) |
|
114 | needed_commits.remove(commit_id) | |
126 |
|
115 | |||
127 | except Exception: |
|
116 | except Exception: | |
128 |
log.exception( |
|
117 | log.exception("Failed to extract commits data") | |
129 | # we don't send any commits when crash happens, only full list |
|
118 | # we don't send any commits when crash happens, only full list | |
130 | # matters we short circuit then. |
|
119 | # matters we short circuit then. | |
131 | return [] |
|
120 | return [] | |
132 |
|
121 | |||
133 | # we failed to remove all needed_commits from all repositories |
|
122 | # we failed to remove all needed_commits from all repositories | |
134 | if needed_commits: |
|
123 | if needed_commits: | |
135 |
raise ValueError(f |
|
124 | raise ValueError(f"Unexpectedly not found {needed_commits} in all available repos {repos}") | |
136 |
|
125 | |||
137 |
missing_commits = set(commit_ids) - set(c[ |
|
126 | missing_commits = set(commit_ids) - set(c["raw_id"] for c in commits) | |
138 | if missing_commits: |
|
127 | if missing_commits: | |
139 |
log.error( |
|
128 | log.error("Inconsistent repository state. " "Missing commits: %s", ", ".join(missing_commits)) | |
140 | 'Missing commits: %s', ', '.join(missing_commits)) |
|
|||
141 |
|
129 | |||
142 | return commits |
|
130 | return commits | |
143 |
|
131 | |||
@@ -146,8 +134,8 b' def _issues_as_dict(commits):' | |||||
146 |
""" |
|
134 | """Helper function to serialize issues from commits""" | |
147 | issues = {} |
|
135 | issues = {} | |
148 | for commit in commits: |
|
136 | for commit in commits: | |
149 |
for issue in commit[ |
|
137 | for issue in commit["issues"]: | |
150 |
issues[issue[ |
|
138 | issues[issue["id"]] = issue | |
151 | return issues |
|
139 | return issues | |
152 |
|
140 | |||
153 |
|
141 | |||
@@ -156,33 +144,36 b' class RepoEvent(RhodeCodeIntegrationEven' | |||||
156 | Base class for events acting on a repository. |
|
144 | Base class for events acting on a repository. | |
157 | """ |
|
145 | """ | |
158 |
|
146 | |||
159 | def __init__(self, repo, actor=None): |
|
147 | def __init__(self, repo, actor=None, context=None): | |
160 | """ |
|
148 | """ | |
161 | :param repo: a :class:`Repository` instance |
|
149 | :param repo: a :class:`Repository` instance | |
162 | """ |
|
150 | """ | |
163 | super().__init__(actor=actor) |
|
151 | super().__init__(actor=actor, context=context) | |
164 | self.repo = repo |
|
152 | self.repo = repo | |
|
153 | self.context = self._context | |||
165 |
|
154 | |||
166 | def as_dict(self): |
|
155 | def as_dict(self): | |
167 | from rhodecode.model.repo import RepoModel |
|
156 | from rhodecode.model.repo import RepoModel | |
|
157 | ||||
168 | data = super().as_dict() |
|
158 | data = super().as_dict() | |
169 |
|
159 | |||
170 | extra_fields = collections.OrderedDict() |
|
160 | extra_fields = collections.OrderedDict() | |
171 | for field in self.repo.extra_fields: |
|
161 | for field in self.repo.extra_fields: | |
172 | extra_fields[field.field_key] = field.field_value |
|
162 | extra_fields[field.field_key] = field.field_value | |
173 |
|
163 | |||
174 |
data.update( |
|
164 | data.update( | |
175 |
|
|
165 | { | |
176 |
|
|
166 | "repo": { | |
177 |
|
|
167 | "repo_id": self.repo.repo_id, | |
178 |
|
|
168 | "repo_name": self.repo.repo_name, | |
179 | 'url': RepoModel().get_url( |
|
169 | "repo_type": self.repo.repo_type, | |
180 | self.repo, request=self.request), |
|
170 | "url": RepoModel().get_url(self.repo, request=self.request), | |
181 |
|
|
171 | "permalink_url": RepoModel().get_url(self.repo, request=self.request, permalink=True), | |
182 | self.repo, request=self.request, permalink=True), |
|
172 | "extra_fields": extra_fields, | |
183 | 'extra_fields': extra_fields |
|
173 | }, | |
|
174 | "context": self.context, | |||
184 | } |
|
175 | } | |
185 |
|
|
176 | ) | |
186 | return data |
|
177 | return data | |
187 |
|
178 | |||
188 |
|
179 | |||
@@ -192,32 +183,32 b' class RepoCommitCommentEvent(RepoEvent):' | |||||
192 | on repository commit. |
|
183 | on repository commit. | |
193 | """ |
|
184 | """ | |
194 |
|
185 | |||
195 |
name = |
|
186 | name = "repo-commit-comment" | |
196 |
display_name = lazy_ugettext( |
|
187 | display_name = lazy_ugettext("repository commit comment") | |
197 |
description = lazy_ugettext( |
|
188 | description = lazy_ugettext("Event triggered after a comment was made on commit inside a repository") | |
198 | 'on commit inside a repository') |
|
|||
199 |
|
189 | |||
200 | def __init__(self, repo, commit, comment): |
|
190 | def __init__(self, repo, commit, comment, context=None): | |
201 | super().__init__(repo) |
|
191 | super().__init__(repo, context=context) | |
202 | self.commit = commit |
|
192 | self.commit = commit | |
203 | self.comment = comment |
|
193 | self.comment = comment | |
204 |
|
194 | |||
205 | def as_dict(self): |
|
195 | def as_dict(self): | |
206 | data = super().as_dict() |
|
196 | data = super().as_dict() | |
207 |
data[ |
|
197 | data["commit"] = { | |
208 |
|
|
198 | "commit_id": self.commit.raw_id, | |
209 |
|
|
199 | "commit_message": self.commit.message, | |
210 |
|
|
200 | "commit_branch": self.commit.branch, | |
211 | } |
|
201 | } | |
212 |
|
202 | |||
213 |
data[ |
|
203 | data["comment"] = { | |
214 |
|
|
204 | "comment_id": self.comment.comment_id, | |
215 |
|
|
205 | "comment_text": self.comment.text, | |
216 |
|
|
206 | "comment_type": self.comment.comment_type, | |
217 |
|
|
207 | "comment_f_path": self.comment.f_path, | |
218 |
|
|
208 | "comment_line_no": self.comment.line_no, | |
219 |
|
|
209 | "comment_version": self.comment.last_version, | |
220 | } |
|
210 | } | |
|
211 | data["contex"] = self.context | |||
221 | return data |
|
212 | return data | |
222 |
|
213 | |||
223 |
|
214 | |||
@@ -227,32 +218,32 b' class RepoCommitCommentEditEvent(RepoEve' | |||||
227 | on repository commit. |
|
218 | on repository commit. | |
228 | """ |
|
219 | """ | |
229 |
|
220 | |||
230 |
name = |
|
221 | name = "repo-commit-edit-comment" | |
231 |
display_name = lazy_ugettext( |
|
222 | display_name = lazy_ugettext("repository commit edit comment") | |
232 |
description = lazy_ugettext( |
|
223 | description = lazy_ugettext("Event triggered after a comment was edited on commit inside a repository") | |
233 | 'on commit inside a repository') |
|
|||
234 |
|
224 | |||
235 | def __init__(self, repo, commit, comment): |
|
225 | def __init__(self, repo, commit, comment, context=None): | |
236 | super().__init__(repo) |
|
226 | super().__init__(repo, context=context) | |
237 | self.commit = commit |
|
227 | self.commit = commit | |
238 | self.comment = comment |
|
228 | self.comment = comment | |
239 |
|
229 | |||
240 | def as_dict(self): |
|
230 | def as_dict(self): | |
241 | data = super().as_dict() |
|
231 | data = super().as_dict() | |
242 |
data[ |
|
232 | data["commit"] = { | |
243 |
|
|
233 | "commit_id": self.commit.raw_id, | |
244 |
|
|
234 | "commit_message": self.commit.message, | |
245 |
|
|
235 | "commit_branch": self.commit.branch, | |
246 | } |
|
236 | } | |
247 |
|
237 | |||
248 |
data[ |
|
238 | data["comment"] = { | |
249 |
|
|
239 | "comment_id": self.comment.comment_id, | |
250 |
|
|
240 | "comment_text": self.comment.text, | |
251 |
|
|
241 | "comment_type": self.comment.comment_type, | |
252 |
|
|
242 | "comment_f_path": self.comment.f_path, | |
253 |
|
|
243 | "comment_line_no": self.comment.line_no, | |
254 |
|
|
244 | "comment_version": self.comment.last_version, | |
255 | } |
|
245 | } | |
|
246 | data["context"] = "context" | |||
256 | return data |
|
247 | return data | |
257 |
|
248 | |||
258 |
|
249 | |||
@@ -261,9 +252,10 b' class RepoPreCreateEvent(RepoEvent):' | |||||
261 | An instance of this class is emitted as an :term:`event` before a repo is |
|
252 | An instance of this class is emitted as an :term:`event` before a repo is | |
262 | created. |
|
253 | created. | |
263 | """ |
|
254 | """ | |
264 | name = 'repo-pre-create' |
|
255 | ||
265 | display_name = lazy_ugettext('repository pre create') |
|
256 | name = "repo-pre-create" | |
266 |
d |
|
257 | display_name = lazy_ugettext("repository pre create") | |
|
258 | description = lazy_ugettext("Event triggered before repository is created") | |||
267 |
|
259 | |||
268 |
|
260 | |||
269 | class RepoCreateEvent(RepoEvent): |
|
261 | class RepoCreateEvent(RepoEvent): | |
@@ -271,9 +263,10 b' class RepoCreateEvent(RepoEvent):' | |||||
271 | An instance of this class is emitted as an :term:`event` whenever a repo is |
|
263 | An instance of this class is emitted as an :term:`event` whenever a repo is | |
272 | created. |
|
264 | created. | |
273 | """ |
|
265 | """ | |
274 | name = 'repo-create' |
|
266 | ||
275 | display_name = lazy_ugettext('repository created') |
|
267 | name = "repo-create" | |
276 |
d |
|
268 | display_name = lazy_ugettext("repository created") | |
|
269 | description = lazy_ugettext("Event triggered after repository was created") | |||
277 |
|
270 | |||
278 |
|
271 | |||
279 | class RepoPreDeleteEvent(RepoEvent): |
|
272 | class RepoPreDeleteEvent(RepoEvent): | |
@@ -281,9 +274,10 b' class RepoPreDeleteEvent(RepoEvent):' | |||||
281 | An instance of this class is emitted as an :term:`event` whenever a repo is |
|
274 | An instance of this class is emitted as an :term:`event` whenever a repo is | |
282 | created. |
|
275 | created. | |
283 | """ |
|
276 | """ | |
284 | name = 'repo-pre-delete' |
|
277 | ||
285 | display_name = lazy_ugettext('repository pre delete') |
|
278 | name = "repo-pre-delete" | |
286 |
d |
|
279 | display_name = lazy_ugettext("repository pre delete") | |
|
280 | description = lazy_ugettext("Event triggered before a repository is deleted") | |||
287 |
|
281 | |||
288 |
|
282 | |||
289 | class RepoDeleteEvent(RepoEvent): |
|
283 | class RepoDeleteEvent(RepoEvent): | |
@@ -291,43 +285,45 b' class RepoDeleteEvent(RepoEvent):' | |||||
291 | An instance of this class is emitted as an :term:`event` whenever a repo is |
|
285 | An instance of this class is emitted as an :term:`event` whenever a repo is | |
292 | created. |
|
286 | created. | |
293 | """ |
|
287 | """ | |
294 | name = 'repo-delete' |
|
288 | ||
295 | display_name = lazy_ugettext('repository deleted') |
|
289 | name = "repo-delete" | |
296 |
d |
|
290 | display_name = lazy_ugettext("repository deleted") | |
|
291 | description = lazy_ugettext("Event triggered after repository was deleted") | |||
297 |
|
292 | |||
298 |
|
293 | |||
299 | class RepoVCSEvent(RepoEvent): |
|
294 | class RepoVCSEvent(RepoEvent): | |
300 | """ |
|
295 | """ | |
301 | Base class for events triggered by the VCS |
|
296 | Base class for events triggered by the VCS | |
302 | """ |
|
297 | """ | |
303 | name = '' |
|
|||
304 | display_name = 'generic_vcs_event' |
|
|||
305 |
|
298 | |||
306 | def __init__(self, repo_name, extras): |
|
299 | name = "" | |
|
300 | display_name = "generic_vcs_event" | |||
|
301 | ||||
|
302 | def __init__(self, repo_name, extras, context=None): | |||
307 | self.repo = Repository.get_by_repo_name(repo_name) |
|
303 | self.repo = Repository.get_by_repo_name(repo_name) | |
308 | if not self.repo: |
|
304 | if not self.repo: | |
309 |
raise Exception(f |
|
305 | raise Exception(f"repo by this name {repo_name} does not exist") | |
310 | self.extras = extras |
|
306 | self.extras = extras | |
311 | super().__init__(self.repo) |
|
307 | super().__init__(self.repo, context=context) | |
312 |
|
308 | |||
313 | @property |
|
309 | @property | |
314 | def actor(self): |
|
310 | def actor(self): | |
315 |
if self.extras.get( |
|
311 | if self.extras.get("username"): | |
316 |
return User.get_by_username(self.extras[ |
|
312 | return User.get_by_username(self.extras["username"]) | |
317 |
|
313 | |||
318 | @property |
|
314 | @property | |
319 | def actor_ip(self): |
|
315 | def actor_ip(self): | |
320 |
if self.extras.get( |
|
316 | if self.extras.get("ip"): | |
321 |
return self.extras[ |
|
317 | return self.extras["ip"] | |
322 |
|
318 | |||
323 | @property |
|
319 | @property | |
324 | def server_url(self): |
|
320 | def server_url(self): | |
325 |
if self.extras.get( |
|
321 | if self.extras.get("server_url"): | |
326 |
return self.extras[ |
|
322 | return self.extras["server_url"] | |
327 |
|
323 | |||
328 | @property |
|
324 | @property | |
329 | def request(self): |
|
325 | def request(self): | |
330 |
return self.extras.get( |
|
326 | return self.extras.get("request") or self.get_request() | |
331 |
|
327 | |||
332 |
|
328 | |||
333 | class RepoPrePullEvent(RepoVCSEvent): |
|
329 | class RepoPrePullEvent(RepoVCSEvent): | |
@@ -335,9 +331,10 b' class RepoPrePullEvent(RepoVCSEvent):' | |||||
335 | An instance of this class is emitted as an :term:`event` before commits |
|
331 | An instance of this class is emitted as an :term:`event` before commits | |
336 | are pulled from a repo. |
|
332 | are pulled from a repo. | |
337 | """ |
|
333 | """ | |
338 | name = 'repo-pre-pull' |
|
334 | ||
339 | display_name = lazy_ugettext('repository pre pull') |
|
335 | name = "repo-pre-pull" | |
340 | description = lazy_ugettext('Event triggered before repository code is pulled') |
|
336 | display_name = lazy_ugettext("repository pre pull") | |
|
337 | description = lazy_ugettext("Event triggered before repository code is pulled") | |||
341 |
|
338 | |||
342 |
|
339 | |||
343 | class RepoPullEvent(RepoVCSEvent): |
|
340 | class RepoPullEvent(RepoVCSEvent): | |
@@ -345,9 +342,10 b' class RepoPullEvent(RepoVCSEvent):' | |||||
345 | An instance of this class is emitted as an :term:`event` after commits |
|
342 | An instance of this class is emitted as an :term:`event` after commits | |
346 | are pulled from a repo. |
|
343 | are pulled from a repo. | |
347 | """ |
|
344 | """ | |
348 | name = 'repo-pull' |
|
345 | ||
349 | display_name = lazy_ugettext('repository pull') |
|
346 | name = "repo-pull" | |
350 | description = lazy_ugettext('Event triggered after repository code was pulled') |
|
347 | display_name = lazy_ugettext("repository pull") | |
|
348 | description = lazy_ugettext("Event triggered after repository code was pulled") | |||
351 |
|
349 | |||
352 |
|
350 | |||
353 | class RepoPrePushEvent(RepoVCSEvent): |
|
351 | class RepoPrePushEvent(RepoVCSEvent): | |
@@ -355,10 +353,10 b' class RepoPrePushEvent(RepoVCSEvent):' | |||||
355 | An instance of this class is emitted as an :term:`event` before commits |
|
353 | An instance of this class is emitted as an :term:`event` before commits | |
356 | are pushed to a repo. |
|
354 | are pushed to a repo. | |
357 | """ |
|
355 | """ | |
358 | name = 'repo-pre-push' |
|
356 | ||
359 | display_name = lazy_ugettext('repository pre push') |
|
357 | name = "repo-pre-push" | |
360 | description = lazy_ugettext('Event triggered before the code is ' |
|
358 | display_name = lazy_ugettext("repository pre push") | |
361 | 'pushed to a repository') |
|
359 | description = lazy_ugettext("Event triggered before the code is pushed to a repository") | |
362 |
|
360 | |||
363 |
|
361 | |||
364 | class RepoPushEvent(RepoVCSEvent): |
|
362 | class RepoPushEvent(RepoVCSEvent): | |
@@ -368,13 +366,13 b' class RepoPushEvent(RepoVCSEvent):' | |||||
368 |
|
366 | |||
369 | :param extras: (optional) dict of data from proxied VCS actions |
|
367 | :param extras: (optional) dict of data from proxied VCS actions | |
370 | """ |
|
368 | """ | |
371 | name = 'repo-push' |
|
|||
372 | display_name = lazy_ugettext('repository push') |
|
|||
373 | description = lazy_ugettext('Event triggered after the code was ' |
|
|||
374 | 'pushed to a repository') |
|
|||
375 |
|
369 | |||
376 | def __init__(self, repo_name, pushed_commit_ids, extras): |
|
370 | name = "repo-push" | |
377 | super().__init__(repo_name, extras) |
|
371 | display_name = lazy_ugettext("repository push") | |
|
372 | description = lazy_ugettext("Event triggered after the code was pushed to a repository") | |||
|
373 | ||||
|
374 | def __init__(self, repo_name, pushed_commit_ids, extras, context=None): | |||
|
375 | super().__init__(repo_name, extras, context=context) | |||
378 | self.pushed_commit_ids = pushed_commit_ids |
|
376 | self.pushed_commit_ids = pushed_commit_ids | |
379 | self.new_refs = extras.new_refs |
|
377 | self.new_refs = extras.new_refs | |
380 |
|
378 | |||
@@ -382,63 +380,48 b' class RepoPushEvent(RepoVCSEvent):' | |||||
382 | data = super().as_dict() |
|
380 | data = super().as_dict() | |
383 |
|
381 | |||
384 | def branch_url(branch_name): |
|
382 | def branch_url(branch_name): | |
385 |
return |
|
383 | return "{}/changelog?branch={}".format(data["repo"]["url"], branch_name) | |
386 | data['repo']['url'], branch_name) |
|
|||
387 |
|
384 | |||
388 | def tag_url(tag_name): |
|
385 | def tag_url(tag_name): | |
389 |
return |
|
386 | return "{}/files/{}/".format(data["repo"]["url"], tag_name) | |
390 | data['repo']['url'], tag_name) |
|
|||
391 |
|
387 | |||
392 | commits = _commits_as_dict( |
|
388 | commits = _commits_as_dict(self, commit_ids=self.pushed_commit_ids, repos=[self.repo]) | |
393 | self, commit_ids=self.pushed_commit_ids, repos=[self.repo]) |
|
|||
394 |
|
389 | |||
395 | last_branch = None |
|
390 | last_branch = None | |
396 | for commit in reversed(commits): |
|
391 | for commit in reversed(commits): | |
397 |
commit[ |
|
392 | commit["branch"] = commit["branch"] or last_branch | |
398 |
last_branch = commit[ |
|
393 | last_branch = commit["branch"] | |
399 | issues = _issues_as_dict(commits) |
|
394 | issues = _issues_as_dict(commits) | |
400 |
|
395 | |||
401 | branches = set() |
|
396 | branches = set() | |
402 | tags = set() |
|
397 | tags = set() | |
403 | for commit in commits: |
|
398 | for commit in commits: | |
404 |
if commit[ |
|
399 | if commit["refs"]["tags"]: | |
405 |
for tag in commit[ |
|
400 | for tag in commit["refs"]["tags"]: | |
406 | tags.add(tag) |
|
401 | tags.add(tag) | |
407 |
if commit[ |
|
402 | if commit["branch"]: | |
408 |
branches.add(commit[ |
|
403 | branches.add(commit["branch"]) | |
409 |
|
404 | |||
410 | # maybe we have branches in new_refs ? |
|
405 | # maybe we have branches in new_refs ? | |
411 | try: |
|
406 | try: | |
412 |
branches = branches.union(set(self.new_refs[ |
|
407 | branches = branches.union(set(self.new_refs["branches"])) | |
413 | except Exception: |
|
408 | except Exception: | |
414 | pass |
|
409 | pass | |
415 |
|
410 | |||
416 | branches = [ |
|
411 | branches = [{"name": branch, "url": branch_url(branch)} for branch in branches] | |
417 | { |
|
|||
418 | 'name': branch, |
|
|||
419 | 'url': branch_url(branch) |
|
|||
420 | } |
|
|||
421 | for branch in branches |
|
|||
422 | ] |
|
|||
423 |
|
412 | |||
424 | # maybe we have branches in new_refs ? |
|
413 | # maybe we have branches in new_refs ? | |
425 | try: |
|
414 | try: | |
426 |
tags = tags.union(set(self.new_refs[ |
|
415 | tags = tags.union(set(self.new_refs["tags"])) | |
427 | except Exception: |
|
416 | except Exception: | |
428 | pass |
|
417 | pass | |
429 |
|
418 | |||
430 | tags = [ |
|
419 | tags = [{"name": tag, "url": tag_url(tag)} for tag in tags] | |
431 | { |
|
|||
432 | 'name': tag, |
|
|||
433 | 'url': tag_url(tag) |
|
|||
434 | } |
|
|||
435 | for tag in tags |
|
|||
436 | ] |
|
|||
437 |
|
420 | |||
438 |
data[ |
|
421 | data["push"] = { | |
439 |
|
|
422 | "commits": commits, | |
440 |
|
|
423 | "issues": issues, | |
441 |
|
|
424 | "branches": branches, | |
442 |
|
|
425 | "tags": tags, | |
443 | } |
|
426 | } | |
444 | return data |
|
427 | return data |
@@ -29,27 +29,31 b' class RepoGroupEvent(RhodeCodeIntegratio' | |||||
29 | """ |
|
29 | """ | |
30 | Base class for events acting on a repository group. |
|
30 | Base class for events acting on a repository group. | |
31 |
|
31 | |||
32 | :param repo: a :class:`RepositoryGroup` instance |
|
32 | :param repo_group: a :class:`RepositoryGroup` instance | |
33 | """ |
|
33 | """ | |
34 |
|
34 | |||
35 | def __init__(self, repo_group): |
|
35 | def __init__(self, repo_group, context=None): | |
36 | super().__init__() |
|
36 | super().__init__(context=context) | |
37 | self.repo_group = repo_group |
|
37 | self.repo_group = repo_group | |
|
38 | self.context = self._context | |||
38 |
|
39 | |||
39 | def as_dict(self): |
|
40 | def as_dict(self): | |
40 | data = super().as_dict() |
|
41 | data = super().as_dict() | |
41 |
data.update( |
|
42 | data.update( | |
42 |
|
|
43 | { | |
43 |
|
|
44 | "repo_group": { | |
44 |
|
|
45 | "group_id": self.repo_group.group_id, | |
45 |
|
|
46 | "group_name": self.repo_group.group_name, | |
46 |
|
|
47 | "group_parent_id": self.repo_group.group_parent_id, | |
47 |
|
|
48 | "group_description": self.repo_group.group_description, | |
48 |
|
|
49 | "user_id": self.repo_group.user_id, | |
49 |
|
|
50 | "created_by": self.repo_group.user.username, | |
50 |
|
|
51 | "created_on": self.repo_group.created_on, | |
|
52 | "enable_locking": self.repo_group.enable_locking, | |||
|
53 | }, | |||
|
54 | "context": self.context | |||
51 | } |
|
55 | } | |
52 |
|
|
56 | ) | |
53 | return data |
|
57 | return data | |
54 |
|
58 | |||
55 |
|
59 | |||
@@ -58,9 +62,10 b' class RepoGroupCreateEvent(RepoGroupEven' | |||||
58 | An instance of this class is emitted as an :term:`event` whenever a |
|
62 | An instance of this class is emitted as an :term:`event` whenever a | |
59 | repository group is created. |
|
63 | repository group is created. | |
60 | """ |
|
64 | """ | |
61 | name = 'repo-group-create' |
|
65 | ||
62 | display_name = lazy_ugettext('repository group created') |
|
66 | name = "repo-group-create" | |
63 |
d |
|
67 | display_name = lazy_ugettext("repository group created") | |
|
68 | description = lazy_ugettext("Event triggered after a repository group was created") | |||
64 |
|
69 | |||
65 |
|
70 | |||
66 | class RepoGroupDeleteEvent(RepoGroupEvent): |
|
71 | class RepoGroupDeleteEvent(RepoGroupEvent): | |
@@ -68,9 +73,10 b' class RepoGroupDeleteEvent(RepoGroupEven' | |||||
68 | An instance of this class is emitted as an :term:`event` whenever a |
|
73 | An instance of this class is emitted as an :term:`event` whenever a | |
69 | repository group is deleted. |
|
74 | repository group is deleted. | |
70 | """ |
|
75 | """ | |
71 | name = 'repo-group-delete' |
|
76 | ||
72 | display_name = lazy_ugettext('repository group deleted') |
|
77 | name = "repo-group-delete" | |
73 |
d |
|
78 | display_name = lazy_ugettext("repository group deleted") | |
|
79 | description = lazy_ugettext("Event triggered after a repository group was deleted") | |||
74 |
|
80 | |||
75 |
|
81 | |||
76 | class RepoGroupUpdateEvent(RepoGroupEvent): |
|
82 | class RepoGroupUpdateEvent(RepoGroupEvent): | |
@@ -78,6 +84,7 b' class RepoGroupUpdateEvent(RepoGroupEven' | |||||
78 | An instance of this class is emitted as an :term:`event` whenever a |
|
84 | An instance of this class is emitted as an :term:`event` whenever a | |
79 | repository group is updated. |
|
85 | repository group is updated. | |
80 | """ |
|
86 | """ | |
81 | name = 'repo-group-update' |
|
87 | ||
82 | display_name = lazy_ugettext('repository group update') |
|
88 | name = "repo-group-update" | |
83 |
d |
|
89 | display_name = lazy_ugettext("repository group update") | |
|
90 | description = lazy_ugettext("Event triggered after a repository group was updated") |
@@ -21,8 +21,7 b' from zope.interface import implementer' | |||||
21 |
|
21 | |||
22 | from rhodecode.translation import lazy_ugettext |
|
22 | from rhodecode.translation import lazy_ugettext | |
23 | from rhodecode.events.base import RhodecodeEvent, RhodeCodeIntegrationEvent |
|
23 | from rhodecode.events.base import RhodecodeEvent, RhodeCodeIntegrationEvent | |
24 |
from rhodecode.events.interfaces import |
|
24 | from rhodecode.events.interfaces import IUserRegistered, IUserPreCreate, IUserPreUpdate | |
25 | IUserRegistered, IUserPreCreate, IUserPreUpdate) |
|
|||
26 |
|
25 | |||
27 | log = logging.getLogger(__name__) |
|
26 | log = logging.getLogger(__name__) | |
28 |
|
27 | |||
@@ -33,8 +32,9 b' class UserRegistered(RhodeCodeIntegratio' | |||||
33 | An instance of this class is emitted as an :term:`event` whenever a user |
|
32 | An instance of this class is emitted as an :term:`event` whenever a user | |
34 | account is registered. |
|
33 | account is registered. | |
35 | """ |
|
34 | """ | |
36 | name = 'user-register' |
|
35 | ||
37 | display_name = lazy_ugettext('user registered') |
|
36 | name = "user-register" | |
|
37 | display_name = lazy_ugettext("user registered") | |||
38 |
|
38 | |||
39 | def __init__(self, user, session): |
|
39 | def __init__(self, user, session): | |
40 | super().__init__() |
|
40 | super().__init__() | |
@@ -48,8 +48,9 b' class UserPreCreate(RhodeCodeIntegration' | |||||
48 | An instance of this class is emitted as an :term:`event` before a new user |
|
48 | An instance of this class is emitted as an :term:`event` before a new user | |
49 | object is created. |
|
49 | object is created. | |
50 | """ |
|
50 | """ | |
51 | name = 'user-pre-create' |
|
51 | ||
52 |
|
|
52 | name = "user-pre-create" | |
|
53 | display_name = lazy_ugettext("user pre create") | |||
53 |
|
54 | |||
54 | def __init__(self, user_data): |
|
55 | def __init__(self, user_data): | |
55 | super().__init__() |
|
56 | super().__init__() | |
@@ -62,8 +63,9 b' class UserPostCreate(RhodeCodeIntegratio' | |||||
62 | An instance of this class is emitted as an :term:`event` after a new user |
|
63 | An instance of this class is emitted as an :term:`event` after a new user | |
63 | object is created. |
|
64 | object is created. | |
64 | """ |
|
65 | """ | |
65 | name = 'user-post-create' |
|
66 | ||
66 |
|
|
67 | name = "user-post-create" | |
|
68 | display_name = lazy_ugettext("user post create") | |||
67 |
|
69 | |||
68 | def __init__(self, user_data): |
|
70 | def __init__(self, user_data): | |
69 | super().__init__() |
|
71 | super().__init__() | |
@@ -76,8 +78,9 b' class UserPreUpdate(RhodeCodeIntegration' | |||||
76 | An instance of this class is emitted as an :term:`event` before a user |
|
78 | An instance of this class is emitted as an :term:`event` before a user | |
77 | object is updated. |
|
79 | object is updated. | |
78 | """ |
|
80 | """ | |
79 | name = 'user-pre-update' |
|
81 | ||
80 |
|
|
82 | name = "user-pre-update" | |
|
83 | display_name = lazy_ugettext("user pre update") | |||
81 |
|
84 | |||
82 | def __init__(self, user, user_data): |
|
85 | def __init__(self, user, user_data): | |
83 | super().__init__() |
|
86 | super().__init__() | |
@@ -87,8 +90,8 b' class UserPreUpdate(RhodeCodeIntegration' | |||||
87 |
|
90 | |||
88 | class UserPermissionsChange(RhodecodeEvent): |
|
91 | class UserPermissionsChange(RhodecodeEvent): | |
89 | """ |
|
92 | """ | |
90 | This event should be triggered on an event that permissions of user might changed. |
|
93 | This event should be triggered on an event that permissions of user might be changed. | |
91 | Currently this should be triggered on: |
|
94 | Currently, this should be triggered on: | |
92 |
|
95 | |||
93 | - user added/removed from user group |
|
96 | - user added/removed from user group | |
94 | - repo permissions changed |
|
97 | - repo permissions changed | |
@@ -96,9 +99,11 b' class UserPermissionsChange(RhodecodeEve' | |||||
96 | - user group permissions changed |
|
99 | - user group permissions changed | |
97 |
|
100 | |||
98 | """ |
|
101 | """ | |
99 | name = 'user-permissions-change' |
|
102 | ||
100 |
|
|
103 | name = "user-permissions-change" | |
|
104 | display_name = lazy_ugettext("user permissions change") | |||
101 |
|
105 | |||
102 | def __init__(self, user_ids): |
|
106 | def __init__(self, user_ids, context=None): | |
103 | super().__init__() |
|
107 | super().__init__(context=context) | |
104 | self.user_ids = user_ids |
|
108 | self.user_ids = user_ids | |
|
109 | self.context = self._context |
General Comments 0
You need to be logged in to leave comments.
Login now