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

86 lines
2.6 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-11-18 11:00:15 +05:30
before_action :whitelist_query_limiting, except: :commits_root
2015-09-11 14:41:01 +05:30
before_action :require_non_empty_project
2018-11-18 11:00:15 +05:30
before_action :assign_ref_vars, except: :commits_root
2015-09-11 14:41:01 +05:30
before_action :authorize_download_code!
2018-11-18 11:00:15 +05:30
before_action :set_commits, except: :commits_root
2018-11-08 19:23:39 +05:30
before_action :set_request_format, only: :show
2014-09-02 18:07:02 +05:30
2018-11-18 11:00:15 +05:30
def commits_root
redirect_to project_commits_path(@project, @project.default_branch)
end
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-27 19:54:05 +05:30
respond_to do |format|
format.html
format.atom { render layout: 'xml.atom' }
2016-11-24 13:41:30 +05:30
2018-03-27 19:54:05 +05:30
format.json do
pager_json(
'projects/commits/_commits',
@commits.size,
project: @project,
ref: @ref)
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-27 19:54:05 +05:30
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
}
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
2018-11-20 20:47:30 +05:30
@commits = set_commits_for_rendering(@commits)
2018-03-17 18:26:18 +05:30
end
2018-11-08 19:23:39 +05:30
# Rails 5 sets request.format from the extension.
# Explicitly set to :html.
def set_request_format
request.format = :html if set_request_format?
end
# Rails 5 sets request.format from extension.
# In this case if the ref ends with `.atom`, it's expected to be the html response,
# not the atom one. So explicitly set request.format as :html to act like rails4.
def set_request_format?
request.format.to_s == "text/html" || @commits.ref.ends_with?("atom")
end
2018-03-17 18:26:18 +05:30
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