Skip to content

Commit

Permalink
Expand diffs that contain comments by default
Browse files Browse the repository at this point in the history
  • Loading branch information
danidoni committed Mar 27, 2023
1 parent d92c9fe commit 3fe2a12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/api/app/components/diff_list_component.html.haml
@@ -1,6 +1,6 @@
- diff_list.each_with_index do |(name, file_info), file_index|
- state = file_info['state']
- expanded = expand?(name, state)
- expanded = expand?(name, state, file_index)
.accordion.mb-2{ id: "diff-list-#{name.parameterize}" }
.accordion-item
%h2.accordion-header
Expand Down
14 changes: 12 additions & 2 deletions src/api/app/components/diff_list_component.rb
Expand Up @@ -11,7 +11,17 @@ def initialize(diff_list:, view_id: nil, commentable: nil)
@commented_lines = commentable ? commentable.comments.where.not(diff_ref: nil).select(:diff_ref).distinct.pluck(:diff_ref) : []
end

def expand?(filename, state)
state != 'deleted' && filename.exclude?('/') && (filename == '_patchinfo' || filename.ends_with?('.spec', '.changes'))
# We expand the diff if the changeset:
# it's not for a deletion
# and it is not a directory
# and it's a _patchinfo, *.spec or *.changes file
# or someone commented on the diff
def expand?(filename, state, file_index)
return true if
state != 'deleted' &&
filename.exclude?('/') &&
(filename == '_patchinfo' || filename.ends_with?('.spec', '.changes'))

commented_lines.any? { |cl| cl.split('_')[1].to_i == file_index }
end
end

0 comments on commit 3fe2a12

Please sign in to comment.