annotate rhodecode/model/comment.py @ 2541:1c2ba03c42b4 beta

Added dynamic data loading for other repo we open pull request against - fixed notification emails, now with link to comment or status change in given pull request
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 03 Jul 2012 03:07:15 +0200
parents 17893d61792a
children f3e039e4dc49
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 """
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 rhodecode.model.comment
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 comments model for RhodeCode
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
7
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 :created_on: Nov 11, 2011
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 :author: marcink
1824
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1789
diff changeset
10 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com>
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 :license: GPLv3, see COPYING for more details.
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 """
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # This program is free software: you can redistribute it and/or modify
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # it under the terms of the GNU General Public License as published by
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # (at your option) any later version.
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 #
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 #
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import logging
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 import traceback
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
29 from pylons.i18n.translation import _
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
30 from sqlalchemy.util.compat import defaultdict
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
31
2178
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
32 from rhodecode.lib.utils2 import extract_mentioned_users, safe_unicode
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
33 from rhodecode.lib import helpers as h
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 from rhodecode.model import BaseModel
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
35 from rhodecode.model.db import ChangesetComment, User, Repository, \
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
36 Notification, PullRequest
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1681
diff changeset
37 from rhodecode.model.notification import NotificationModel
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 log = logging.getLogger(__name__)
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 class ChangesetCommentsModel(BaseModel):
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43
2522
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
44 cls = ChangesetComment
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
45
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
46 def __get_changeset_comment(self, changeset_comment):
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
47 return self._get_instance(ChangesetComment, changeset_comment)
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
49 def __get_pull_request(self, pull_request):
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
50 return self._get_instance(PullRequest, pull_request)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
51
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
52 def _extract_mentions(self, s):
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
53 user_objects = []
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
54 for username in extract_mentioned_users(s):
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
55 user_obj = User.get_by_username(username, case_insensitive=True)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
56 if user_obj:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
57 user_objects.append(user_obj)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
58 return user_objects
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
59
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
60 def create(self, text, repo, user, revision=None, pull_request=None,
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
61 f_path=None, line_no=None, status_change=None):
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 """
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
63 Creates new comment for changeset or pull request.
2478
8eab81115660 white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
64 IF status_change is not none this comment is associated with a
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
65 status change of changeset or changesets associated with pull request
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
66
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 :param text:
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
68 :param repo:
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
69 :param user:
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
70 :param revision:
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
71 :param pull_request:
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 :param f_path:
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 :param line_no:
2296
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2187
diff changeset
74 :param status_change:
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 """
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
76 if not text:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
77 return
2150
a8c9c0094ddf White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
78
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
79 repo = self._get_repo(repo)
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
80 user = self._get_user(user)
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
81 comment = ChangesetComment()
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
82 comment.repo = repo
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
83 comment.author = user
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
84 comment.text = text
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
85 comment.f_path = f_path
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
86 comment.line_no = line_no
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
87
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
88 if revision:
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
89 cs = repo.scm_instance.get_changeset(revision)
2178
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
90 desc = "%s - %s" % (cs.short_id, h.shorter(cs.message, 256))
2082
0e27da019f84 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2077
diff changeset
91 author_email = cs.author_email
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
92 comment.revision = revision
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
93 elif pull_request:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
94 pull_request = self.__get_pull_request(pull_request)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
95 comment.pull_request = pull_request
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
96 desc = pull_request.pull_request_id
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
97 else:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
98 raise Exception('Please specify revision or pull_request_id')
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
100 self.sa.add(comment)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
101 self.sa.flush()
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
102
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
103 # make notification
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
104 line = ''
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
105 body = text
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
106
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
107 #changeset
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
108 if revision:
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
109 if line_no:
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
110 line = _('on line %s') % line_no
2178
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
111 subj = safe_unicode(
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
112 h.link_to('Re commit: %(desc)s %(line)s' % \
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
113 {'desc': desc, 'line': line},
2178
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
114 h.url('changeset_home', repo_name=repo.repo_name,
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
115 revision=revision,
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
116 anchor='comment-%s' % comment.comment_id,
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
117 qualified=True,
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
118 )
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
119 )
989c137f26eb Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2150
diff changeset
120 )
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
121 notification_type = Notification.TYPE_CHANGESET_COMMENT
2077
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
122 # get the current participants of this changeset
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1681
diff changeset
123 recipients = ChangesetComment.get_users(revision=revision)
2082
0e27da019f84 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2077
diff changeset
124 # add changeset author if it's in rhodecode system
0e27da019f84 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2077
diff changeset
125 recipients += [User.get_by_email(author_email)]
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
126 #pull request
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
127 elif pull_request:
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
128 subj = safe_unicode(
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
129 h.link_to('Re pull request: %(desc)s %(line)s' % \
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
130 {'desc': desc, 'line': line},
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
131 h.url('pullrequest_show',
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
132 repo_name=pull_request.other_repo.repo_name,
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
133 pull_request_id=pull_request.pull_request_id,
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
134 anchor='comment-%s' % comment.comment_id,
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
135 qualified=True,
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
136 )
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
137 )
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
138 )
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
139
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
140 notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
141 # get the current participants of this pull request
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
142 recipients = ChangesetComment.get_users(pull_request_id=
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
143 pull_request.pull_request_id)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
144 # add pull request author
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
145 recipients += [pull_request.author]
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
146
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
147 # create notification objects, and emails
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
148 NotificationModel().create(
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
149 created_by=user, subject=subj, body=body,
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
150 recipients=recipients, type_=notification_type,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
151 email_kwargs={'status_change': status_change}
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
152 )
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
153
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
154 mention_recipients = set(self._extract_mentions(body))\
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
155 .difference(recipients)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
156 if mention_recipients:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
157 subj = _('[Mention]') + ' ' + subj
2077
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
158 NotificationModel().create(
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
159 created_by=user, subject=subj, body=body,
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
160 recipients=mention_recipients,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
161 type_=notification_type,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
162 email_kwargs={'status_change': status_change}
2077
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
163 )
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1681
diff changeset
164
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
165 return comment
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
167 def delete(self, comment):
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 """
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 Deletes given comment
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
170
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171 :param comment_id:
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172 """
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
173 comment = self.__get_changeset_comment(comment)
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 self.sa.delete(comment)
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
175
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176 return comment
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
177
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
178 def get_comments(self, repo_id, revision=None, pull_request=None):
2439
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
179 """
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
180 Get's main comments based on revision or pull_request_id
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
181
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
182 :param repo_id:
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
183 :type repo_id:
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
184 :param revision:
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
185 :type revision:
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
186 :param pull_request:
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
187 :type pull_request:
2439
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
188 """
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
189
2439
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
190 q = ChangesetComment.query()\
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
191 .filter(ChangesetComment.repo_id == repo_id)\
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
192 .filter(ChangesetComment.line_no == None)\
2439
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
193 .filter(ChangesetComment.f_path == None)
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
194 if revision:
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
195 q = q.filter(ChangesetComment.revision == revision)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
196 elif pull_request:
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
197 pull_request = self.__get_pull_request(pull_request)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
198 q = q.filter(ChangesetComment.pull_request == pull_request)
2439
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
199 else:
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
200 raise Exception('Please specify revision or pull_request')
2439
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
201 return q.all()
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
202
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
203 def get_inline_comments(self, repo_id, revision=None, pull_request=None):
2439
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
204 q = self.sa.query(ChangesetComment)\
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
205 .filter(ChangesetComment.repo_id == repo_id)\
1681
1bf03daafaf0 fixes inline comments double entries
Marcin Kuzminski <marcin@python-works.com>
parents: 1677
diff changeset
206 .filter(ChangesetComment.line_no != None)\
2187
b61e540122f2 #415: Adding comment to changeset causes reload
Marcin Kuzminski <marcin@python-works.com>
parents: 2178
diff changeset
207 .filter(ChangesetComment.f_path != None)\
b61e540122f2 #415: Adding comment to changeset causes reload
Marcin Kuzminski <marcin@python-works.com>
parents: 2178
diff changeset
208 .order_by(ChangesetComment.comment_id.asc())\
2439
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
209
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
210 if revision:
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
211 q = q.filter(ChangesetComment.revision == revision)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
212 elif pull_request:
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
213 pull_request = self.__get_pull_request(pull_request)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
214 q = q.filter(ChangesetComment.pull_request == pull_request)
2439
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
215 else:
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
216 raise Exception('Please specify revision or pull_request_id')
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
217
ad19dfcdb1cc Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
218 comments = q.all()
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
219
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
220 paths = defaultdict(lambda: defaultdict(list))
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
221
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
222 for co in comments:
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
223 paths[co.f_path][co.line_no].append(co)
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
224 return paths.items()