debian-mirror-gitlab/app/controllers/projects/commits_controller.rb

74 lines
2.2 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require "base64"
class Projects::CommitsController < Projects::ApplicationController
include ExtractsPath
2018-03-17 18:26:18 +05:30
include RendersCommits
2014-09-02 18:07:02 +05:30
2018-03-17 18:26:18 +05:30
before_action :whitelist_query_limiting
2015-09-11 14:41:01 +05:30
before_action :require_non_empty_project
before_action :assign_ref_vars
before_action :authorize_download_code!
2017-09-10 17:25:29 +05:30
before_action :set_commits
2014-09-02 18:07:02 +05:30
def show
2017-09-10 17:25:29 +05:30
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
2016-04-02 18:10:28 +05:30
2018-03-17 18:26:18 +05:30
# https://gitlab.com/gitlab-org/gitaly/issues/931
Gitlab::GitalyClient.allow_n_plus_1_calls do
respond_to do |format|
format.html
format.atom { render layout: 'xml.atom' }
2016-11-24 13:41:30 +05:30
2018-03-17 18:26:18 +05:30
format.json do
pager_json(
'projects/commits/_commits',
@commits.size,
project: @project,
ref: @ref)
end
2016-11-24 13:41:30 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
2017-09-10 17:25:29 +05:30
def signatures
2018-03-17 18:26:18 +05:30
# https://gitlab.com/gitlab-org/gitaly/issues/931
Gitlab::GitalyClient.allow_n_plus_1_calls do
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
}
end
2017-09-10 17:25:29 +05:30
end
end
end
private
def set_commits
2018-03-17 18:26:18 +05:30
render_404 unless @path.empty? || request.format == :atom || @repository.blob_at(@commit.id, @path) || @repository.tree(@commit.id, @path).entries.present?
2017-09-10 17:25:29 +05:30
@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
2018-03-17 18:26:18 +05:30
@commits = @commits.with_pipeline_status
@commits = prepare_commits_for_rendering(@commits)
end
def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42330')
2017-09-10 17:25:29 +05:30
end
2014-09-02 18:07:02 +05:30
end