Mercurial > kallithea
annotate kallithea/model/comment.py @ 8757:4cca6590f263
model/comment: drop unused fields in email_kwargs
Keep things as simple as possible.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Thu, 05 Nov 2020 23:04:52 +0100 |
parents | b4749d02192d |
children | 3cef2caf44f3 |
rev | line source |
---|---|
1670 | 1 # -*- coding: utf-8 -*- |
2 # This program is free software: you can redistribute it and/or modify | |
3 # it under the terms of the GNU General Public License as published by | |
4 # the Free Software Foundation, either version 3 of the License, or | |
5 # (at your option) any later version. | |
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 General Public License | |
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 | 27 |
28 import logging | |
5054
74b5e0318d4e
compat: import defaultdict from collections, sqlalchemy 0.8.0 dropped the shim
Andrew Shadura <andrew@shadura.me>
parents:
4791
diff
changeset
|
29 from collections import defaultdict |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1703
diff
changeset
|
30 |
8720
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
31 from kallithea.lib import webutils |
8677
a765b2961eda
lib: move extract_mentioned_users out of utils2
Mads Kiilerich <mads@kiilerich.com>
parents:
8561
diff
changeset
|
32 from kallithea.lib.utils import extract_mentioned_users |
8722
5dfb757197c9
lib: move shorter to utils2 - less use of helpers in model
Mads Kiilerich <mads@kiilerich.com>
parents:
8721
diff
changeset
|
33 from kallithea.lib.utils2 import shorter |
8727
c98c7d4c9ec3
model: changes toward import whole modules
Mads Kiilerich <mads@kiilerich.com>
parents:
8722
diff
changeset
|
34 from kallithea.model import db, meta, notification |
7811
0a277465fddf
scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents:
7489
diff
changeset
|
35 |
1670 | 36 |
37 log = logging.getLogger(__name__) | |
38 | |
39 | |
6496
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
40 def _list_changeset_commenters(revision): |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
41 return (meta.Session().query(db.User) |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
42 .join(db.ChangesetComment.author) |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
43 .filter(db.ChangesetComment.revision == revision) |
6496
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
44 .all()) |
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
45 |
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
46 def _list_pull_request_commenters(pull_request): |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
47 return (meta.Session().query(db.User) |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
48 .join(db.ChangesetComment.author) |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
49 .filter(db.ChangesetComment.pull_request_id == pull_request.pull_request_id) |
6496
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
50 .all()) |
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
51 |
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
52 |
6523
3760df6251e0
model: remove BaseModel class
Søren Løvborg <sorenl@unity3d.com>
parents:
6496
diff
changeset
|
53 class ChangesetCommentsModel(object): |
1670 | 54 |
8754
78059b94991e
model/comment: inline _get_notification_data
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8753
diff
changeset
|
55 def create_notification(self, repo, comment, author, comment_text, |
78059b94991e
model/comment: inline _get_notification_data
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8753
diff
changeset
|
56 line_no=None, revision=None, pull_request=None, |
78059b94991e
model/comment: inline _get_notification_data
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8753
diff
changeset
|
57 status_change=None, closing_pr=False): |
78059b94991e
model/comment: inline _get_notification_data
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8753
diff
changeset
|
58 |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6553
diff
changeset
|
59 # changeset |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
60 if revision: |
8727
c98c7d4c9ec3
model: changes toward import whole modules
Mads Kiilerich <mads@kiilerich.com>
parents:
8722
diff
changeset
|
61 notification_type = notification.NotificationModel.TYPE_CHANGESET_COMMENT |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
62 cs = repo.scm_instance.get_changeset(revision) |
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
63 |
8720
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
64 threading = ['%s-rev-%s@%s' % (repo.repo_name, revision, webutils.canonical_hostname())] |
4446
5e7c69707f08
notifications: fix threading - use line number
Mads Kiilerich <madski@unity3d.com>
parents:
4445
diff
changeset
|
65 if line_no: # TODO: url to file _and_ line number |
5e7c69707f08
notifications: fix threading - use line number
Mads Kiilerich <madski@unity3d.com>
parents:
4445
diff
changeset
|
66 threading.append('%s-rev-%s-line-%s@%s' % (repo.repo_name, revision, line_no, |
8720
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
67 webutils.canonical_hostname())) |
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
68 comment_url = webutils.canonical_url('changeset_home', |
4384
0529498575ce
notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents:
4381
diff
changeset
|
69 repo_name=repo.repo_name, |
0529498575ce
notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents:
4381
diff
changeset
|
70 revision=revision, |
4445
f9bc28c44f30
urls: introduce canonical_url config setting
Mads Kiilerich <madski@unity3d.com>
parents:
4422
diff
changeset
|
71 anchor='comment-%s' % comment.comment_id) |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
72 # get the current participants of this changeset |
6496
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
73 recipients = _list_changeset_commenters(revision) |
5438
68011c4e6f33
pull requests: call it 'owner' instead of 'author'
Mads Kiilerich <madski@unity3d.com>
parents:
5306
diff
changeset
|
74 # add changeset author if it's known locally |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
75 cs_author = db.User.get_from_cs_author(cs.author) |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
76 if not cs_author: |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6553
diff
changeset
|
77 # use repo owner if we cannot extract the author correctly |
6056
3a221939a19f
notifications: make more template strings available for mails
Mads Kiilerich <madski@unity3d.com>
parents:
5877
diff
changeset
|
78 # FIXME: just use committer name even if not a user |
6230
cd6176c0634a
db: PullRequest/Repository/RepoGroup/UserGroup: change 'user' to 'owner'
Søren Løvborg <sorenl@unity3d.com>
parents:
6135
diff
changeset
|
79 cs_author = repo.owner |
6496
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
80 recipients.append(cs_author) |
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
81 |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
82 email_kwargs = { |
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
83 'status_change': status_change, |
6231
d1ed15ef8714
model: change ChangesetComment 'user' to 'author'
Søren Løvborg <sorenl@unity3d.com>
parents:
6230
diff
changeset
|
84 'cs_comment_user': author.full_name_and_username, |
8720
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
85 'cs_target_repo': webutils.canonical_url('summary_home', repo_name=repo.repo_name), |
4384
0529498575ce
notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents:
4381
diff
changeset
|
86 'cs_comment_url': comment_url, |
8720
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
87 'cs_url': webutils.canonical_url('changeset_home', repo_name=repo.repo_name, revision=revision), |
4381
55f2f2b4c462
notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents:
4380
diff
changeset
|
88 'message': cs.message, |
8722
5dfb757197c9
lib: move shorter to utils2 - less use of helpers in model
Mads Kiilerich <mads@kiilerich.com>
parents:
8721
diff
changeset
|
89 'message_short': shorter(cs.message, 50, firstline=True), |
6056
3a221939a19f
notifications: make more template strings available for mails
Mads Kiilerich <madski@unity3d.com>
parents:
5877
diff
changeset
|
90 'cs_author': cs_author, |
8561
5fe492c6d7d7
comments: add changeset author in mail notification subject
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8195
diff
changeset
|
91 'cs_author_username': cs_author.username, |
4381
55f2f2b4c462
notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents:
4380
diff
changeset
|
92 'repo_name': repo.repo_name, |
8717
b551f9c441dc
lib: minimize use of h.short_id() - it is already more common to use [:12]
Mads Kiilerich <mads@kiilerich.com>
parents:
8687
diff
changeset
|
93 'short_id': revision[:12], |
4381
55f2f2b4c462
notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents:
4380
diff
changeset
|
94 'branch': cs.branch, |
4446
5e7c69707f08
notifications: fix threading - use line number
Mads Kiilerich <madski@unity3d.com>
parents:
4445
diff
changeset
|
95 'threading': threading, |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
96 } |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6553
diff
changeset
|
97 # pull request |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
98 elif pull_request: |
8727
c98c7d4c9ec3
model: changes toward import whole modules
Mads Kiilerich <mads@kiilerich.com>
parents:
8722
diff
changeset
|
99 notification_type = notification.NotificationModel.TYPE_PULL_REQUEST_COMMENT |
4381
55f2f2b4c462
notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents:
4380
diff
changeset
|
100 _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':') |
6056
3a221939a19f
notifications: make more template strings available for mails
Mads Kiilerich <madski@unity3d.com>
parents:
5877
diff
changeset
|
101 _other_ref_type, other_ref_name, _other_rev = comment.pull_request.other_ref.split(':') |
4446
5e7c69707f08
notifications: fix threading - use line number
Mads Kiilerich <madski@unity3d.com>
parents:
4445
diff
changeset
|
102 threading = ['%s-pr-%s@%s' % (pull_request.other_repo.repo_name, |
5e7c69707f08
notifications: fix threading - use line number
Mads Kiilerich <madski@unity3d.com>
parents:
4445
diff
changeset
|
103 pull_request.pull_request_id, |
8720
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
104 webutils.canonical_hostname())] |
4446
5e7c69707f08
notifications: fix threading - use line number
Mads Kiilerich <madski@unity3d.com>
parents:
4445
diff
changeset
|
105 if line_no: # TODO: url to file _and_ line number |
5e7c69707f08
notifications: fix threading - use line number
Mads Kiilerich <madski@unity3d.com>
parents:
4445
diff
changeset
|
106 threading.append('%s-pr-%s-line-%s@%s' % (pull_request.other_repo.repo_name, |
5e7c69707f08
notifications: fix threading - use line number
Mads Kiilerich <madski@unity3d.com>
parents:
4445
diff
changeset
|
107 pull_request.pull_request_id, line_no, |
8720
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
108 webutils.canonical_hostname())) |
4447
e30401bac6e1
pull requests: show more helpful URLs
Mads Kiilerich <madski@unity3d.com>
parents:
4446
diff
changeset
|
109 comment_url = pull_request.url(canonical=True, |
4445
f9bc28c44f30
urls: introduce canonical_url config setting
Mads Kiilerich <madski@unity3d.com>
parents:
4422
diff
changeset
|
110 anchor='comment-%s' % comment.comment_id) |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
111 # get the current participants of this pull request |
6496
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
112 recipients = _list_pull_request_commenters(pull_request) |
89eb2b2da3c5
model: refactor listing of commenters
Søren Løvborg <sorenl@unity3d.com>
parents:
6464
diff
changeset
|
113 recipients.append(pull_request.owner) |
5763
20a094053606
pullrequests: optimize iteration over reviewers - avoid fetching users one by one
Mads Kiilerich <madski@unity3d.com>
parents:
5598
diff
changeset
|
114 recipients += pull_request.get_reviewer_users() |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
115 |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6553
diff
changeset
|
116 # set some variables for email notification |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
117 email_kwargs = { |
3780
1de8abd9a4e1
emails: try to improve wording and layout - 1st iteration
Mads Kiilerich <madski@unity3d.com>
parents:
3430
diff
changeset
|
118 'pr_title': pull_request.title, |
8722
5dfb757197c9
lib: move shorter to utils2 - less use of helpers in model
Mads Kiilerich <mads@kiilerich.com>
parents:
8721
diff
changeset
|
119 'pr_title_short': shorter(pull_request.title, 50), |
5089
196c46444d98
pullrequests: add PullRequest.nice_id method
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5086
diff
changeset
|
120 'pr_nice_id': pull_request.nice_id(), |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
121 'status_change': status_change, |
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
122 'closing_pr': closing_pr, |
4384
0529498575ce
notifications: insert 'References' mail headers to help MUA threading
Mads Kiilerich <madski@unity3d.com>
parents:
4381
diff
changeset
|
123 'pr_comment_url': comment_url, |
6135
8b75085c2c02
mails: restructure notification mail content
Mads Kiilerich <madski@unity3d.com>
parents:
6119
diff
changeset
|
124 'pr_url': pull_request.url(canonical=True), |
6231
d1ed15ef8714
model: change ChangesetComment 'user' to 'author'
Søren Løvborg <sorenl@unity3d.com>
parents:
6230
diff
changeset
|
125 'pr_comment_user': author.full_name_and_username, |
8720
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
126 'pr_target_repo': webutils.canonical_url('summary_home', |
4445
f9bc28c44f30
urls: introduce canonical_url config setting
Mads Kiilerich <madski@unity3d.com>
parents:
4422
diff
changeset
|
127 repo_name=pull_request.other_repo.repo_name), |
6056
3a221939a19f
notifications: make more template strings available for mails
Mads Kiilerich <madski@unity3d.com>
parents:
5877
diff
changeset
|
128 'pr_target_branch': other_ref_name, |
8720
0c65a8f15e54
lib: move canonical_url & co to webutils
Mads Kiilerich <mads@kiilerich.com>
parents:
8717
diff
changeset
|
129 'pr_source_repo': webutils.canonical_url('summary_home', |
6056
3a221939a19f
notifications: make more template strings available for mails
Mads Kiilerich <madski@unity3d.com>
parents:
5877
diff
changeset
|
130 repo_name=pull_request.org_repo.repo_name), |
3a221939a19f
notifications: make more template strings available for mails
Mads Kiilerich <madski@unity3d.com>
parents:
5877
diff
changeset
|
131 'pr_source_branch': org_ref_name, |
3a221939a19f
notifications: make more template strings available for mails
Mads Kiilerich <madski@unity3d.com>
parents:
5877
diff
changeset
|
132 'pr_owner': pull_request.owner, |
6059
d4061c6cc0e2
notifications: tweak PR mail subject lines
Mads Kiilerich <madski@unity3d.com>
parents:
6058
diff
changeset
|
133 'pr_owner_username': pull_request.owner.username, |
4381
55f2f2b4c462
notifications: improve Email subjects
Mads Kiilerich <madski@unity3d.com>
parents:
4380
diff
changeset
|
134 'repo_name': pull_request.other_repo.repo_name, |
4446
5e7c69707f08
notifications: fix threading - use line number
Mads Kiilerich <madski@unity3d.com>
parents:
4445
diff
changeset
|
135 'threading': threading, |
3430
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 |
8753
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
138 email_kwargs['is_mention'] = False |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
139 # create notification objects, and emails |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
140 notification.NotificationModel().create( |
8756
b4749d02192d
model: remove unused 'subject' parameter of NotificationModel.create()
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8755
diff
changeset
|
141 created_by=author, body=comment_text, |
8753
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
142 recipients=recipients, type_=notification_type, |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
143 email_kwargs=email_kwargs, |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
144 ) |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
145 |
8755
d952e08eeb03
model/comment: get rid of unnecessary variable 'body' in create_notification
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8754
diff
changeset
|
146 mention_recipients = extract_mentioned_users(comment_text).difference(recipients) |
8753
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
147 if mention_recipients: |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
148 email_kwargs['is_mention'] = True |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
149 notification.NotificationModel().create( |
8756
b4749d02192d
model: remove unused 'subject' parameter of NotificationModel.create()
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8755
diff
changeset
|
150 created_by=author, body=comment_text, |
8753
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
151 recipients=mention_recipients, |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
152 type_=notification_type, |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
153 email_kwargs=email_kwargs |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
154 ) |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
155 |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
156 |
6231
d1ed15ef8714
model: change ChangesetComment 'user' to 'author'
Søren Løvborg <sorenl@unity3d.com>
parents:
6230
diff
changeset
|
157 def create(self, text, repo, author, revision=None, pull_request=None, |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
158 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
|
159 send_email=True): |
1670 | 160 """ |
5085
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
161 Creates a new comment for either a changeset or a pull request. |
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
162 status_change and closing_pr is only for the optional email. |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
163 |
5085
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
164 Returns the created comment. |
1670 | 165 """ |
5068
140f2811fc6f
comments: avoid storing 'No comments' text when changing status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5054
diff
changeset
|
166 if not status_change and not text: |
3430
bbe21df7ad48
notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3257
diff
changeset
|
167 log.warning('Missing text for comment, skipping...') |
5198
93e055489e68
pullrequsts: really create a comment when creating a PR and setting status to 'under review'
Mads Kiilerich <madski@unity3d.com>
parents:
5089
diff
changeset
|
168 return None |
2150
a8c9c0094ddf
White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
169 |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
170 repo = db.Repository.guess_instance(repo) |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
171 author = db.User.guess_instance(author) |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
172 comment = db.ChangesetComment() |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
173 comment.repo = repo |
6231
d1ed15ef8714
model: change ChangesetComment 'user' to 'author'
Søren Løvborg <sorenl@unity3d.com>
parents:
6230
diff
changeset
|
174 comment.author = author |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
175 comment.text = text |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
176 comment.f_path = f_path |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
177 comment.line_no = line_no |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
178 |
5306
63bed817308c
cleanup: check for None object identity in cases where that is what the 'contract' says
Mads Kiilerich <madski@unity3d.com>
parents:
5305
diff
changeset
|
179 if revision is not None: |
1677
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
180 comment.revision = revision |
5306
63bed817308c
cleanup: check for None object identity in cases where that is what the 'contract' says
Mads Kiilerich <madski@unity3d.com>
parents:
5305
diff
changeset
|
181 elif pull_request is not None: |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
182 pull_request = db.PullRequest.guess_instance(pull_request) |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
183 comment.pull_request = pull_request |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
184 else: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
185 raise Exception('Please specify revision or pull_request_id') |
1670 | 186 |
8686
b095e2fbba44
model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents:
8677
diff
changeset
|
187 meta.Session().add(comment) |
b095e2fbba44
model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents:
8677
diff
changeset
|
188 meta.Session().flush() |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
189 |
3257
32a283e5fd0d
Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3250
diff
changeset
|
190 if send_email: |
8753
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
191 self.create_notification( |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
192 repo, comment, author, text, line_no, revision, pull_request, |
cdcebb7c2900
model/comment: extract notification-related code into a separate method
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8727
diff
changeset
|
193 status_change, closing_pr |
2077 | 194 ) |
1703
f23828b00b21
notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1681
diff
changeset
|
195 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
196 return comment |
1670 | 197 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
198 def delete(self, comment): |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
199 comment = db.ChangesetComment.guess_instance(comment) |
8686
b095e2fbba44
model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents:
8677
diff
changeset
|
200 meta.Session().delete(comment) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
201 |
1670 | 202 return comment |
1675
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
203 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2439
diff
changeset
|
204 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
|
205 """ |
5085
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
206 Gets general comments for either 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
|
207 |
5085
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
208 Returns a list, ordered by creation date. |
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 """ |
5086
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
210 return self._get_comments(repo_id, revision=revision, pull_request=pull_request, |
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
211 inline=False) |
1675
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
212 |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
213 def get_inline_comments(self, repo_id, revision=None, pull_request=None, |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
214 f_path=None, line_no=None): |
5085
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
215 """ |
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
216 Gets inline comments for either revision or pull_request. |
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
217 |
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
218 Returns a list of tuples with file path and list of comments per line number. |
34f2da0a2969
ChangesetCommentsModel: cleanup of doc strings
Jan Heylen <heyleke@gmail.com>
parents:
5068
diff
changeset
|
219 """ |
5086
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
220 comments = self._get_comments(repo_id, revision=revision, pull_request=pull_request, |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
221 inline=True, f_path=f_path, line_no=line_no) |
5086
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
222 |
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
223 paths = defaultdict(lambda: defaultdict(list)) |
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
224 for co in comments: |
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
225 paths[co.f_path][co.line_no].append(co) |
8047
db6573f71b89
tests: fix ordering of get_inline_comments output
Mads Kiilerich <mads@kiilerich.com>
parents:
7821
diff
changeset
|
226 return sorted(paths.items()) |
5086
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
227 |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
228 def _get_comments(self, repo_id, revision=None, pull_request=None, |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
229 inline=False, f_path=None, line_no=None): |
5086
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
230 """ |
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
231 Gets comments for either revision or pull_request_id, either inline or general. |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
232 If a file path and optionally line number are given, return only the matching inline comments. |
5086
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
233 """ |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
234 if f_path is None and line_no is not None: |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
235 raise Exception("line_no only makes sense if f_path is given.") |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
236 |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
237 if inline is None and f_path is not None: |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
238 raise Exception("f_path only makes sense for inline comments.") |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
239 |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
240 q = meta.Session().query(db.ChangesetComment) |
5086
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
241 |
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
242 if inline: |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
243 if f_path is not None: |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
244 # inline comments for a given file... |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
245 q = q.filter(db.ChangesetComment.f_path == f_path) |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
246 if line_no is None: |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
247 # ... on any line |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
248 q = q.filter(db.ChangesetComment.line_no != None) |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
249 else: |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
250 # ... on specific line |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
251 q = q.filter(db.ChangesetComment.line_no == line_no) |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
252 else: |
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
253 # all inline comments |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
254 q = q.filter(db.ChangesetComment.line_no != None) \ |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
255 .filter(db.ChangesetComment.f_path != None) |
5086
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
256 else: |
7489
445d6875c2ee
model: comments: allow selective retrieval of inline comments
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7448
diff
changeset
|
257 # all general comments |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
258 q = q.filter(db.ChangesetComment.line_no == None) \ |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
259 .filter(db.ChangesetComment.f_path == 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
|
260 |
5539
87285c5007fb
comments: check for None instead of boolean checks
Mads Kiilerich <madski@unity3d.com>
parents:
5499
diff
changeset
|
261 if revision is not None: |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
262 q = q.filter(db.ChangesetComment.revision == revision) \ |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
263 .filter(db.ChangesetComment.repo_id == repo_id) |
5539
87285c5007fb
comments: check for None instead of boolean checks
Mads Kiilerich <madski@unity3d.com>
parents:
5499
diff
changeset
|
264 elif pull_request is not None: |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
265 pull_request = db.PullRequest.guess_instance(pull_request) |
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
266 q = q.filter(db.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
|
267 else: |
5086
b5e399286ce5
ChangesetCommentsModel: refactor duplicate code
Jan Heylen <heyleke@gmail.com>
parents:
5085
diff
changeset
|
268 raise Exception('Please specify either revision or pull_request') |
1677
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
269 |
8687
5e46f73f0d1c
model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents:
8686
diff
changeset
|
270 return q.order_by(db.ChangesetComment.created_on).all() |