gitlab-org--gitlab-foss/app/controllers/projects/commits_controller.rb

95 lines
2.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2011-10-08 17:36:38 -04:00
require "base64"
class Projects::CommitsController < Projects::ApplicationController
include ExtractsPath
include RendersCommits
COMMITS_DEFAULT_LIMIT = 40
prepend_before_action(only: [:show]) { authenticate_sessionless_user!(:rss) }
around_action :allow_gitaly_ref_name_caching
before_action :require_non_empty_project
before_action :assign_ref_vars, except: :commits_root
before_action :authorize_download_code!
before_action :validate_ref!, except: :commits_root
before_action :set_commits, except: :commits_root
2011-10-08 17:36:38 -04:00
feature_category :source_code_management
urgency :low, [:signatures, :show]
def commits_root
redirect_to project_commits_path(@project, @project.default_branch)
end
# rubocop: disable CodeReuse/ActiveRecord
def show
2017-06-21 09:48:12 -04:00
@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)
respond_to do |format|
format.html
format.atom { render layout: 'xml' }
2018-01-18 09:10:17 -05:00
format.json do
pager_json(
'projects/commits/_commits',
@commits.size,
project: @project,
ref: @ref)
end
2011-10-08 17:36:38 -04:00
end
end
# rubocop: enable CodeReuse/ActiveRecord
2017-07-25 03:40:23 -04:00
def signatures
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-07-25 03:40:23 -04:00
end
end
end
private
def validate_ref!
render_404 unless valid_ref?(@ref)
end
2017-07-25 03:40:23 -04:00
def set_commits
2017-11-27 08:36:02 -05:00
render_404 unless @path.empty? || request.format == :atom || @repository.blob_at(@commit.id, @path) || @repository.tree(@commit.id, @path).entries.present?
limit = permitted_params[:limit].to_i
@limit = limit > 0 ? limit : COMMITS_DEFAULT_LIMIT # limit can only ever be a positive number
@offset = (permitted_params[:offset] || 0).to_i
search = permitted_params[:search]
author = permitted_params[:author]
2017-07-25 03:40:23 -04:00
@commits =
if search.present?
@repository.find_commits_by_message(search, @ref, @path, @limit, @offset)
elsif author.present?
@repository.commits(@ref, author: author, path: @path, limit: @limit, offset: @offset)
2017-07-25 03:40:23 -04:00
else
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end
@commits.each(&:lazy_author) # preload authors
@commits = @commits.with_latest_pipeline(@ref)
@commits = set_commits_for_rendering(@commits)
2017-07-25 03:40:23 -04:00
end
def permitted_params
params.permit(:limit, :offset, :search, :author)
end
2011-10-08 17:36:38 -04:00
end