OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/app/models/activity/changeset_activity_provider.rb

108 lines
3.5 KiB

#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# 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.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
class Activity::ChangesetActivityProvider < Activity::BaseActivityProvider
acts_as_activity_provider type: 'changesets',
permission: :view_changesets
def extend_event_query(query)
query.join(repositories_table).on(activity_journals_table[:repository_id].eq(repositories_table[:id]))
end
def event_query_projection
[
activity_journal_projection_statement(:revision, 'revision'),
activity_journal_projection_statement(:comments, 'comments'),
activity_journal_projection_statement(:committed_on, 'committed_on'),
projection_statement(repositories_table, :project_id, 'project_id'),
projection_statement(repositories_table, :type, 'repository_type')
]
end
def projects_reference_table
repositories_table
end
protected
def event_title(event)
ren = self.format_revision(event)
shomment = self.split_comment(event['comments']).first
ti "#{l(:label_revision)} #{revision}"
ti< (short_comment.blank? ? '' : (': ' + short_comment))
end
def event_description(event)
split_comment(event_data['comments']).last
end
def event_datetime(event)
committed_on = event_data['committed_on']
committed_date = committed_on.is_a?(String) ? DateTime.parse(committed_on)
: committed_on
end
def event_path(event)
Rails.application.routes.url_helpers.revisions_project_repository_path(url_helper_parameter(event))
end
def event_url(event)
Rails.application.routes.url_helpers.revisions_project_repository_url(url_helper_parameter(event),
host: ::Setting.host_name)
end
private
def repositories_table
@repositories_table ||= Arel::Table.new(:repositories)
end
def format_revision(event)
reory_class = event['repository_type'].constantize
reory_class.respond_to?(:format_revision) ? repository_class.format_revision(event['revision'])
: event['revision']
end
def split_comment(comments)
cos =~ /\A(.+?)\r?\n(.*)\z/m
shomments = $1 || comments
lomments = $2.to_s.strip
[scomments, long_comments]
end
def url_helper_parameter(event)
{ project_id: event['project_id'], rev: event['revision'] }
end
end