From 2398324a0d0341ca488049e7bc83416f53ebec84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20W=C3=A4lter?= Date: Thu, 5 Aug 2021 11:01:48 +0200 Subject: [PATCH 1/4] Fix signature badge on commits tab of merge request Changelog: fixed --- app/models/merge_request_diff.rb | 4 ++-- spec/models/merge_request_diff_commit_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index bea75927b2cc1b..cab638af77e44e 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -701,8 +701,8 @@ def load_diffs(options) end def load_commits(limit: nil) - commits = merge_request_diff_commits.with_users.limit(limit) - .map { |commit| Commit.from_hash(commit.to_hash, project) } + commits = Gitlab::Git::Commit.batch_by_oid(repository, merge_request_diff_commits.with_users.limit(limit).map(&:sha)) + commits = Commit.decorate(commits, project) CommitCollection .new(merge_request.source_project, commits, merge_request.source_branch) diff --git a/spec/models/merge_request_diff_commit_spec.rb b/spec/models/merge_request_diff_commit_spec.rb index adddec7ced837d..6fd00659014af7 100644 --- a/spec/models/merge_request_diff_commit_spec.rb +++ b/spec/models/merge_request_diff_commit_spec.rb @@ -26,7 +26,7 @@ it 'returns the same results as Commit#to_hash, except for parent_ids' do commit_from_repo = project.repository.commit(subject.sha) - commit_from_repo_hash = commit_from_repo.to_hash.merge(parent_ids: []) + commit_from_repo_hash = commit_from_repo.to_hash.merge(parent_ids: commit_from_repo.parent_ids) expect(subject.to_hash).to eq(commit_from_repo_hash) end -- GitLab From 502b143ea6a6fee0c4b24a0ec3549db2bcaf6356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20W=C3=A4lter?= Date: Mon, 16 Aug 2021 09:21:22 +0200 Subject: [PATCH 2/4] Add spec for signature verification badge --- .../projects/merge_requests/_commits.html.haml_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/views/projects/merge_requests/_commits.html.haml_spec.rb b/spec/views/projects/merge_requests/_commits.html.haml_spec.rb index fd77c4eb37220e..c113480cf4667c 100644 --- a/spec/views/projects/merge_requests/_commits.html.haml_spec.rb +++ b/spec/views/projects/merge_requests/_commits.html.haml_spec.rb @@ -34,6 +34,12 @@ expect(rendered).to have_link(href: href) end + it 'shows signature verification badge' do + render + + expect(rendered).to have_css('.gpg-status-box') + end + context 'when there are hidden commits' do before do assign(:hidden_commit_count, 1) -- GitLab From ab676f5171df13c37bf4fc58620c00906da1213c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20W=C3=A4lter?= Date: Tue, 24 Aug 2021 15:25:23 +0200 Subject: [PATCH 3/4] Add `load_from_gitaly` parameter --- .../projects/merge_requests_controller.rb | 2 +- app/models/merge_request.rb | 8 ++++---- app/models/merge_request_diff.rb | 17 +++++++++++------ spec/models/merge_request_diff_commit_spec.rb | 2 +- .../merge_requests/_commits.html.haml_spec.rb | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 9dac240f2817c7..b9da1e09d4be13 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -175,7 +175,7 @@ def commits # or from cache if already merged @commits = set_commits_for_rendering( - @merge_request.recent_commits.with_latest_pipeline(@merge_request.source_branch).with_markdown_cache, + @merge_request.recent_commits(load_from_gitaly: true).with_latest_pipeline(@merge_request.source_branch).with_markdown_cache, commits_count: @merge_request.commits_count ) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index cf1468c5c53c2d..156540d455c6d5 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -615,8 +615,8 @@ def context_commits_count context_commits.count end - def commits(limit: nil) - return merge_request_diff.commits(limit: limit) if merge_request_diff.persisted? + def commits(limit: nil, load_from_gitaly: false) + return merge_request_diff.commits(limit: limit, load_from_gitaly: load_from_gitaly) if merge_request_diff.persisted? commits_arr = if compare_commits reversed_commits = compare_commits.reverse @@ -628,8 +628,8 @@ def commits(limit: nil) CommitCollection.new(source_project, commits_arr, source_branch) end - def recent_commits - commits(limit: MergeRequestDiff::COMMITS_SAFE_SIZE) + def recent_commits(load_from_gitaly: false) + commits(limit: MergeRequestDiff::COMMITS_SAFE_SIZE, load_from_gitaly: load_from_gitaly) end def commits_count diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index cab638af77e44e..97d707dc5b2bac 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -288,9 +288,9 @@ def raw_diffs(options = {}) end end - def commits(limit: nil) - strong_memoize(:"commits_#{limit || 'all'}") do - load_commits(limit: limit) + def commits(limit: nil, load_from_gitaly: false) + strong_memoize(:"commits_#{limit || 'all'}_#{load_from_gitaly}") do + load_commits(limit: limit, load_from_gitaly: load_from_gitaly) end end @@ -700,9 +700,14 @@ def load_diffs(options) end end - def load_commits(limit: nil) - commits = Gitlab::Git::Commit.batch_by_oid(repository, merge_request_diff_commits.with_users.limit(limit).map(&:sha)) - commits = Commit.decorate(commits, project) + def load_commits(limit: nil, load_from_gitaly: false) + if load_from_gitaly + commits = Gitlab::Git::Commit.batch_by_oid(repository, merge_request_diff_commits.with_users.limit(limit).map(&:sha)) + commits = Commit.decorate(commits, project) + else + commits = merge_request_diff_commits.with_users.limit(limit) + .map { |commit| Commit.from_hash(commit.to_hash, project) } + end CommitCollection .new(merge_request.source_project, commits, merge_request.source_branch) diff --git a/spec/models/merge_request_diff_commit_spec.rb b/spec/models/merge_request_diff_commit_spec.rb index 6fd00659014af7..adddec7ced837d 100644 --- a/spec/models/merge_request_diff_commit_spec.rb +++ b/spec/models/merge_request_diff_commit_spec.rb @@ -26,7 +26,7 @@ it 'returns the same results as Commit#to_hash, except for parent_ids' do commit_from_repo = project.repository.commit(subject.sha) - commit_from_repo_hash = commit_from_repo.to_hash.merge(parent_ids: commit_from_repo.parent_ids) + commit_from_repo_hash = commit_from_repo.to_hash.merge(parent_ids: []) expect(subject.to_hash).to eq(commit_from_repo_hash) end diff --git a/spec/views/projects/merge_requests/_commits.html.haml_spec.rb b/spec/views/projects/merge_requests/_commits.html.haml_spec.rb index c113480cf4667c..f0273c1716f661 100644 --- a/spec/views/projects/merge_requests/_commits.html.haml_spec.rb +++ b/spec/views/projects/merge_requests/_commits.html.haml_spec.rb @@ -21,7 +21,7 @@ controller.prepend_view_path('app/views/projects') assign(:merge_request, merge_request) - assign(:commits, merge_request.commits) + assign(:commits, merge_request.commits(load_from_gitaly: true)) assign(:hidden_commit_count, 0) end -- GitLab From a1c489ccb1db7074d79d10763a7a75c6dc049bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20W=C3=A4lter?= Date: Wed, 25 Aug 2021 16:32:33 +0200 Subject: [PATCH 4/4] Remove unused `with_users` --- app/models/merge_request_diff.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 97d707dc5b2bac..d2b3ca753b1d6c 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -702,7 +702,7 @@ def load_diffs(options) def load_commits(limit: nil, load_from_gitaly: false) if load_from_gitaly - commits = Gitlab::Git::Commit.batch_by_oid(repository, merge_request_diff_commits.with_users.limit(limit).map(&:sha)) + commits = Gitlab::Git::Commit.batch_by_oid(repository, merge_request_diff_commits.limit(limit).map(&:sha)) commits = Commit.decorate(commits, project) else commits = merge_request_diff_commits.with_users.limit(limit) -- GitLab