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

83 lines
2.4 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
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-29 20:51:05 +05:30
prepend_before_action(only: [:show]) { authenticate_sessionless_user!(:rss) }
2019-07-07 11:18:12 +05:30
around_action :allow_gitaly_ref_name_caching
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!
2019-02-15 15:39:39 +05:30
before_action :validate_ref!, except: :commits_root
2018-11-18 11:00:15 +05:30
before_action :set_commits, except: :commits_root
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
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
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
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
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
2019-02-15 15:39:39 +05:30
def validate_ref!
render_404 unless valid_ref?(@ref)
end
2017-09-10 17:25:29 +05:30
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
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