Defect #29838 » 0001-fix-logging-time-via-a-commit-message-for-project-sp.patch
| app/models/changeset.rb | ||
|---|---|---|
| 259 | 259 |
:comments => l(:text_time_logged_by_changeset, :value => text_tag(issue.project), |
| 260 | 260 |
:locale => Setting.default_language) |
| 261 | 261 |
) |
| 262 |
time_entry.activity = log_time_activity unless log_time_activity.nil? |
|
| 262 |
if activity = issue.project.commit_logtime_activity |
|
| 263 |
time_entry.activity = activity |
|
| 264 |
end |
|
| 263 | 265 | |
| 264 | 266 |
unless time_entry.save |
| 265 | 267 |
logger.warn("TimeEntry could not be created by changeset #{id}: #{time_entry.errors.full_messages}") if logger
|
| ... | ... | |
| 267 | 269 |
time_entry |
| 268 | 270 |
end |
| 269 | 271 | |
| 270 |
def log_time_activity |
|
| 271 |
if Setting.commit_logtime_activity_id.to_i > 0 |
|
| 272 |
TimeEntryActivity.find_by_id(Setting.commit_logtime_activity_id.to_i) |
|
| 273 |
end |
|
| 274 |
end |
|
| 275 | ||
| 276 | 272 |
def split_comments |
| 277 | 273 |
comments =~ /\A(.+?)\r?\n(.*)$/m |
| 278 | 274 |
@short_comments = $1 || comments |
| app/models/project.rb | ||
|---|---|---|
| 295 | 295 |
end |
| 296 | 296 |
end |
| 297 | 297 | |
| 298 |
# returns the time log activity to be used when logging time via a changeset |
|
| 299 |
def commit_logtime_activity |
|
| 300 |
activity_id = Setting.commit_logtime_activity_id.to_i |
|
| 301 |
if activity_id > 0 |
|
| 302 |
activities |
|
| 303 |
.where('id = ? OR parent_id = ?', activity_id, activity_id)
|
|
| 304 |
.first |
|
| 305 |
end |
|
| 306 |
end |
|
| 307 | ||
| 298 | 308 |
# Returns a :conditions SQL string that can be used to find the issues associated with this project. |
| 299 | 309 |
# |
| 300 | 310 |
# Examples: |
| test/unit/changeset_test.rb | ||
|---|---|---|
| 75 | 75 |
assert_equal [1, 2], c.issue_ids.sort |
| 76 | 76 |
end |
| 77 | 77 | |
| 78 |
def test_project_specific_activity |
|
| 79 |
project = Project.find 1 |
|
| 80 |
activity = TimeEntryActivity.find 9 |
|
| 81 | ||
| 82 |
Setting.commit_ref_keywords = '*' |
|
| 83 |
Setting.commit_logtime_enabled = '1' |
|
| 84 |
Setting.commit_logtime_activity_id = activity.id |
|
| 85 | ||
| 86 |
project_specific_activity = TimeEntryActivity.create!( |
|
| 87 |
name: activity.name, |
|
| 88 |
parent_id: activity.id, |
|
| 89 |
position: activity.position, |
|
| 90 |
project_id: project.id |
|
| 91 |
) |
|
| 92 | ||
| 93 |
c = Changeset.new(:repository => project.repository, |
|
| 94 |
:committed_on => 24.hours.ago, |
|
| 95 |
:comments => "Worked on this issue #1 @8h", |
|
| 96 |
:revision => '520', |
|
| 97 |
:user => User.find(2)) |
|
| 98 |
assert_difference 'TimeEntry.count' do |
|
| 99 |
c.scan_comment_for_issue_ids |
|
| 100 |
end |
|
| 101 | ||
| 102 |
time = TimeEntry.order('id desc').first
|
|
| 103 |
assert_equal project_specific_activity, time.activity |
|
| 104 |
end |
|
| 105 | ||
| 78 | 106 |
def test_ref_keywords_any_with_timelog |
| 79 | 107 |
Setting.commit_ref_keywords = '*' |
| 80 | 108 |
Setting.commit_logtime_enabled = '1' |
| 109 |
Setting.commit_logtime_activity_id = 9 |
|
| 81 | 110 | |
| 82 | 111 |
{
|
| 83 | 112 |
'2' => 2.0, |
| ... | ... | |
| 113 | 142 |
"@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
|
| 114 | 143 |
) |
| 115 | 144 |
assert_equal Date.yesterday, time.spent_on |
| 116 |
assert time.activity.is_default?
|
|
| 145 |
assert_equal 9, time.activity_id
|
|
| 117 | 146 |
assert( |
| 118 | 147 |
time.comments.include?('r520'),
|
| 119 | 148 |
"r520 was expected in time_entry comments: #{time.comments}"
|