2025-07-18 17:36:37 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2011-05-29 13:11:52 -07:00
|
|
|
#-- copyright
|
2020-01-15 11:31:26 +01:00
|
|
|
# OpenProject is an open source project management software.
|
2024-07-30 13:42:36 +02:00
|
|
|
# Copyright (C) the OpenProject GmbH
|
2011-05-30 20:52:25 +02:00
|
|
|
#
|
2011-05-29 13:11:52 -07:00
|
|
|
# This program is free software; you can redistribute it and/or
|
2013-06-05 16:27:56 +02:00
|
|
|
# modify it under the terms of the GNU General Public License version 3.
|
2011-05-30 20:52:25 +02:00
|
|
|
#
|
2013-09-16 17:59:31 +02:00
|
|
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
2021-01-13 17:47:45 +01:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2013-09-16 17:59:31 +02:00
|
|
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
#
|
2021-09-02 21:49:06 +02:00
|
|
|
# See COPYRIGHT and LICENSE files for more details.
|
2011-05-29 13:11:52 -07:00
|
|
|
#++
|
|
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
require "SVG/Graph/Bar"
|
|
|
|
|
require "SVG/Graph/BarHorizontal"
|
2007-05-01 20:56:19 +00:00
|
|
|
require "digest/sha1"
|
2007-03-25 17:11:46 +00:00
|
|
|
|
2015-08-27 16:05:46 +02:00
|
|
|
class ChangesetNotFound < StandardError
|
2015-06-29 13:16:14 +02:00
|
|
|
end
|
2021-02-11 16:02:18 +01:00
|
|
|
|
2015-08-27 16:05:46 +02:00
|
|
|
class InvalidRevisionParam < StandardError
|
2015-06-29 13:16:14 +02:00
|
|
|
end
|
2007-12-01 17:15:42 +00:00
|
|
|
|
2006-12-24 13:38:45 +00:00
|
|
|
class RepositoriesController < ApplicationController
|
2013-06-19 16:04:56 +02:00
|
|
|
include PaginationHelper
|
2015-09-16 11:06:48 +02:00
|
|
|
include RepositoriesHelper
|
2013-06-19 16:04:56 +02:00
|
|
|
|
2008-01-19 11:53:43 +00:00
|
|
|
menu_item :repository
|
2021-02-11 16:02:18 +01:00
|
|
|
menu_item :settings, only: %i[edit destroy_info]
|
2009-10-21 17:07:18 +00:00
|
|
|
default_search_scope :changesets
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2016-09-06 15:40:49 +02:00
|
|
|
before_action :find_project_by_project_id
|
|
|
|
|
before_action :authorize
|
2024-01-09 13:58:27 +02:00
|
|
|
before_action :find_repository, except: %i[update create destroy destroy_info]
|
2007-08-29 16:52:35 +00:00
|
|
|
accept_key_auth :revisions
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2020-02-11 08:04:46 +01:00
|
|
|
rescue_from OpenProject::SCM::Exceptions::SCMError, with: :show_error_command_failed
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2023-03-09 10:25:57 +01:00
|
|
|
def show
|
|
|
|
|
if Setting.autofetch_changesets? && @path.blank?
|
|
|
|
|
@repository.fetch_changesets
|
|
|
|
|
@repository.update_required_storage
|
|
|
|
|
end
|
2018-03-02 16:34:36 +01:00
|
|
|
|
2023-03-09 10:25:57 +01:00
|
|
|
@limit = Setting.repository_truncate_at
|
|
|
|
|
@entries = @repository.entries(@path, @rev, limit: @limit)
|
|
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
|
|
|
|
|
|
|
|
|
if request.xhr?
|
|
|
|
|
if @entries && @repository.valid?
|
|
|
|
|
render(partial: "dir_list_content")
|
|
|
|
|
else
|
|
|
|
|
render(nothing: true)
|
|
|
|
|
end
|
|
|
|
|
elsif @entries.nil? && @repository.invalid?
|
|
|
|
|
show_error_not_found
|
|
|
|
|
else
|
|
|
|
|
@changesets = @repository.latest_changesets(@path, @rev)
|
|
|
|
|
@properties = @repository.properties(@path, @rev)
|
|
|
|
|
render action: "show"
|
|
|
|
|
end
|
2015-06-29 13:16:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2020-02-11 08:04:46 +01:00
|
|
|
service = SCM::RepositoryFactoryService.new(@project, params)
|
2015-07-16 08:36:14 +02:00
|
|
|
if service.build_and_save
|
2015-07-13 17:57:10 +02:00
|
|
|
@repository = service.repository
|
2020-09-16 11:26:15 +02:00
|
|
|
flash[:notice] = I18n.t("repositories.create_successful")
|
|
|
|
|
flash[:notice] << (" " + I18n.t("repositories.create_managed_delay")) if @repository.managed?
|
2015-07-13 17:57:10 +02:00
|
|
|
else
|
|
|
|
|
flash[:error] = service.build_error
|
2010-04-17 12:51:46 +00:00
|
|
|
end
|
2015-03-13 09:09:05 +01:00
|
|
|
|
2021-10-29 14:41:12 +02:00
|
|
|
redirect_to project_settings_repository_path(@project)
|
2007-09-14 11:34:08 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2023-03-09 10:25:57 +01:00
|
|
|
def update
|
|
|
|
|
@repository = @project.repository
|
|
|
|
|
update_repository(params.fetch(:repository, {}))
|
|
|
|
|
|
|
|
|
|
redirect_to project_settings_repository_path(@project)
|
|
|
|
|
end
|
|
|
|
|
|
2008-11-10 18:59:06 +00:00
|
|
|
def committers
|
|
|
|
|
@committers = @repository.committers
|
2016-02-24 10:37:19 +01:00
|
|
|
@users = @project.users.to_a
|
2014-11-04 11:06:05 +01:00
|
|
|
additional_user_ids = @committers.map(&:last).map(&:to_i) - @users.map(&:id)
|
2015-06-26 11:23:13 +02:00
|
|
|
@users += User.where(id: additional_user_ids) unless additional_user_ids.empty?
|
2008-11-10 18:59:06 +00:00
|
|
|
@users.compact!
|
|
|
|
|
@users.sort!
|
2016-09-12 11:06:04 +02:00
|
|
|
if request.post? && params.key?(:committers)
|
2008-12-15 18:02:25 +00:00
|
|
|
# Build a hash with repository usernames as keys and corresponding user ids as values
|
2015-11-24 22:47:45 +01:00
|
|
|
@repository.committer_ids = params[:committers].values
|
2021-02-11 16:02:18 +01:00
|
|
|
.inject({}) do |h, c|
|
2015-11-24 22:47:45 +01:00
|
|
|
h[c.first] = c.last
|
|
|
|
|
h
|
2021-02-11 16:02:18 +01:00
|
|
|
end
|
2020-09-16 11:26:15 +02:00
|
|
|
flash[:notice] = I18n.t(:notice_successful_update)
|
2014-11-03 21:10:20 +01:00
|
|
|
redirect_to action: "committers", project_id: @project
|
2008-11-10 18:59:06 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-02-12 09:44:46 +00:00
|
|
|
|
2015-07-16 08:36:14 +02:00
|
|
|
def destroy_info
|
|
|
|
|
@repository = @project.repository
|
2021-10-29 14:41:12 +02:00
|
|
|
project_settings_repository_path(@project)
|
2015-07-16 08:36:14 +02:00
|
|
|
end
|
|
|
|
|
|
2007-09-14 11:34:08 +00:00
|
|
|
def destroy
|
2015-08-28 12:01:47 +02:00
|
|
|
repository = @project.repository
|
|
|
|
|
if repository.destroy
|
|
|
|
|
flash[:notice] = I18n.t("repositories.delete_sucessful")
|
|
|
|
|
else
|
2015-09-02 15:04:10 +02:00
|
|
|
flash[:error] = repository.errors.full_messages
|
2015-08-28 12:01:47 +02:00
|
|
|
end
|
2025-07-24 16:02:40 +02:00
|
|
|
redirect_to project_settings_repository_path(@project),
|
|
|
|
|
status: :see_other
|
2007-09-14 11:34:08 +00:00
|
|
|
end
|
2011-02-12 09:44:46 +00:00
|
|
|
|
2009-08-15 22:41:40 +00:00
|
|
|
alias_method :browse, :show
|
2011-02-12 09:44:46 +00:00
|
|
|
|
2007-06-12 20:12:05 +00:00
|
|
|
def changes
|
2008-06-15 15:47:28 +00:00
|
|
|
@entry = @repository.entry(@path, @rev)
|
2015-11-24 22:47:45 +01:00
|
|
|
|
|
|
|
|
unless @entry
|
|
|
|
|
show_error_not_found
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@changesets = @repository.latest_changesets(@path,
|
|
|
|
|
@rev,
|
|
|
|
|
Setting.repository_log_display_limit.to_i)
|
2008-07-05 08:59:04 +00:00
|
|
|
@properties = @repository.properties(@path, @rev)
|
2015-11-24 22:47:45 +01:00
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
2016-09-12 11:06:04 +02:00
|
|
|
|
|
|
|
|
render "changes", formats: [:html]
|
2006-12-24 13:38:45 +00:00
|
|
|
end
|
2011-02-12 09:44:46 +00:00
|
|
|
|
2006-12-24 13:38:45 +00:00
|
|
|
def revisions
|
2015-06-29 13:16:14 +02:00
|
|
|
@changesets = @repository.changesets
|
|
|
|
|
.includes(:user, :repository)
|
2019-01-09 08:46:59 +01:00
|
|
|
.page(page_param)
|
2014-11-03 21:26:12 +01:00
|
|
|
.per_page(per_page_param)
|
2007-06-12 20:12:05 +00:00
|
|
|
|
2007-08-29 16:52:35 +00:00
|
|
|
respond_to do |format|
|
2015-11-24 22:47:45 +01:00
|
|
|
format.html do
|
|
|
|
|
render layout: false if request.xhr?
|
|
|
|
|
end
|
|
|
|
|
format.atom do
|
2020-09-16 11:26:15 +02:00
|
|
|
render_feed(@changesets, title: "#{@project.name}: #{I18n.t(:label_revision_plural)}")
|
2015-11-24 22:47:45 +01:00
|
|
|
end
|
2007-08-29 16:52:35 +00:00
|
|
|
end
|
2006-12-24 13:38:45 +00:00
|
|
|
end
|
2011-02-12 09:44:46 +00:00
|
|
|
|
2006-12-24 13:38:45 +00:00
|
|
|
def entry
|
2008-06-15 15:47:28 +00:00
|
|
|
@entry = @repository.entry(@path, @rev)
|
2015-11-24 22:47:45 +01:00
|
|
|
unless @entry
|
|
|
|
|
show_error_not_found
|
|
|
|
|
return
|
|
|
|
|
end
|
2009-12-18 14:22:18 +00:00
|
|
|
|
2008-04-27 10:12:15 +00:00
|
|
|
# If the entry is a dir, show the browser
|
2015-06-16 15:38:40 +02:00
|
|
|
if @entry.dir?
|
|
|
|
|
show
|
|
|
|
|
return
|
|
|
|
|
end
|
2009-12-18 14:22:18 +00:00
|
|
|
|
2008-06-15 15:47:28 +00:00
|
|
|
@content = @repository.cat(@path, @rev)
|
2015-11-24 22:47:45 +01:00
|
|
|
|
|
|
|
|
unless @content
|
|
|
|
|
show_error_not_found
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 20:29:52 +02:00
|
|
|
if raw_or_to_large_or_non_text(@content, @path)
|
|
|
|
|
send_raw(@content, @path)
|
2007-12-14 17:48:11 +00:00
|
|
|
else
|
2017-07-26 20:29:52 +02:00
|
|
|
render_text_entry
|
2011-03-22 15:31:17 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2007-12-02 20:58:02 +00:00
|
|
|
def annotate
|
2008-12-22 20:33:01 +00:00
|
|
|
@entry = @repository.entry(@path, @rev)
|
2011-02-12 09:44:46 +00:00
|
|
|
|
2015-11-24 22:47:45 +01:00
|
|
|
unless @entry
|
|
|
|
|
show_error_not_found
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@annotate = @repository.scm.annotate(@path, @rev)
|
2011-01-21 13:22:08 +00:00
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
2016-09-12 11:06:04 +02:00
|
|
|
|
|
|
|
|
render "annotate", formats: [:html]
|
2007-12-02 20:58:02 +00:00
|
|
|
end
|
2011-01-21 13:22:08 +00:00
|
|
|
|
2006-12-24 13:38:45 +00:00
|
|
|
def revision
|
2011-01-14 20:24:03 +00:00
|
|
|
raise ChangesetNotFound if @rev.blank?
|
2021-02-11 16:02:18 +01:00
|
|
|
|
2009-09-20 15:20:22 +00:00
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
2007-12-01 17:15:42 +00:00
|
|
|
raise ChangesetNotFound unless @changeset
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
2021-02-11 16:02:18 +01:00
|
|
|
format.js { render layout: false }
|
2007-12-01 17:15:42 +00:00
|
|
|
end
|
|
|
|
|
rescue ChangesetNotFound
|
2008-01-25 10:55:16 +00:00
|
|
|
show_error_not_found
|
2006-12-24 13:38:45 +00:00
|
|
|
end
|
2011-02-12 09:44:46 +00:00
|
|
|
|
2006-12-24 13:38:45 +00:00
|
|
|
def diff
|
2008-06-08 16:48:21 +00:00
|
|
|
if params[:format] == "diff"
|
2008-06-08 16:28:42 +00:00
|
|
|
@diff = @repository.diff(@path, @rev, @rev_to)
|
2015-11-24 22:47:45 +01:00
|
|
|
|
|
|
|
|
unless @diff
|
|
|
|
|
show_error_not_found
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2008-06-08 16:48:21 +00:00
|
|
|
filename = "changeset_r#{@rev}"
|
2026-01-26 11:34:42 +01:00
|
|
|
filename += "_r#{@rev_to}" if @rev_to
|
2015-06-29 13:16:14 +02:00
|
|
|
send_data @diff.join,
|
|
|
|
|
filename: "#{filename}.diff",
|
|
|
|
|
type: "text/x-patch",
|
|
|
|
|
disposition: "attachment"
|
2008-06-08 16:48:21 +00:00
|
|
|
else
|
2021-12-20 12:06:05 +01:00
|
|
|
@diff_type = diff_type_persisted
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2015-11-24 22:47:45 +01:00
|
|
|
@cache_key = "repositories/diff/#{@repository.id}/" +
|
|
|
|
|
Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
|
|
|
|
|
|
2008-06-08 16:48:21 +00:00
|
|
|
unless read_fragment(@cache_key)
|
|
|
|
|
@diff = @repository.diff(@path, @rev, @rev_to)
|
|
|
|
|
show_error_not_found unless @diff
|
|
|
|
|
end
|
2011-01-02 09:45:05 +00:00
|
|
|
|
|
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
|
|
|
|
@changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
|
2011-01-11 16:04:07 +00:00
|
|
|
@diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
|
2016-11-24 09:47:41 +01:00
|
|
|
|
|
|
|
|
render "diff", formats: :html
|
2007-05-01 20:56:19 +00:00
|
|
|
end
|
2006-12-24 13:38:45 +00:00
|
|
|
end
|
2011-01-11 16:04:07 +00:00
|
|
|
|
2011-02-12 09:44:46 +00:00
|
|
|
def stats
|
2025-07-08 14:38:27 +02:00
|
|
|
append_content_security_policy_directives object_src: %w('self') # rubocop:disable Lint/PercentStringArray
|
2018-09-24 13:27:10 +01:00
|
|
|
|
2023-10-23 11:23:42 +02:00
|
|
|
@show_commits_per_author = current_user.allowed_in_project?(:view_commit_author_statistics, @project)
|
2007-03-25 17:11:46 +00:00
|
|
|
end
|
2011-02-12 09:44:46 +00:00
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
def graph
|
2011-02-12 09:44:46 +00:00
|
|
|
data = nil
|
2007-03-25 17:11:46 +00:00
|
|
|
case params[:graph]
|
2014-11-03 21:26:12 +01:00
|
|
|
when "commits_per_month"
|
2007-03-25 17:11:46 +00:00
|
|
|
data = graph_commits_per_month(@repository)
|
2014-11-03 21:26:12 +01:00
|
|
|
when "commits_per_author"
|
2023-10-23 11:23:42 +02:00
|
|
|
unless current_user.allowed_in_project?(:view_commit_author_statistics, @project)
|
2013-09-05 14:59:15 +01:00
|
|
|
return deny_access
|
|
|
|
|
end
|
2021-02-11 16:02:18 +01:00
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
data = graph_commits_per_author(@repository)
|
|
|
|
|
end
|
2015-06-29 13:16:14 +02:00
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
if data
|
2014-11-03 21:26:12 +01:00
|
|
|
headers["Content-Type"] = "image/svg+xml"
|
|
|
|
|
send_data(data, type: "image/svg+xml", disposition: "inline")
|
2007-03-25 17:11:46 +00:00
|
|
|
else
|
|
|
|
|
render_404
|
|
|
|
|
end
|
|
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2010-12-18 18:37:49 +00:00
|
|
|
private
|
|
|
|
|
|
2010-12-20 18:47:54 +00:00
|
|
|
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
|
2010-12-18 18:37:49 +00:00
|
|
|
|
2015-06-29 13:16:14 +02:00
|
|
|
def update_repository(repo_params)
|
|
|
|
|
@repository.attributes = @repository.class.permitted_params(repo_params)
|
|
|
|
|
|
|
|
|
|
if @repository.save
|
2020-09-16 11:26:15 +02:00
|
|
|
flash[:notice] = I18n.t("repositories.update_settings_successful")
|
2015-06-29 13:16:14 +02:00
|
|
|
else
|
2018-03-05 07:40:01 +01:00
|
|
|
flash[:error] = @repository.errors.full_messages.join('\n')
|
2015-06-29 13:16:14 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2007-09-14 11:34:08 +00:00
|
|
|
def find_repository
|
2006-12-24 13:38:45 +00:00
|
|
|
@repository = @project.repository
|
2015-11-24 22:47:45 +01:00
|
|
|
|
|
|
|
|
unless @repository
|
|
|
|
|
render_404
|
|
|
|
|
return false
|
|
|
|
|
end
|
2015-07-13 17:57:10 +02:00
|
|
|
|
2015-08-19 09:08:26 +02:00
|
|
|
# Prepare checkout instructions
|
|
|
|
|
# available on all pages (even empty!)
|
2018-02-23 09:24:02 +01:00
|
|
|
@path = params[:repo_path] || ""
|
2020-02-11 08:04:46 +01:00
|
|
|
@instructions = ::SCM::CheckoutInstructionsService.new(@repository, path: @path)
|
2015-08-19 09:08:26 +02:00
|
|
|
|
|
|
|
|
# Asserts repository availability, or renders an appropriate error
|
2015-07-13 17:57:10 +02:00
|
|
|
@repository.scm.check_availability!
|
|
|
|
|
|
2012-08-07 12:04:59 +02:00
|
|
|
@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip
|
2008-04-03 16:50:53 +00:00
|
|
|
@rev_to = params[:rev_to]
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
if !@rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) && @repository.branches.blank?
|
|
|
|
|
raise InvalidRevisionParam
|
2010-12-18 18:37:49 +00:00
|
|
|
end
|
2020-02-11 08:04:46 +01:00
|
|
|
rescue OpenProject::SCM::Exceptions::SCMEmpty
|
2015-07-22 12:54:42 +02:00
|
|
|
render "empty"
|
2008-04-03 16:50:53 +00:00
|
|
|
rescue InvalidRevisionParam
|
|
|
|
|
show_error_not_found
|
2006-12-24 13:38:45 +00:00
|
|
|
end
|
|
|
|
|
|
2008-01-23 17:25:11 +00:00
|
|
|
def show_error_not_found
|
2020-09-16 11:26:15 +02:00
|
|
|
render_error message: I18n.t(:error_scm_not_found), status: 404
|
2008-01-23 17:25:11 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2008-06-15 16:11:07 +00:00
|
|
|
def show_error_command_failed(exception)
|
2020-09-16 11:26:15 +02:00
|
|
|
render_error I18n.t(:error_scm_command_failed, value: exception.message)
|
2006-12-24 13:38:45 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
def graph_commits_per_month(repository)
|
|
|
|
|
@date_to = Date.today
|
2007-08-15 23:04:14 +00:00
|
|
|
@date_from = @date_to << 11
|
|
|
|
|
@date_from = Date.civil(@date_from.year, @date_from.month, 1)
|
2015-11-24 22:47:45 +01:00
|
|
|
commits_by_day = Changeset.where(
|
|
|
|
|
["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]
|
|
|
|
|
).group(:commit_date).size
|
2007-03-25 17:11:46 +00:00
|
|
|
commits_by_month = [0] * 12
|
2015-11-24 22:47:45 +01:00
|
|
|
commits_by_day.each do |c|
|
|
|
|
|
commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last
|
|
|
|
|
end
|
2007-03-25 17:11:46 +00:00
|
|
|
|
2015-07-01 12:15:07 +02:00
|
|
|
changes_by_day = Change.includes(:changeset)
|
2022-06-27 12:07:37 +02:00
|
|
|
.where(["#{Changeset.table_name}.repository_id = ? " \
|
2015-11-24 22:47:45 +01:00
|
|
|
"AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?",
|
|
|
|
|
repository.id, @date_from, @date_to])
|
2015-07-07 18:48:26 +02:00
|
|
|
.references(:changesets)
|
|
|
|
|
.group(:commit_date)
|
|
|
|
|
.size
|
2007-03-25 17:11:46 +00:00
|
|
|
changes_by_month = [0] * 12
|
2015-11-24 22:47:45 +01:00
|
|
|
changes_by_day.each do |c|
|
|
|
|
|
changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last
|
|
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
fields = []
|
2015-11-24 22:47:45 +01:00
|
|
|
12.times do |m|
|
|
|
|
|
fields << month_name(((Date.today.month - 1 - m) % 12) + 1)
|
|
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
graph = SVG::Graph::Bar.new(
|
2014-11-03 21:10:20 +01:00
|
|
|
height: 300,
|
|
|
|
|
width: 800,
|
|
|
|
|
fields: fields.reverse,
|
|
|
|
|
stack: :side,
|
|
|
|
|
scale_integers: true,
|
|
|
|
|
step_x_labels: 2,
|
|
|
|
|
show_data_values: false,
|
2020-09-16 11:26:15 +02:00
|
|
|
graph_title: I18n.t(:label_commits_per_month),
|
2014-11-03 21:10:20 +01:00
|
|
|
show_graph_title: true
|
2007-03-25 17:11:46 +00:00
|
|
|
)
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
graph.add_data(
|
2014-11-03 21:10:20 +01:00
|
|
|
data: commits_by_month[0..11].reverse,
|
2020-09-16 11:26:15 +02:00
|
|
|
title: I18n.t(:label_revision_plural)
|
2007-03-25 17:11:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
graph.add_data(
|
2014-11-03 21:10:20 +01:00
|
|
|
data: changes_by_month[0..11].reverse,
|
2020-09-16 11:26:15 +02:00
|
|
|
title: I18n.t(:label_change_plural)
|
2007-03-25 17:11:46 +00:00
|
|
|
)
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
graph.burn
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def graph_commits_per_author(repository)
|
2014-11-03 21:26:12 +01:00
|
|
|
commits_by_author = Changeset.where(["repository_id = ?", repository.id]).group(:committer).size
|
2023-09-06 10:58:07 +02:00
|
|
|
commits_by_author.to_a.sort_by!(&:last)
|
2007-03-26 17:14:06 +00:00
|
|
|
|
2015-07-01 12:15:07 +02:00
|
|
|
changes_by_author = Change.includes(:changeset)
|
2015-07-07 18:48:26 +02:00
|
|
|
.where(["#{Changeset.table_name}.repository_id = ?", repository.id])
|
|
|
|
|
.references(:changesets)
|
|
|
|
|
.group(:committer)
|
|
|
|
|
.size
|
2021-02-11 16:02:18 +01:00
|
|
|
h = changes_by_author.inject({}) do |o, i|
|
2015-11-24 22:47:45 +01:00
|
|
|
o[i.first] = i.last
|
|
|
|
|
o
|
2021-02-11 16:02:18 +01:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2014-11-04 11:06:05 +01:00
|
|
|
fields = commits_by_author.map(&:first)
|
|
|
|
|
commits_data = commits_by_author.map(&:last)
|
|
|
|
|
changes_data = commits_by_author.map { |r| h[r.first] || 0 }
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2014-11-03 21:26:12 +01:00
|
|
|
fields = fields + ([""] * (10 - fields.length)) if fields.length < 10
|
|
|
|
|
commits_data = commits_data + ([0] * (10 - commits_data.length)) if commits_data.length < 10
|
|
|
|
|
changes_data = changes_data + ([0] * (10 - changes_data.length)) if changes_data.length < 10
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2021-01-22 09:14:21 -05:00
|
|
|
# Remove email address in usernames
|
2014-11-04 11:06:05 +01:00
|
|
|
fields = fields.map { |c| c.gsub(%r{<.+@.+>}, "") }
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2007-03-25 17:11:46 +00:00
|
|
|
graph = SVG::Graph::BarHorizontal.new(
|
2014-11-03 21:10:20 +01:00
|
|
|
height: 400,
|
|
|
|
|
width: 800,
|
|
|
|
|
fields:,
|
|
|
|
|
stack: :side,
|
|
|
|
|
scale_integers: true,
|
|
|
|
|
show_data_values: false,
|
|
|
|
|
rotate_y_labels: false,
|
2020-09-16 11:26:15 +02:00
|
|
|
graph_title: I18n.t(:label_commits_per_author),
|
2014-11-03 21:10:20 +01:00
|
|
|
show_graph_title: true
|
2007-03-25 17:11:46 +00:00
|
|
|
)
|
|
|
|
|
graph.add_data(
|
2014-11-03 21:10:20 +01:00
|
|
|
data: commits_data,
|
2020-09-16 11:26:15 +02:00
|
|
|
title: I18n.t(:label_revision_plural)
|
2007-03-25 17:11:46 +00:00
|
|
|
)
|
2007-03-26 17:14:06 +00:00
|
|
|
graph.add_data(
|
2014-11-03 21:10:20 +01:00
|
|
|
data: changes_data,
|
2020-09-16 11:26:15 +02:00
|
|
|
title: I18n.t(:label_change_plural)
|
2007-03-26 17:14:06 +00:00
|
|
|
)
|
2007-03-25 17:11:46 +00:00
|
|
|
graph.burn
|
|
|
|
|
end
|
2017-06-19 12:55:28 +02:00
|
|
|
|
|
|
|
|
def login_back_url_params
|
2018-02-26 15:53:26 +01:00
|
|
|
params.permit(:repo_path)
|
2017-06-19 12:55:28 +02:00
|
|
|
end
|
2017-07-26 20:29:52 +02:00
|
|
|
|
|
|
|
|
def raw_or_to_large_or_non_text(content, path)
|
|
|
|
|
params[:format] == "raw" ||
|
|
|
|
|
(content.size && content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
|
2021-12-20 12:11:47 +01:00
|
|
|
!entry_text_data?(content, path)
|
2017-07-26 20:29:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def send_raw(content, path)
|
2026-03-13 14:44:56 +01:00
|
|
|
# Force the download as binary to prevent CSP bypass
|
|
|
|
|
send_data content,
|
|
|
|
|
filename: filename_for_content_disposition(path.split("/").last),
|
|
|
|
|
type: "application/octet-stream",
|
|
|
|
|
disposition: :attachment
|
2017-07-26 20:29:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def render_text_entry
|
|
|
|
|
# Prevent empty lines when displaying a file with Windows style eol
|
|
|
|
|
# TODO: UTF-16
|
|
|
|
|
# Is this needs? AttachmentsController reads file simply.
|
|
|
|
|
@content.gsub!("\r\n", "\n")
|
|
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
|
|
|
|
|
|
|
|
|
# Forcing html format here to avoid
|
|
|
|
|
# rails looking for e.g text when .txt is asked for
|
|
|
|
|
render "entry", formats: [:html]
|
|
|
|
|
end
|
2021-12-20 12:06:05 +01:00
|
|
|
|
|
|
|
|
def diff_type_persisted
|
|
|
|
|
preferences = current_user.pref
|
|
|
|
|
|
|
|
|
|
diff_type = params[:type] || preferences.diff_type
|
|
|
|
|
diff_type = "inline" unless %w(inline sbs).include?(diff_type)
|
|
|
|
|
|
|
|
|
|
# Save diff type as user preference
|
|
|
|
|
if current_user.logged? && diff_type != preferences.diff_type
|
|
|
|
|
preferences.diff_type = diff_type
|
|
|
|
|
preferences.save
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
diff_type
|
|
|
|
|
end
|
2021-12-20 12:11:47 +01:00
|
|
|
|
|
|
|
|
def entry_text_data?(ent, path)
|
|
|
|
|
# UTF-16 contains "\x00".
|
|
|
|
|
# It is very strict that file contains less than 30% of ascii symbols
|
|
|
|
|
# in non Western Europe.
|
|
|
|
|
# TODO: need to handle edge cases of non-binary content that isn't UTF-8
|
|
|
|
|
OpenProject::MimeType.is_type?("text", path) ||
|
|
|
|
|
ent.dup.force_encoding("UTF-8") == ent.dup.force_encoding("BINARY")
|
|
|
|
|
end
|
2006-12-24 13:38:45 +00:00
|
|
|
end
|