2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
require "base64"
|
|
|
|
|
2013-06-23 12:47:22 -04:00
|
|
|
class Projects::CommitsController < Projects::ApplicationController
|
2012-09-20 15:32:00 -04:00
|
|
|
include ExtractsPath
|
2017-08-23 12:53:29 -04:00
|
|
|
include RendersCommits
|
2012-09-20 15:32:00 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
prepend_before_action(only: [:show]) { authenticate_sessionless_user!(:rss) }
|
2018-07-23 20:04:16 -04:00
|
|
|
before_action :whitelist_query_limiting, except: :commits_root
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :require_non_empty_project
|
2018-07-23 20:04:16 -04:00
|
|
|
before_action :assign_ref_vars, except: :commits_root
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_download_code!
|
2018-07-23 20:04:16 -04:00
|
|
|
before_action :set_commits, except: :commits_root
|
2011-10-08 17:36:38 -04:00
|
|
|
|
2018-07-23 20:04:16 -04:00
|
|
|
def commits_root
|
|
|
|
redirect_to project_commits_path(@project, @project.default_branch)
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2012-09-20 15:32:00 -04:00
|
|
|
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)
|
2016-02-01 18:43:51 -05:00
|
|
|
|
2018-02-28 11:56:00 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.atom { render layout: 'xml.atom' }
|
2018-01-18 09:10:17 -05:00
|
|
|
|
2018-02-28 11:56:00 -05:00
|
|
|
format.json do
|
|
|
|
pager_json(
|
|
|
|
'projects/commits/_commits',
|
|
|
|
@commits.size,
|
|
|
|
project: @project,
|
|
|
|
ref: @ref)
|
2016-10-21 04:22:43 -04:00
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-07-25 03:40:23 -04:00
|
|
|
|
|
|
|
def signatures
|
2018-02-28 11:56:00 -05:00
|
|
|
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 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?
|
2017-07-25 03:40:23 -04:00
|
|
|
@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
|
2017-08-23 12:53:29 -04:00
|
|
|
|
2017-11-10 14:57:11 -05:00
|
|
|
@commits = @commits.with_pipeline_status
|
2018-08-21 13:47:04 -04:00
|
|
|
@commits = set_commits_for_rendering(@commits)
|
2017-07-25 03:40:23 -04:00
|
|
|
end
|
2018-01-15 10:21:04 -05:00
|
|
|
|
|
|
|
def whitelist_query_limiting
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42330')
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|