Defect #29838 » 0001-fix-logging-time-via-a-commit-message-for-project-sp.patch
| app/models/changeset.rb | ||
|---|---|---|
|
: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
|
||
| ... | ... | |
|
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
|
||
| app/models/project.rb | ||
|---|---|---|
|
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
|
||
|
.where('id = ? OR parent_id = ?', activity_id, activity_id)
|
||
|
.first
|
||
|
end
|
||
|
end
|
||
|
# Returns a :conditions SQL string that can be used to find the issues associated with this project.
|
||
|
#
|
||
|
# Examples:
|
||
| test/unit/changeset_test.rb | ||
|---|---|---|
|
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,
|
||
| ... | ... | |
|
"@#{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}"
|
||