Project

General

Profile

Feature #11152 » patch_time_log_comment.diff

Jonathan Rajotte, 2012-07-12 19:33

View differences:

app/models/changeset.rb (working copy)
# Redmine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang
#
......
TIMELOG_RE = /
(
((\d+)(h|hours?))((\d+)(m|min)?)?
((\d+)(h|hours?))((\d+)(min|m)?)?
|
((\d+)(h|hours?|m|min))
((\d+)(h|hours?|min|m))
|
(\d+):(\d+)
|
......
kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
referenced_issues = []
comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+((\s+@#{TIMELOG_RE})?(\s+&(.*?)&)?)([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?(\s+&(.*?)&)?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
action, refs = match[2], match[3]
next unless action.present? || ref_keywords_any
refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
if issue
action, refs = match[2], match[3]
next unless action.present? || ref_keywords_any
refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})(\s+&(.*?)&)?/).each do |m|
issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
log_comment = m[17]
if issue
referenced_issues << issue
fix_issue(issue) if fix_keywords.include?(action.to_s.downcase)
log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
log_time(issue, hours, log_comment) if hours && Setting.commit_logtime_enabled?
end
end
end
......
issue
end
def log_time(issue, hours)
time_entry = TimeEntry.new(
def log_time(issue, hours, comment)
if comment.nil?
comment=l(:text_time_logged_by_changeset, :value => text_tag(issue.project),:locale => Setting.default_language)
else
comment+= " [" + text_tag(issue.project) +"]"
end
time_entry = TimeEntry.new(
:user => user,
:hours => hours,
:issue => issue,
:spent_on => commit_date,
:comments => l(:text_time_logged_by_changeset, :value => text_tag(issue.project),
:locale => Setting.default_language)
)
:comments => comment
)
time_entry.activity = log_time_activity unless log_time_activity.nil?
unless time_entry.save
(3-3/5)