Fix comment links for file attachments in diffs.
Review Request #13681 — Created March 29, 2024 and submitted
This change fixes the links for file attachments which are attached to
binary files in a diff. The Review UI implementation was previously just
linking to the file attachment page, but that's a pretty crummy
experience when the comments were made on the diff.This is pretty complex because there are a lot of corner cases. In
particular, we have to deal with three annoying things:
- We sometimes elide the base commit ID or tip commit ID from the URL,
depending on what commits are selected.- When a review request has commit history, the attachment is uploaded
for the commit-specific filediff, and then we do some magic to find
it when the user is viewing the cumulative diff. In this case, we
have to do the opposite and figure out if the user had commented on
the file while viewing the cumulative diff so we can link back to
that rather than the commit range.- When we do that backwards lookup for annoying thing #2, we need to
make sure that we set the anchor to the correct filediff ID.Unit tests have been added to cover all of these corner cases.
- Created a review request with a ton of comments on binary files across
various revision and commit ranges. Checked that clicking on the
filename listed in the comments correctly opened the corresponding
diff view. - Ran unit tests.
Summary | ID |
---|---|
b656e376010e8a741d0b4277b5def441de9b0225 |
Description | From | Last Updated |
---|---|---|
local variable 'upstream_attachment' is assigned to but never used Column: 9 Error code: F841 |
reviewbot | |
'typing.cast' imported but unused Column: 1 Error code: F401 |
reviewbot | |
These should be in alphabetical order. |
chipx86 | |
"For comments file attachments" -> "For file attachment comments" ? |
chipx86 | |
These are missing docs. |
chipx86 | |
We aren't returning anything in this case. |
chipx86 | |
Looks like the line join got broken when wrapping. |
chipx86 | |
We aren't returning anything in this case. |
chipx86 | |
We aren't returning anything in this case. |
chipx86 | |
This is still going through all the logic of constructing an object and setting up deferred attribute values. We should … |
chipx86 | |
This should go in the previous import group. |
chipx86 | |
We can wrap this at a . and beanbag-docutils will do the right thing. Although this is a standard comment … |
chipx86 | |
Let's sort these in alphabetical order. |
chipx86 | |
This should say "get_comment_link_url" instead of "get_comment_thumbnail". |
maubin | |
This is wrong. |
maubin |
- Commits:
-
Summary ID 3797485cc2a5ab0b03b80d11f5530f5722686c03 38d04ea4b32057b8a6e11e03886715db413d8a98
Checks run (2 succeeded)
- Change Summary:
-
Move revision computation into
FileAttachmentComment
so we can use it elsewhere. - Commits:
-
Summary ID 38d04ea4b32057b8a6e11e03886715db413d8a98 ca928728603066426e91cfec3fae190fcdf8f196
- Commits:
-
Summary ID ca928728603066426e91cfec3fae190fcdf8f196 56a785a3da2fea4dc2a480a571c9a1001d851782
Checks run (2 succeeded)
-
-
-
-
-
-
-
-
-
This is still going through all the logic of constructing an object and setting up deferred attribute values. We should just use
values_list
:last_commit_id = ( modified_diffset.commits .order_by('-pk') .values_list('pk', flat=True) )[0]
This will still only fetch one result, since
values_list
will evaluate on access, and a direct access of an item will evaluate only to the item needed unless the cache is already populated. -
-
We can wrap this at a
.
andbeanbag-docutils
will do the right thing.Although this is a standard comment and not processed by ReST.
-
- Commits:
-
Summary ID 56a785a3da2fea4dc2a480a571c9a1001d851782 43ce20313daaff948f7dbc92017039d961eb548c