diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-07-30 19:55:28 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-07-30 19:55:28 +0300 |
commit | 9a81550feddd907f8796362d604f63ed66ad80a2 (patch) | |
tree | 90d9c1deae0ee2c57b05fbe76ed96d13cf54a1af /app | |
parent | 5b6553a0810f65d79c648aca9dba254644a293fb (diff) |
Create GPG commit signature in bulk
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/services/git_push_service.rb | 14 | ||||
-rw-r--r-- | app/workers/create_gpg_signature_worker.rb | 16 |
3 files changed, 24 insertions, 10 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index b876270116e..da30d2fbb4f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -548,6 +548,10 @@ class Project < ActiveRecord::Base repository.commit_by(oid: oid) end + def commits_by(oids:) + repository.commits_by(oids: oids) + end + # ref can't be HEAD, can only be branch/tag name or SHA def latest_successful_builds_for(ref = default_branch) latest_pipeline = pipelines.latest_successful_for(ref) diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 29c8ce5fea3..f0587667d37 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -76,7 +76,7 @@ class GitPushService < BaseService else paths = Set.new - @push_commits.last(PROCESS_COMMIT_LIMIT).each do |commit| + last_pushed_commits.each do |commit| commit.raw_deltas.each do |diff| paths << diff.new_path end @@ -92,7 +92,7 @@ class GitPushService < BaseService end def update_signatures - commit_shas = @push_commits.last(PROCESS_COMMIT_LIMIT).map(&:sha) + commit_shas = last_pushed_commits.map(&:sha) return if commit_shas.empty? @@ -103,16 +103,14 @@ class GitPushService < BaseService commit_shas = Gitlab::Git::Commit.shas_with_signatures(project.repository, commit_shas) - commit_shas.each do |sha| - CreateGpgSignatureWorker.perform_async(sha, project.id) - end + CreateGpgSignatureWorker.perform_async(commit_shas, project.id) end # Schedules processing of commit messages. def process_commit_messages default = default_branch? - @push_commits.last(PROCESS_COMMIT_LIMIT).each do |commit| + last_pushed_commits.each do |commit| if commit.matches_cross_reference_regex? ProcessCommitWorker .perform_async(project.id, current_user.id, commit.to_hash, default) @@ -206,4 +204,8 @@ class GitPushService < BaseService def branch_name @branch_name ||= Gitlab::Git.ref_name(params[:ref]) end + + def last_pushed_commits + @last_pushed_commits ||= @push_commits.last(PROCESS_COMMIT_LIMIT) + end end diff --git a/app/workers/create_gpg_signature_worker.rb b/app/workers/create_gpg_signature_worker.rb index a2da1bda11f..91833941070 100644 --- a/app/workers/create_gpg_signature_worker.rb +++ b/app/workers/create_gpg_signature_worker.rb @@ -3,15 +3,23 @@ class CreateGpgSignatureWorker include ApplicationWorker - def perform(commit_sha, project_id) + def perform(commit_shas, project_id) + return if commit_shas.empty? + project = Project.find_by(id: project_id) return unless project - commit = project.commit(commit_sha) + commits = project.commits_by(oids: commit_shas) - return unless commit + return if commits.empty? # This calculates and caches the signature in the database - Gitlab::Gpg::Commit.new(commit).signature + commits.each do |commit| + begin + Gitlab::Gpg::Commit.new(commit).signature + rescue => e + Rails.logger.error("Failed to create signature for commit #{commit.id}. Error: #{e.message}") + end + end end end |