Commit ff650aa8 authored by Gary Holtz's avatar Gary Holtz

Moves some entity code to avoid a fixture error

parent 9b641b7b
......@@ -17,20 +17,7 @@ class DiffsEntity < Grape::Entity
end
expose :commit do |diffs, options|
if options[:commit]
neighbors = commits(options[:commit].id) if options[:commit]
prev_commit_id = neighbors[:prev_commit_id]
next_commit_id = neighbors[:next_commit_id]
end
CommitEntity.represent options[:commit], options.merge(
type: :full,
commit_url_params: { merge_request_iid: merge_request&.iid },
pipeline_ref: merge_request&.source_branch,
pipeline_project: merge_request&.source_project,
prev_commit_id: prev_commit_id,
next_commit_id: next_commit_id
)
CommitEntity.represent options[:commit], commit_options(options)
end
expose :context_commits, using: API::Entities::Commit, if: -> (diffs, options) { merge_request&.project&.context_commits_enabled? } do |diffs|
......@@ -90,6 +77,8 @@ class DiffsEntity < Grape::Entity
options[:merge_request]
end
private
def commit_ids
strong_memoize(:commit_ids) do
[nil] + merge_request.commits.collect(&:id) + [nil]
......@@ -101,4 +90,19 @@ class DiffsEntity < Grape::Entity
{ prev_commit_id: prev_commit, next_commit_id: next_commit } if commit == id
end
end
def commit_options(options)
neighbors = commits(options[:commit].id)
prev_commit_id = neighbors.try(:prev_commit_id)
next_commit_id = neighbors.try(:next_commit_id)
options.merge(
type: :full,
commit_url_params: { merge_request_iid: merge_request&.iid },
pipeline_ref: merge_request&.source_branch,
pipeline_project: merge_request&.source_project,
prev_commit_id: prev_commit_id,
next_commit_id: next_commit_id
)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment