diffs: fixed outdated files in pull-requests re-using the filediff raw_id for anchor generation.

In some cases when there are no longer any files this caused error since filediff wasn't present.
In addition this generated wrong ids since it used a last-defined attribute on a for loop.

Fixes #5567
This commit is contained in:
Marcin Kuzminski 2019-09-25 10:33:00 +02:00
parent 8cd4048e19
commit e9cf83badc
3 changed files with 7 additions and 5 deletions

View file

@ -54,7 +54,7 @@ class TestGetRepoChangeset(object):
details=details,
)
response = api_call(self.app, params)
expected = 'commit_id must be a string value'
expected = "commit_id must be a string value got <type 'int'> instead"
assert_error(id_, expected, given=response.body)
@pytest.mark.parametrize("details", ['basic', 'extended', 'full'])
@ -137,5 +137,5 @@ class TestGetRepoChangeset(object):
details=details,
)
response = api_call(self.app, params)
expected = 'commit_id must be a string value'
expected = "commit_id must be a string value got <type 'int'> instead"
assert_error(id_, expected, given=response.body)

View file

@ -735,7 +735,7 @@ class BaseRepository(object):
def _validate_commit_id(self, commit_id):
if not isinstance(commit_id, compat.string_types):
raise TypeError("commit_id must be a string value")
raise TypeError("commit_id must be a string value got {} instead".format(type(commit_id)))
def _validate_commit_idx(self, commit_idx):
if not isinstance(commit_idx, (int, long)):

View file

@ -367,15 +367,17 @@ return '%s_%s_%i' % (h.md5_safe(commit+filename), type, line)
## outdated comments that are made for a file that has been deleted
% for filename, comments_dict in (deleted_files_comments or {}).items():
<%
display_state = 'display: none'
open_comments_in_file = [x for x in comments_dict['comments'] if x.outdated is False]
if open_comments_in_file:
display_state = ''
fid = str(id(filename))
%>
<div class="filediffs filediff-outdated" style="${display_state}">
<input ${(collapse_all and 'checked' or '')} class="filediff-collapse-state collapse-${diffset_container_id}" id="filediff-collapse-${id(filename)}" type="checkbox" onchange="updateSticky();">
<div class="filediff" data-f-path="${filename}" id="a_${h.FID(filediff.raw_id, filename)}">
<div class="filediff" data-f-path="${filename}" id="a_${h.FID(fid, filename)}">
<label for="filediff-collapse-${id(filename)}" class="filediff-heading">
<div class="filediff-collapse-indicator icon-"></div>
@ -387,7 +389,7 @@ return '%s_%s_%i' % (h.md5_safe(commit+filename), type, line)
## file op, doesn't need translation
<span class="pill" op="removed">removed in this version</span>
</span>
<a class="pill filediff-anchor" href="#a_${h.FID(filediff.raw_id, filename)}">¶</a>
<a class="pill filediff-anchor" href="#a_${h.FID(fid, filename)}">¶</a>
<span class="pill-group pull-right">
<span class="pill" op="deleted">-${comments_dict['stats']}</span>
</span>