Add an API for commenting on FileDiffs ranges
Review Request #10190 — Created Oct. 19, 2018 and submitted — Latest diff uploaded
The
ReviewDiffCommentResource
is now capable of creating comments on
FileDiffs with a base FileDiff ID. This allows us to comment on
FileDiffs in commit ranges and keep the context of the base FileDiff.
Ran unit tests.
Diff Revision 2
This is not the most recent revision of the diff. The latest diff is revision 5. See what's changed.
orig
1
2
3
4
5
reviewboard/reviews/models/diff_comment.py | |||
---|---|---|---|
Revision c99980cf764719729190164f389d5906a8c165de | New Change | ||
11 lines | |||
12 |
"""A comment made on a diff. |
12 |
"""A comment made on a diff. |
13 | 13 | ||
14 |
A comment can belong to a single filediff or to an interdiff between
|
14 |
A comment can belong to a single filediff or to an interdiff between
|
15 |
two filediffs. It can also have multiple replies.
|
15 |
two filediffs. It can also have multiple replies.
|
16 |
"""
|
16 |
"""
|
17 | |||
18 |
_BASE_FILEDIFF_ID_KEY = '__base_filediff_id' |
||
19 | |||
17 |
anchor_prefix = "comment" |
20 |
anchor_prefix = "comment" |
18 |
comment_type = "diff" |
21 |
comment_type = "diff" |
19 |
filediff = models.ForeignKey(FileDiff, verbose_name=_('file diff'), |
22 |
filediff = models.ForeignKey(FileDiff, verbose_name=_('file diff'), |
20 |
related_name="comments") |
23 |
related_name="comments") |
21 |
interfilediff = models.ForeignKey(FileDiff, |
24 |
interfilediff = models.ForeignKey(FileDiff, |
8 lines | |||
30 |
num_lines = models.PositiveIntegerField(_("number of lines"), blank=True, |
33 |
num_lines = models.PositiveIntegerField(_("number of lines"), blank=True, |
31 |
null=True) |
34 |
null=True) |
32 | 35 | ||
33 |
last_line = property(lambda self: self.first_line + self.num_lines - 1) |
36 |
last_line = property(lambda self: self.first_line + self.num_lines - 1) |
34 | 37 | ||
38 |
@property
|
||
39 |
def base_filediff_id(self): |
||
1 | 40 |
"""The ID base FileDiff for the cumulative diff this comment is on.""" |
|
1 | 41 |
if self.extra_data is None: |
|
42 |
return None |
||
43 | |||
44 |
return self.extra_data.get(self._BASE_FILEDIFF_ID_KEY) |
||
45 | |||
46 |
@base_filediff_id.setter |
||
47 |
def base_filediff_id(self, filediff_id): |
||
48 |
if self.extra_data is None: |
||
49 |
self.extra_data = {} |
||
50 | |||
51 |
self.extra_data[self._BASE_FILEDIFF_ID_KEY] = filediff_id |
||
52 | |||
35 |
def get_absolute_url(self): |
53 |
def get_absolute_url(self): |
36 |
revision_path = six.text_type(self.filediff.diffset.revision) |
54 |
revision_path = six.text_type(self.filediff.diffset.revision) |
37 |
if self.interfilediff: |
55 |
if self.interfilediff: |
38 |
revision_path += "-%s" % self.interfilediff.diffset.revision |
56 |
revision_path += "-%s" % self.interfilediff.diffset.revision |
39 | 57 | ||
9 lines |
reviewboard/webapi/resources/base_comment.py |
---|
reviewboard/webapi/resources/base_diff_comment.py |
---|
reviewboard/webapi/resources/review_diff_comment.py |
---|
reviewboard/webapi/tests/test_review_comment.py |
---|