Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 15:08:18 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 15:08:18 +0300
commit684d65316ac77c62f47d68b9926eea8af30db227 (patch)
treed1f4c4eec399d7772ab4ad6294f98e7505c1cee5 /app/serializers
parentade18c9d68d5a2e6c6e28ef7e9d3add3b3491ace (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/diffs_entity.rb34
1 files changed, 28 insertions, 6 deletions
diff --git a/app/serializers/diffs_entity.rb b/app/serializers/diffs_entity.rb
index b709fc7228b..1d0b4183f96 100644
--- a/app/serializers/diffs_entity.rb
+++ b/app/serializers/diffs_entity.rb
@@ -16,12 +16,7 @@ class DiffsEntity < Grape::Entity
end
expose :commit do |diffs, options|
- 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
- )
+ 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|
@@ -88,4 +83,31 @@ class DiffsEntity < Grape::Entity
def merge_request
options[:merge_request]
end
+
+ private
+
+ def commit_ids
+ @commit_ids ||= merge_request.recent_commits.map(&:id)
+ end
+
+ def commit_neighbors(commit_id)
+ index = commit_ids.index(commit_id)
+
+ return [] unless index
+
+ [(index > 0 ? commit_ids[index - 1] : nil), commit_ids[index + 1]]
+ end
+
+ def commit_options(options)
+ prev_commit_id, next_commit_id = *commit_neighbors(options[: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