Show More
@@ -0,0 +1,72 b'' | |||
|
1 | # Copyright (C) 2016-2016 RhodeCode GmbH | |
|
2 | # | |
|
3 | # This program is free software: you can redistribute it and/or modify | |
|
4 | # it under the terms of the GNU Affero General Public License, version 3 | |
|
5 | # (only), as published by the Free Software Foundation. | |
|
6 | # | |
|
7 | # This program is distributed in the hope that it will be useful, | |
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
10 | # GNU General Public License for more details. | |
|
11 | # | |
|
12 | # You should have received a copy of the GNU Affero General Public License | |
|
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
|
14 | # | |
|
15 | # This program is dual-licensed. If you wish to learn more about the | |
|
16 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
|
18 | ||
|
19 | from rhodecode.events.repo import RepoEvent | |
|
20 | ||
|
21 | ||
|
22 | class PullRequestEvent(RepoEvent): | |
|
23 | """ | |
|
24 | Base class for events acting on a repository. | |
|
25 | ||
|
26 | :param repo: a :class:`Repository` instance | |
|
27 | """ | |
|
28 | def __init__(self, pullrequest): | |
|
29 | super(PullRequestEvent, self).__init__(pullrequest.target_repo) | |
|
30 | self.pullrequest = pullrequest | |
|
31 | ||
|
32 | ||
|
33 | class PullRequestCreateEvent(PullRequestEvent): | |
|
34 | """ | |
|
35 | An instance of this class is emitted as an :term:`event` after a pull | |
|
36 | request is created. | |
|
37 | """ | |
|
38 | name = 'pullrequest-create' | |
|
39 | ||
|
40 | ||
|
41 | class PullRequestCloseEvent(PullRequestEvent): | |
|
42 | """ | |
|
43 | An instance of this class is emitted as an :term:`event` after a pull | |
|
44 | request is closed. | |
|
45 | """ | |
|
46 | name = 'pullrequest-close' | |
|
47 | ||
|
48 | ||
|
49 | class PullRequestUpdateEvent(PullRequestEvent): | |
|
50 | """ | |
|
51 | An instance of this class is emitted as an :term:`event` after a pull | |
|
52 | request is updated. | |
|
53 | """ | |
|
54 | name = 'pullrequest-update' | |
|
55 | ||
|
56 | ||
|
57 | class PullRequestMergeEvent(PullRequestEvent): | |
|
58 | """ | |
|
59 | An instance of this class is emitted as an :term:`event` after a pull | |
|
60 | request is merged. | |
|
61 | """ | |
|
62 | name = 'pullrequest-merge' | |
|
63 | ||
|
64 | ||
|
65 | class PullRequestReviewEvent(PullRequestEvent): | |
|
66 | """ | |
|
67 | An instance of this class is emitted as an :term:`event` after a pull | |
|
68 | request is reviewed. | |
|
69 | """ | |
|
70 | name = 'pullrequest-review' | |
|
71 | ||
|
72 |
@@ -0,0 +1,61 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | ||
|
3 | # Copyright (C) 2010-2016 RhodeCode GmbH | |
|
4 | # | |
|
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 | |
|
7 | # (only), as published by the Free Software Foundation. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
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/>. | |
|
16 | # | |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
|
20 | ||
|
21 | import pytest | |
|
22 | ||
|
23 | from rhodecode.tests.events.conftest import EventCatcher | |
|
24 | ||
|
25 | from rhodecode.model.pull_request import PullRequestModel | |
|
26 | from rhodecode.events import ( | |
|
27 | PullRequestCreateEvent, | |
|
28 | PullRequestUpdateEvent, | |
|
29 | PullRequestReviewEvent, | |
|
30 | PullRequestMergeEvent, | |
|
31 | PullRequestCloseEvent, | |
|
32 | ) | |
|
33 | ||
|
34 | ||
|
35 | @pytest.mark.backends("git", "hg") | |
|
36 | def test_create_pull_request_events(pr_util): | |
|
37 | with EventCatcher() as event_catcher: | |
|
38 | pr_util.create_pull_request() | |
|
39 | ||
|
40 | assert PullRequestCreateEvent in event_catcher.events_types | |
|
41 | ||
|
42 | ||
|
43 | @pytest.mark.backends("git", "hg") | |
|
44 | def test_close_pull_request_events(pr_util, user_admin): | |
|
45 | pr = pr_util.create_pull_request() | |
|
46 | ||
|
47 | with EventCatcher() as event_catcher: | |
|
48 | PullRequestModel().close_pull_request(pr, user_admin) | |
|
49 | ||
|
50 | assert PullRequestCloseEvent in event_catcher.events_types | |
|
51 | ||
|
52 | ||
|
53 | @pytest.mark.backends("git", "hg") | |
|
54 | def test_close_pull_request_with_comment_events(pr_util, user_admin): | |
|
55 | pr = pr_util.create_pull_request() | |
|
56 | ||
|
57 | with EventCatcher() as event_catcher: | |
|
58 | PullRequestModel().close_pull_request_with_comment( | |
|
59 | pr, user_admin, pr.target_repo) | |
|
60 | ||
|
61 | assert PullRequestCloseEvent in event_catcher.events_types |
@@ -49,3 +49,11 b' from rhodecode.events.repo import (' | |||
|
49 | 49 | RepoPrePushEvent, RepoPushEvent, |
|
50 | 50 | RepoPrePullEvent, RepoPullEvent, |
|
51 | 51 | ) |
|
52 | ||
|
53 | from rhodecode.events.pullrequest import ( | |
|
54 | PullRequestCreateEvent, | |
|
55 | PullRequestUpdateEvent, | |
|
56 | PullRequestReviewEvent, | |
|
57 | PullRequestMergeEvent, | |
|
58 | PullRequestCloseEvent, | |
|
59 | ) No newline at end of file |
@@ -21,6 +21,7 b'' | |||
|
21 | 21 | import pylons |
|
22 | 22 | import webob |
|
23 | 23 | |
|
24 | from rhodecode import events | |
|
24 | 25 | from rhodecode.lib import hooks_base |
|
25 | 26 | from rhodecode.lib import utils2 |
|
26 | 27 | |
@@ -76,6 +77,7 b' def trigger_log_create_pull_request_hook' | |||
|
76 | 77 | |
|
77 | 78 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
78 | 79 | 'create_pull_request') |
|
80 | events.trigger(events.PullRequestCreateEvent(pull_request)) | |
|
79 | 81 | extras.update(pull_request.get_api_data()) |
|
80 | 82 | hooks_base.log_create_pull_request(**extras) |
|
81 | 83 | |
@@ -95,6 +97,7 b' def trigger_log_merge_pull_request_hook(' | |||
|
95 | 97 | |
|
96 | 98 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
97 | 99 | 'merge_pull_request') |
|
100 | events.trigger(events.PullRequestMergeEvent(pull_request)) | |
|
98 | 101 | extras.update(pull_request.get_api_data()) |
|
99 | 102 | hooks_base.log_merge_pull_request(**extras) |
|
100 | 103 | |
@@ -114,6 +117,7 b' def trigger_log_close_pull_request_hook(' | |||
|
114 | 117 | |
|
115 | 118 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
116 | 119 | 'close_pull_request') |
|
120 | events.trigger(events.PullRequestCloseEvent(pull_request)) | |
|
117 | 121 | extras.update(pull_request.get_api_data()) |
|
118 | 122 | hooks_base.log_close_pull_request(**extras) |
|
119 | 123 | |
@@ -133,6 +137,7 b' def trigger_log_review_pull_request_hook' | |||
|
133 | 137 | |
|
134 | 138 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
135 | 139 | 'review_pull_request') |
|
140 | events.trigger(events.PullRequestReviewEvent(pull_request)) | |
|
136 | 141 | extras.update(pull_request.get_api_data()) |
|
137 | 142 | hooks_base.log_review_pull_request(**extras) |
|
138 | 143 | |
@@ -152,5 +157,6 b' def trigger_log_update_pull_request_hook' | |||
|
152 | 157 | |
|
153 | 158 | extras = _get_rc_scm_extras(username, repo_name, repo_alias, |
|
154 | 159 | 'update_pull_request') |
|
160 | events.trigger(events.PullRequestUpdateEvent(pull_request)) | |
|
155 | 161 | extras.update(pull_request.get_api_data()) |
|
156 | 162 | hooks_base.log_update_pull_request(**extras) |
General Comments 0
You need to be logged in to leave comments.
Login now