Commit 6bfbc3c6 authored by Gary Holtz's avatar Gary Holtz

Some quick refactors to make the pipelines pass

Also makes the code a little more verbose
parent ff650aa8
......@@ -85,16 +85,15 @@ class DiffsEntity < Grape::Entity
end
end
def commits(id)
commit_ids.each_cons(3) do |prev_commit, commit, next_commit|
{ prev_commit_id: prev_commit, next_commit_id: next_commit } if commit == id
end
def commit_with_neighbors(id)
commits = commit_ids.each_cons(3).find { |prev_commit, commit, next_commit| commit == id }
{ prev_commit_id: commits.first, next_commit_id: commits.last } if commits
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)
neighbors = commit_with_neighbors(options[:commit]&.id)
prev_commit_id = neighbors&.dig(:prev_commit_id)
next_commit_id = neighbors&.dig(:next_commit_id)
options.merge(
type: :full,
......
......@@ -28,8 +28,8 @@ describe DiffsEntity do
end
context "when a commit_id is passed" do
let(:commits) { merge_request.commits }
let(:commit) { commits.sample }
let(:commits) { [nil] + merge_request.commits + [nil] }
let(:commit) { commits.compact.sample }
let(:entity) do
described_class.new(merge_request_diffs.first.diffs, request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs, commit: commit)
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