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

90 lines
2.7 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
2021-01-03 14:25:43 +05:30
feature_category :source_code_management
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]
2020-04-08 14:13:33 +05:30
author = params[:author]
2017-09-10 17:25:29 +05:30
@commits =
if search.present?
@repository.find_commits_by_message(search, @ref, @path, @limit, @offset)
2020-04-08 14:13:33 +05:30
elsif author.present?
@repository.commits(@ref, author: author, path: @path, limit: @limit, offset: @offset)
2017-09-10 17:25:29 +05:30
else
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end
2018-03-17 18:26:18 +05:30
2019-12-21 20:55:43 +05:30
@commits.each(&:lazy_author) # preload authors
@commits = @commits.with_latest_pipeline(@ref)
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
2019-12-04 20:38:33 +05:30
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42330')
2017-09-10 17:25:29 +05:30
end
2014-09-02 18:07:02 +05:30
end