1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-04 08:03:23 +00:00

Fix logging time via a commit message for project specific activities (#29838).

Patch by Jens Krämer.


git-svn-id: http://svn.redmine.org/redmine/trunk@19512 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA 2020-02-11 13:33:22 +00:00
parent 39c979b341
commit 777704249f
3 changed files with 42 additions and 8 deletions

View File

@ -259,7 +259,9 @@ class Changeset < ActiveRecord::Base
:comments => l(:text_time_logged_by_changeset, :value => text_tag(issue.project),
:locale => Setting.default_language)
)
time_entry.activity = log_time_activity unless log_time_activity.nil?
if activity = issue.project.commit_logtime_activity
time_entry.activity = activity
end
unless time_entry.save
logger.warn("TimeEntry could not be created by changeset #{id}: #{time_entry.errors.full_messages}") if logger
@ -267,12 +269,6 @@ class Changeset < ActiveRecord::Base
time_entry
end
def log_time_activity
if Setting.commit_logtime_activity_id.to_i > 0
TimeEntryActivity.find_by_id(Setting.commit_logtime_activity_id.to_i)
end
end
def split_comments
comments =~ /\A(.+?)\r?\n(.*)$/m
@short_comments = $1 || comments

View File

@ -295,6 +295,15 @@ class Project < ActiveRecord::Base
end
end
# returns the time log activity to be used when logging time via a changeset
def commit_logtime_activity
activity_id = Setting.commit_logtime_activity_id.to_i
if activity_id > 0
activities
.find_by('id = ? OR parent_id = ?', activity_id, activity_id)
end
end
# Returns a :conditions SQL string that can be used to find the issues associated with this project.
#
# Examples:

View File

@ -75,9 +75,38 @@ class ChangesetTest < ActiveSupport::TestCase
assert_equal [1, 2], c.issue_ids.sort
end
def test_project_specific_activity
project = Project.find 1
activity = TimeEntryActivity.find 9
Setting.commit_ref_keywords = '*'
Setting.commit_logtime_enabled = '1'
Setting.commit_logtime_activity_id = activity.id
project_specific_activity = TimeEntryActivity.create!(
name: activity.name,
parent_id: activity.id,
position: activity.position,
project_id: project.id
)
c = Changeset.new(:repository => project.repository,
:committed_on => 24.hours.ago,
:comments => "Worked on this issue #1 @8h",
:revision => '520',
:user => User.find(2))
assert_difference 'TimeEntry.count' do
c.scan_comment_for_issue_ids
end
time = TimeEntry.order('id desc').first
assert_equal project_specific_activity, time.activity
end
def test_ref_keywords_any_with_timelog
Setting.commit_ref_keywords = '*'
Setting.commit_logtime_enabled = '1'
Setting.commit_logtime_activity_id = 9
{
'2' => 2.0,
@ -113,7 +142,7 @@ class ChangesetTest < ActiveSupport::TestCase
"@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
)
assert_equal Date.yesterday, time.spent_on
assert time.activity.is_default?
assert_equal 9, time.activity_id
assert(
time.comments.include?('r520'),
"r520 was expected in time_entry comments: #{time.comments}"