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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
2.8 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
2021-12-11 22:18:48 +05:30
COMMITS_DEFAULT_LIMIT = 40
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
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
2021-12-11 22:18:48 +05:30
urgency :low, [:signatures, :show]
2021-01-03 14:25:43 +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
2022-05-07 20:08:51 +05:30
format.atom { render layout: 'xml' }
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?
2021-12-11 22:18:48 +05:30
2022-04-04 11:22:00 +05:30
limit = permitted_params[:limit].to_i
2021-12-11 22:18:48 +05:30
@limit = limit > 0 ? limit : COMMITS_DEFAULT_LIMIT # limit can only ever be a positive number
2022-04-04 11:22:00 +05:30
@offset = (permitted_params[:offset] || 0).to_i
search = permitted_params[:search]
author = permitted_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
2022-07-23 23:45:48 +05:30
@commits = @commits.with_markdown_cache.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
2022-04-04 11:22:00 +05:30
def permitted_params
params.permit(:limit, :offset, :search, :author)
end
2014-09-02 18:07:02 +05:30
end