annotate kallithea/model/comment.py @ 4384:0529498575ce

notifications: insert 'References' mail headers to help MUA threading gmail is however fubar.
author Mads Kiilerich <madski@unity3d.com>
date Fri, 18 Jul 2014 19:22:01 +0200
parents 55f2f2b4c462
children 231442b0b6aa
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 # 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
3 # 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
4 # the Free Software Foundation, either version 3 of the License, or
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 # (at your option) any later version.
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 #
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 # 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
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 # GNU General Public License for more details.
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 #
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 # 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
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
14 """
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
15 kallithea.model.comment
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
17
4212
24c0d584ba86 General renaming to Kallithea
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4211
diff changeset
18 comments model for Kallithea
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
19
4211
1948ede028ef RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4208
diff changeset
20 This file was forked by the Kallithea project in July 2014.
1948ede028ef RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4208
diff changeset
21 Original author and date, and relevant copyright and licensing information is below:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
22 :created_on: Nov 11, 2011
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
23 :author: marcink
4211
1948ede028ef RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4208
diff changeset
24 :copyright: (c) 2013 RhodeCode GmbH, and others.
4208
ad38f9f93b3b Correct licensing information in individual files.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
25 :license: GPLv3, see LICENSE.md for more details.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
26 """
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 import logging
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 import traceback
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
31 from pylons.i18n.translation import _
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
32 from sqlalchemy.util.compat import defaultdict
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
33
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
34 from kallithea.lib.utils2 import extract_mentioned_users, safe_unicode
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
35 from kallithea.lib import helpers as h
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
36 from kallithea.model import BaseModel
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
37 from kallithea.model.db import ChangesetComment, User, Repository, \
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
38 Notification, PullRequest
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
39 from kallithea.model.notification import NotificationModel
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
40 from kallithea.model.meta import Session
1670
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 log = logging.getLogger(__name__)
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 class ChangesetCommentsModel(BaseModel):
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
2522
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
47 cls = ChangesetComment
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
48
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
49 def __get_changeset_comment(self, changeset_comment):
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
50 return self._get_instance(ChangesetComment, changeset_comment)
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
52 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
53 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
54
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
55 def _extract_mentions(self, s):
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
56 user_objects = []
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
57 for username in extract_mentioned_users(s):
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
58 user_obj = User.get_by_username(username, case_insensitive=True)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
59 if user_obj:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
60 user_objects.append(user_obj)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
61 return user_objects
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
62
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
63 def _get_notification_data(self, repo, comment, user, comment_text,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
64 line_no=None, revision=None, pull_request=None,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
65 status_change=None, closing_pr=False):
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
66 """
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
67 Get notification data
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
68
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
69 :param comment_text:
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
70 :param line:
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
71 :returns: tuple (subj,body,recipients,notification_type,email_kwargs)
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
72 """
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
73 # make notification
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
74 body = comment_text # text of the comment
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
75 line = ''
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
76 if line_no:
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
77 line = _('on line %s') % line_no
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
78
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
79 #changeset
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
80 if revision:
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
81 notification_type = Notification.TYPE_CHANGESET_COMMENT
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
82 cs = repo.scm_instance.get_changeset(revision)
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
83 desc = "%s" % (cs.short_id)
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
84
4384
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
85 revision_url = h.url('changeset_home',
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
86 repo_name=repo.repo_name,
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
87 revision=revision,
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
88 qualified=True,)
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
89 comment_url = h.url('changeset_home',
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
90 repo_name=repo.repo_name,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
91 revision=revision,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
92 anchor='comment-%s' % comment.comment_id,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
93 qualified=True,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
94 )
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
95 subj = safe_unicode(
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
96 h.link_to('Re changeset: %(desc)s %(line)s' % \
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
97 {'desc': desc, 'line': line},
4384
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
98 comment_url)
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
99 )
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
100 # get the current participants of this changeset
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
101 recipients = ChangesetComment.get_users(revision=revision)
4212
24c0d584ba86 General renaming to Kallithea
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4211
diff changeset
102 # add changeset author if it's in kallithea system
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
103 cs_author = User.get_from_cs_author(cs.author)
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
104 if not cs_author:
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
105 #use repo owner if we cannot extract the author correctly
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
106 cs_author = repo.user
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
107 recipients += [cs_author]
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
108 email_kwargs = {
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
109 'status_change': status_change,
4380
5ebd887522ea helpers: user email can be unset
Andrew Shadura <andrew@shadura.me>
parents: 4360
diff changeset
110 'cs_comment_user': h.person(user),
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
111 'cs_target_repo': h.url('summary_home', repo_name=repo.repo_name,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
112 qualified=True),
4384
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
113 'cs_comment_url': comment_url,
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
114 'raw_id': revision,
4381
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
115 'message': cs.message,
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
116 'repo_name': repo.repo_name,
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
117 'short_id': h.short_id(revision),
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
118 'branch': cs.branch,
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
119 'comment_username': user.username,
4384
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
120 'threading': [revision_url, comment_url], # TODO: url to line number
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
121 }
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
122 #pull request
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
123 elif pull_request:
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
124 notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
125 desc = comment.pull_request.title
4381
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
126 _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':')
4384
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
127 pr_url = h.url('pullrequest_show',
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
128 repo_name=pull_request.other_repo.repo_name,
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
129 pull_request_id=pull_request.pull_request_id,
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
130 qualified=True,)
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
131 comment_url = h.url('pullrequest_show',
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
132 repo_name=pull_request.other_repo.repo_name,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
133 pull_request_id=pull_request.pull_request_id,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
134 anchor='comment-%s' % comment.comment_id,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
135 qualified=True,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
136 )
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
137 subj = safe_unicode(
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
138 h.link_to('Re pull request #%(pr_id)s: %(desc)s %(line)s' % \
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
139 {'desc': desc,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
140 'pr_id': comment.pull_request.pull_request_id,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
141 'line': line},
4384
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
142 comment_url)
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
143 )
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
144 # get the current participants of this pull request
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
145 recipients = ChangesetComment.get_users(pull_request_id=
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
146 pull_request.pull_request_id)
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
147 # add pull request author
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
148 recipients += [pull_request.author]
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
149
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
150 # add the reviewers to notification
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
151 recipients += [x.user for x in pull_request.reviewers]
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
152
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
153 #set some variables for email notification
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
154 email_kwargs = {
3780
1de8abd9a4e1 emails: try to improve wording and layout - 1st iteration
Mads Kiilerich <madski@unity3d.com>
parents: 3430
diff changeset
155 'pr_title': pull_request.title,
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
156 'pr_id': pull_request.pull_request_id,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
157 'status_change': status_change,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
158 'closing_pr': closing_pr,
4384
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
159 'pr_comment_url': comment_url,
4380
5ebd887522ea helpers: user email can be unset
Andrew Shadura <andrew@shadura.me>
parents: 4360
diff changeset
160 'pr_comment_user': h.person(user),
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
161 'pr_target_repo': h.url('summary_home',
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
162 repo_name=pull_request.other_repo.repo_name,
4381
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
163 qualified=True),
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
164 'repo_name': pull_request.other_repo.repo_name,
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
165 'ref': org_ref_name,
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
166 'comment_username': user.username,
4384
0529498575ce notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents: 4381
diff changeset
167 'threading': [pr_url, comment_url], # TODO: url to line number
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
168 }
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
169
4381
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
170 return subj, body, recipients, notification_type, email_kwargs
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
171
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
172 def create(self, text, repo, user, revision=None, pull_request=None,
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
173 f_path=None, line_no=None, status_change=None, closing_pr=False,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
174 send_email=True):
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175 """
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
176 Creates new comment for changeset or pull request.
4360
05af189da2ae pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents: 4212
diff changeset
177 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
178 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
179
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180 :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
181 :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
182 :param user:
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
183 :param revision:
4360
05af189da2ae pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents: 4212
diff changeset
184 :param pull_request: (for emails, not for comments)
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185 :param f_path:
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186 :param line_no:
4360
05af189da2ae pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents: 4212
diff changeset
187 :param status_change: (for emails, not for comments)
05af189da2ae pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents: 4212
diff changeset
188 :param closing_pr: (for emails, not for comments)
05af189da2ae pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents: 4212
diff changeset
189 :param send_email: also send email
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 """
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
191 if not text:
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
192 log.warning('Missing text for comment, skipping...')
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
193 return
2150
a8c9c0094ddf White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
194
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
195 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
196 user = self._get_user(user)
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
197 comment = ChangesetComment()
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
198 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
199 comment.author = user
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
200 comment.text = text
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
201 comment.f_path = f_path
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
202 comment.line_no = line_no
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
203
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
204 if revision:
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
205 comment.revision = revision
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
206 elif pull_request:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
207 pull_request = self.__get_pull_request(pull_request)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
208 comment.pull_request = pull_request
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
209 else:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
210 raise Exception('Please specify revision or pull_request_id')
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
212 Session().add(comment)
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
213 Session().flush()
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
214
3257
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
215 if send_email:
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
216 (subj, body, recipients, notification_type,
4381
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
217 email_kwargs) = self._get_notification_data(
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
218 repo, comment, user,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
219 comment_text=text,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
220 line_no=line_no,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
221 revision=revision,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
222 pull_request=pull_request,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
223 status_change=status_change,
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
224 closing_pr=closing_pr)
3257
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
225 # create notification objects, and emails
2077
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
226 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
227 created_by=user, subject=subj, body=body,
3257
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
228 recipients=recipients, type_=notification_type,
4381
55f2f2b4c462 notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents: 4380
diff changeset
229 email_kwargs=email_kwargs,
2077
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
230 )
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1681
diff changeset
231
3257
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
232 mention_recipients = set(self._extract_mentions(body))\
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
233 .difference(recipients)
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
234 if mention_recipients:
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
235 email_kwargs.update({'pr_mention': True})
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
236 subj = _('[Mention]') + ' ' + subj
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
237 NotificationModel().create(
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
238 created_by=user, subject=subj, body=body,
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
239 recipients=mention_recipients,
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
240 type_=notification_type,
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
241 email_kwargs=email_kwargs
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
242 )
32a283e5fd0d Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3250
diff changeset
243
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
244 return comment
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
245
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
246 def delete(self, comment):
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
247 """
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
248 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
249
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
250 :param comment_id:
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
251 """
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
252 comment = self.__get_changeset_comment(comment)
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
253 Session().delete(comment)
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
254
1670
d2de0c2f02cd #77 code review
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
255 return comment
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
256
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
257 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
258 """
4089
a5888ca796b5 Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents: 3780
diff changeset
259 Gets main comments based on revision or pull_request_id
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
260
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
261 :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
262 :param revision:
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
263 :param 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
264 """
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
265
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
266 q = ChangesetComment.query()\
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
267 .filter(ChangesetComment.repo_id == repo_id)\
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
268 .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
269 .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
270 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
271 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
272 elif pull_request:
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
273 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
274 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
275 else:
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
276 raise Exception('Please specify revision or pull_request')
2639
f3e039e4dc49 Added created_on column to changeset comments for proper ordering.
Marcin Kuzminski <marcin@python-works.com>
parents: 2541
diff changeset
277 q = q.order_by(ChangesetComment.created_on)
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
278 return q.all()
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
279
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
280 def get_inline_comments(self, repo_id, revision=None, pull_request=None):
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
281 q = Session().query(ChangesetComment)\
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
282 .filter(ChangesetComment.repo_id == repo_id)\
1681
1bf03daafaf0 fixes inline comments double entries
Marcin Kuzminski <marcin@python-works.com>
parents: 1677
diff changeset
283 .filter(ChangesetComment.line_no != None)\
2187
b61e540122f2 #415: Adding comment to changeset causes reload
Marcin Kuzminski <marcin@python-works.com>
parents: 2178
diff changeset
284 .filter(ChangesetComment.f_path != None)\
b61e540122f2 #415: Adding comment to changeset causes reload
Marcin Kuzminski <marcin@python-works.com>
parents: 2178
diff changeset
285 .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
286
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
287 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
288 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
289 elif pull_request:
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2439
diff changeset
290 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
291 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
292 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
293 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
294
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
295 comments = q.all()
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
296
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
297 paths = defaultdict(lambda: defaultdict(list))
1675
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
298
7c487d2678c7 code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1670
diff changeset
299 for co in comments:
1677
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
300 paths[co.f_path][co.line_no].append(co)
7276b170ce8b #71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 1675
diff changeset
301 return paths.items()