diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-08-11 16:36:22 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-08-11 16:36:22 +0300 |
commit | 8b7ece40de9dd60b9f9758ab3af9914c96afa4af (patch) | |
tree | 44531f0f44467ff00db94358e51aaab92b0d0ea0 | |
parent | 1a06f6b8721fdc8ddf25aedf06543fe63e024216 (diff) | |
download | gitlab-ce-winh-gpg-status-repository.tar.gz |
Change commits/signatures method to accept array of shawinh-gpg-status-repository
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r-- | app/controllers/projects/commits_controller.rb | 54 | ||||
-rw-r--r-- | config/routes/repository.rb | 2 | ||||
-rw-r--r-- | spec/controllers/projects/commits_controller_spec.rb | 12 |
3 files changed, 41 insertions, 27 deletions
diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb index 2de9900d449..867506bcf62 100644 --- a/app/controllers/projects/commits_controller.rb +++ b/app/controllers/projects/commits_controller.rb @@ -4,11 +4,20 @@ class Projects::CommitsController < Projects::ApplicationController include ExtractsPath before_action :require_non_empty_project - before_action :assign_ref_vars + before_action :assign_ref_vars, only: :show before_action :authorize_download_code! - before_action :set_commits def show + @limit, @offset = (params[:limit] || 40).to_i, (params[:offset] || 0).to_i + search = params[:search] + + @commits = + if search.present? + @repository.find_commits_by_message(search, @ref, @path, @limit, @offset) + else + @repository.commits(@ref, path: @path, limit: @limit, offset: @offset) + end + @note_counts = project.notes.where(commit_id: @commits.map(&:id)) .group(:commit_id).count @@ -30,31 +39,24 @@ class Projects::CommitsController < Projects::ApplicationController end def signatures - respond_to do |format| - format.json do - render json: { - signatures: @commits.select(&:has_signature?).map do |commit| - { - commit_sha: commit.sha, - html: view_to_html_string('projects/commit/_signature', signature: commit.signature) - } - end + commit_ids = Array(params[:sha]) + + signatures = GpgSignature.where(commit_sha: commit_ids) + + # Filter commits without GpgSignature record in the database + # but with signature in git and create missing GpgSignature objects by + # invoking `signature` method on those + commit_ids = commit_ids - signatures.map(&:commit_sha) + commits = commit_ids.map { |sha| @repository.commit(sha) } + signatures += commits.select(&:has_signature?).map(&:signature) + + render json: { + signatures: signatures.map do |signature| + { + commit_sha: signature.commit_sha, + html: view_to_html_string('projects/commit/_signature', signature: signature) } end - end - end - - private - - def set_commits - @limit, @offset = (params[:limit] || 40).to_i, (params[:offset] || 0).to_i - search = params[:search] - - @commits = - if search.present? - @repository.find_commits_by_message(search, @ref, @path, @limit, @offset) - else - @repository.commits(@ref, path: @path, limit: @limit, offset: @offset) - end + } end end diff --git a/config/routes/repository.rb b/config/routes/repository.rb index 2ba16035ece..2c4557d2e14 100644 --- a/config/routes/repository.rb +++ b/config/routes/repository.rb @@ -10,6 +10,7 @@ end # See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments scope format: false do get '/compare/:from...:to', to: 'compare#show', as: 'compare', constraints: { from: /.+/, to: /.+/ } + get '/commits/signatures', to: 'commits#signatures', as: :signatures resources :compare, only: [:index, :create] do collection do @@ -77,7 +78,6 @@ scope format: false do get '/raw/*id', to: 'raw#show', as: :raw get '/blame/*id', to: 'blame#show', as: :blame - get '/commits/*id/signatures', to: 'commits#signatures', as: :signatures get '/commits/*id', to: 'commits#show', as: :commits post '/create_dir/*id', to: 'tree#create_dir', as: :create_dir diff --git a/spec/controllers/projects/commits_controller_spec.rb b/spec/controllers/projects/commits_controller_spec.rb index e26731fb691..2db5ca800f6 100644 --- a/spec/controllers/projects/commits_controller_spec.rb +++ b/spec/controllers/projects/commits_controller_spec.rb @@ -45,4 +45,16 @@ describe Projects::CommitsController do end end end + + describe "GET signatures" do + it "renders as json" do + get(:signatures, + namespace_id: project.namespace, + project_id: project, + sha: project.repository.commit.sha) + + expect(response).to be_success + expect(response.content_type).to eq('application/json') + end + end end |