doneratio.patch

Set issue done ratio from commit message as proposed in initial feature request. - Felix Tiede, 2013-11-26 19:58

Download (6.23 KB)

View differences:

app/models/changeset.rb 2013-11-26 19:45:20.000000000 +0100
111 111
    (\d+([\.,]\d+)?)h?
112 112
    )
113 113
    /x
114
  DONERATIO_RE = /
115
    (
116
    (100)
117
    |
118
    (\d?0)
119
    )
120
    /x
114 121

  
115 122
  def scan_comment_for_issue_ids
116 123
    return if comments.blank?
......
124 131

  
125 132
    referenced_issues = []
126 133

  
127
    comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
134
    comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?(\s+#{DONERATIO_RE}%)?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?(\s+#{DONERATIO_RE}%)?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
128 135
      action, refs = match[2], match[3]
129 136
      next unless action.present? || ref_keywords_any
130 137

  
131
      refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
132
        issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
138
      refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?(\s+#{DONERATIO_RE}%)?/).each do |m|
139
        issue, hours, ratio = find_referenced_issue_by_id(m[0].to_i), m[2], m[17]
133 140
        if issue
134 141
          referenced_issues << issue
142
          done_ratio(issue, ratio) if ratio && Setting.commit_doneratio_enabled? && !fix_keywords.include?(action.to_s.downcase)
135 143
          fix_issue(issue) if fix_keywords.include?(action.to_s.downcase)
136 144
          log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
137 145
        end
......
258 266
    end
259 267
  end
260 268

  
269
  def done_ratio(issue, ratio)
270
    status = IssueStatus.find_by_id(Setting.commit_doneratio_inprogress_id.to_i)
271
    if status.nil?
272
      logger.warn("No status matches commit_doneratio_inprogress_id setting (#{Setting.commit_doneratio_inprogress_id})") if logger
273
    end
274

  
275
    issue.reload
276
    journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, text_tag(issue.project)))
277
    issue.done_ratio = ratio.to_i
278
	issue.status = status if status
279
    unless issue.save
280
      logger.warn("Issue ##{issue.id} could not be saved by changeset #{id}: #{issue.errors.full_messages}") if logger
281
    end
282
    issue
283
  end
284

  
261 285
  def split_comments
262 286
    comments =~ /\A(.+?)\r?\n(.*)$/m
263 287
    @short_comments = $1 || comments
app/views/settings/_repositories.html.erb 2013-11-26 19:22:21.000000000 +0100
80 80

  
81 81
<p><%= setting_check_box :commit_cross_project_ref %></p>
82 82

  
83
<p><%= setting_check_box :commit_doneratio_enabled,
84
                         :onclick =>
85
                            "if (this.checked) { $('#settings_commit_doneratio_inprogess_id').removeAttr('disabled'); } else { $('#settings_commit_doneratio_inprogress_id').attr('disabled', true); }"%></p>
86

  
87
<p><%= setting_select :commit_doneratio_inprogress_id,
88
                      [[l(:label_default), 2]] +
89
                          IssueStatus.sorted.all.collect{|status| [status.name, status.id.to_s]},
90
                      :disabled => !Setting.commit_doneratio_enabled?%></p>
91

  
83 92
<p><%= setting_check_box :commit_logtime_enabled,
84 93
                         :onclick =>
85 94
                            "if (this.checked) { $('#settings_commit_logtime_activity_id').removeAttr('disabled'); } else { $('#settings_commit_logtime_activity_id').attr('disabled', true); }"%></p>
config/locales/de.yml 2013-11-26 19:04:27.000000000 +0100
949 949
  setting_bcc_recipients: E-Mails als Blindkopie (BCC) senden
950 950
  setting_cache_formatted_text: Formatierten Text im Cache speichern
951 951
  setting_commit_cross_project_ref: Erlauben auf Tickets aller anderen Projekte zu referenzieren
952
  setting_commit_doneratio_enabled: Aktiviere Fertigstellung
953
  setting_commit_doneratio_inprogress_id: Bearbeitungsstatus für erledigt
952 954
  setting_commit_fix_keywords: Schlüsselwörter (Status)
953 955
  setting_commit_logtime_activity_id: Aktivität für die Zeiterfassung
954 956
  setting_commit_logtime_enabled: Aktiviere Zeitlogging
config/locales/en-GB.yml 2013-11-26 19:02:02.000000000 +0100
366 366
  setting_rest_api_enabled: Enable REST web service
367 367
  setting_cache_formatted_text: Cache formatted text
368 368
  setting_default_notification_option: Default notification option
369
  setting_commit_doneratio_enabled: Enable done ratio logging
370
  setting_commit_doneratio_inprogress_id: Progressing status for done ratio
369 371
  setting_commit_logtime_enabled: Enable time logging
370 372
  setting_commit_logtime_activity_id: Activity for logged time
371 373
  setting_gantt_items_limit: Maximum number of items displayed on the gantt chart
config/locales/en.yml 2013-11-26 19:01:50.000000000 +0100
387 387
  setting_rest_api_enabled: Enable REST web service
388 388
  setting_cache_formatted_text: Cache formatted text
389 389
  setting_default_notification_option: Default notification option
390
  setting_commit_doneratio_enabled: Enable done ratio logging
391
  setting_commit_doneratio_inprogress_id: Progressing status for done ratio
390 392
  setting_commit_logtime_enabled: Enable time logging
391 393
  setting_commit_logtime_activity_id: Activity for logged time
392 394
  setting_gantt_items_limit: Maximum number of items displayed on the gantt chart
config/settings.yml 2013-11-26 19:14:48.000000000 +0100
113 113
  default: 0
114 114
commit_fix_done_ratio:
115 115
  default: 100
116
commit_doneratio_enabled:
117
  default: 0
118
commit_doneratio_inprogress_id:
119
  format: int
120
  default: 2
116 121
commit_logtime_enabled:
117 122
  default: 0
118 123
commit_logtime_activity_id: