Skip to content

Commit

Permalink
Merge pull request #16964 from hellcp-work/diff-use-revs
Browse files Browse the repository at this point in the history
Make use of the revs in the comments to display the right diff
  • Loading branch information
hellcp-work authored Oct 21, 2024
2 parents 76ee4a7 + e7fe9a8 commit 949785f
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 218 deletions.
3 changes: 2 additions & 1 deletion src/api/.rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Metrics/BlockNesting:
- 'app/models/bs_request_action.rb'
- 'lib/xpath_engine.rb'

# Offense count: 85
# Offense count: 86
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Exclude:
Expand Down Expand Up @@ -143,6 +143,7 @@ Metrics/ClassLength:
- 'app/models/bs_request_permission_check.rb'
- 'app/models/buildresult.rb'
- 'app/models/channel.rb'
- 'app/models/comment.rb'
- 'app/models/event/base.rb'
- 'app/models/event/request.rb'
- 'app/models/group.rb'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def diff_for_ref(comment)
return unless (ref = comment.diff_ref&.match(/diff_([0-9]+)/))

file_index = ref.captures.first
sourcediff = @commented_actions.find(comment.commentable.id).first.webui_sourcediff.first
sourcediff = @commented_actions.find(comment.commentable.id).first.webui_sourcediff(rev: comment.source_rev, orev: comment.target_rev).first
filename = sourcediff.dig('filenames', file_index.to_i)
sourcediff.dig('files', filename)
end
Expand Down
5 changes: 3 additions & 2 deletions src/api/app/components/bs_request_comment_component.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@
- if diff
- action = comment.commentable
.px-3.pt-3.pb-2
= link_to request_show_path(number: action.bs_request, request_action_id: action) do
= action.uniq_key
= link_to(action.uniq_key, request_show_path(number: action.bs_request, request_action_id: action))
>
= link_to request_changes_path(number: action.bs_request, request_action_id: action, anchor: comment.diff_ref) do
= render(DiffSubjectComponent.new(state: diff['state'], old_filename: diff.dig('old', 'name'), new_filename: diff.dig('new', 'name')))
- if comment.outdated?
%span.badge.text-bg-warning Outdated
= render(DiffComponent.new(diff: diff.dig('diff', '_content'), range:))
- else
%p.border-bottom.fst-italic.px-3.pt-3.pb-2
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/controllers/webui/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ def diff
return unless @comment.root.commentable_type == 'BsRequestAction' && @comment.root.diff_ref
return unless (ref = @comment.root.diff_ref&.match(/diff_([0-9]+)/))

diffs = @comment.root.commentable.bs_request.webui_actions(action_id: @comment.root.commentable_id, diffs: true, cacheonly: 1).first
sourcediff = @comment.root.commentable.webui_sourcediff(rev: @comment.root.source_rev, orev: @comment.root.target_rev).first
file_index = ref.captures.first
sourcediff = diffs[:sourcediff].first
filename = sourcediff.dig('filenames', file_index.to_i)
sourcediff.dig('files', filename)
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/bs_request_action/differ/for_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def diff(source_package_name)
end

def query
query = {}
query = options.slice(:rev, :orev).compact
query[:view] = :xml if options[:view].to_s == 'xml'
query[:withissues] = 1 if options[:withissues].present?
if options[:nodiff].present?
Expand Down
8 changes: 8 additions & 0 deletions src/api/app/models/bs_request_action_submit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ def forward
forward_object
end

def source_srcmd5
source_package_object&.dir_hash({ rev: source_rev }.compact)&.[]('srcmd5')
end

def target_srcmd5
target_package_object&.dir_hash&.[]('srcmd5')
end

#### Alias of methods
end

Expand Down
14 changes: 14 additions & 0 deletions src/api/app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ def body
super
end

def revisions?
return false if diff_ref.blank?
return false if source_rev.nil? || target_rev.nil?

true
end

def outdated?
return false unless revisions?
return true unless commentable.target_srcmd5 == target_rev && commentable.source_srcmd5 == source_rev

false
end

private

def create_event
Expand Down
Loading

0 comments on commit 949785f

Please sign in to comment.