Project

General

Profile

Patch #7445 » commit-update-1.0.4.patch

Brian Lindahl, 2011-01-25 19:55

View differences:

redmine-1.0.4-commit-update/app/models/changeset.rb 2011-01-21 16:31:45.922686700 -0700
81 81
    return if comments.blank?
82 82
    # keywords used to reference issues
83 83
    ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip)
84
    # keywords used to fix issues
85
    fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip)
86
    
87
    kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
84
	
85
    # keywords used to update issues
86
    keywords1 = Setting.commit_update1_keywords.downcase.split(",").collect(&:strip)
87
    keywords2 = Setting.commit_update2_keywords.downcase.split(",").collect(&:strip)
88
    keywords3 = Setting.commit_update3_keywords.downcase.split(",").collect(&:strip)
89
    keywords4 = Setting.commit_update4_keywords.downcase.split(",").collect(&:strip)
90
    keywords5 = Setting.commit_update5_keywords.downcase.split(",").collect(&:strip)
91

  
92
    kw_regexp = (ref_keywords + keywords1 + keywords2 + keywords3 + keywords4 + keywords5).collect{|kw| Regexp.escape(kw)}.join("|")
88 93
    return if kw_regexp.blank?
89
    
94

  
90 95
    referenced_issues = []
91 96
    
92 97
    if ref_keywords.delete('*')
......
95 100
      comments.scan(%r{([\s\(\[,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] }
96 101
      referenced_issues += find_referenced_issues_by_id(target_issue_ids)
97 102
    end
98
    
103
	
99 104
    comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match|
100 105
      action = match[0]
101 106
      target_issue_ids = match[1].scan(/\d+/)
102 107
      target_issues = find_referenced_issues_by_id(target_issue_ids)
103
      if fix_keywords.include?(action.downcase) && fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id)
104
        # update status of issues
105
        logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug?
106
        target_issues.each do |issue|
107
          # the issue may have been updated by the closure of another one (eg. duplicate)
108
          issue.reload
109
          # don't change the status is the issue is closed
110
          next if issue.status.is_closed?
111
          csettext = "r#{self.revision}"
112
          if self.scmid && (! (csettext =~ /^r[0-9]+$/))
113
            csettext = "commit:\"#{self.scmid}\""
114
          end
115
          journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, csettext))
116
          issue.status = fix_status
117
          unless Setting.commit_fix_done_ratio.blank?
118
            issue.done_ratio = Setting.commit_fix_done_ratio.to_i
119
          end
120
          Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,
121
                                  { :changeset => self, :issue => issue })
122
          issue.save
123
        end
124
      end
108

  
109
      update_issue_id(action, target_issues, target_issue_ids, keywords1, 
110
                      Setting.commit_update1_status_id, Setting.commit_update1_done_ratio)
111
      update_issue_id(action, target_issues, target_issue_ids, keywords2, 
112
                      Setting.commit_update2_status_id, Setting.commit_update2_done_ratio)
113
      update_issue_id(action, target_issues, target_issue_ids, keywords3, 
114
                      Setting.commit_update3_status_id, Setting.commit_update3_done_ratio)
115
      update_issue_id(action, target_issues, target_issue_ids, keywords4, 
116
                      Setting.commit_update4_status_id, Setting.commit_update4_done_ratio)
117
      update_issue_id(action, target_issues, target_issue_ids, keywords5, 
118
                      Setting.commit_update5_status_id, Setting.commit_update5_done_ratio)
119
	  
125 120
      referenced_issues += target_issues
126 121
    end
127
    
122
	
128 123
    referenced_issues.uniq!
129 124
    self.issues = referenced_issues unless referenced_issues.empty?
125
  end 
126
	
127
  def update_issue_id(action, issues, issue_ids, keywords, status_id, done_ratio)
128
    if keywords.include?(action.downcase) && new_status = IssueStatus.find_by_id(status_id)
129
      # update status of issues
130
      logger.debug "Issues #{new_status.downcase} by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug?
131
      issues.each do |issue|
132
        # the issue may have been updated by the closure of another one (eg. duplicate)
133
        issue.reload
134
        # don't change the status if the issue is closed
135
        next if issue.status.is_closed?
136
        csettext = "r#{self.revision}"
137
        if self.scmid && (! (csettext =~ /^r[0-9]+$/))
138
          csettext = "commit:\"#{self.scmid}\""
139
        end
140
        journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, csettext))
141
        issue.status = new_status
142
        unless done_ratio.blank?
143
          issue.done_ratio = done_ratio.to_i
144
        end
145
        Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,
146
                                { :changeset => self, :issue => issue })
147
        issue.save
148
      end
149
    end
130 150
  end
131 151
  
132 152
  def short_comments
redmine-1.0.4-commit-update/app/views/settings/_repositories.rhtml 2011-01-21 16:31:45.938311700 -0700
27 27
<p><%= setting_text_field :commit_ref_keywords, :size => 30 %><br />
28 28
<em><%= l(:text_comma_separated) %></em></p>
29 29

  
30
<p><%= setting_text_field :commit_fix_keywords, :size => 30 %>
31
&nbsp;<%= l(:label_applied_status) %>: <%= setting_select :commit_fix_status_id, [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, :label => false %>
32
&nbsp;<%= l(:field_done_ratio) %>: <%= setting_select :commit_fix_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, :blank => :label_no_change_option, :label => false %>
30
<p><%= setting_text_field :commit_update1_keywords, :size => 30 %>
31
&nbsp;<%= l(:label_applied_status) %>: <%= setting_select :commit_update1_status_id, [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, :label => false %>
32
&nbsp;<%= l(:field_done_ratio) %>: <%= setting_select :commit_update1_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, :blank => :label_no_change_option, :label => false %>
33 33
<br /><em><%= l(:text_comma_separated) %></em></p>
34

  
35
<p><%= setting_text_field :commit_update2_keywords, :size => 30 %>
36
&nbsp;<%= l(:label_applied_status) %>: <%= setting_select :commit_update2_status_id, [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, :label => false %>
37
&nbsp;<%= l(:field_done_ratio) %>: <%= setting_select :commit_update2_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, :blank => :label_no_change_option, :label => false %>
38
<br /><em><%= l(:text_comma_separated) %></em></p>
39

  
40
<p><%= setting_text_field :commit_update3_keywords, :size => 30 %>
41
&nbsp;<%= l(:label_applied_status) %>: <%= setting_select :commit_update3_status_id, [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, :label => false %>
42
&nbsp;<%= l(:field_done_ratio) %>: <%= setting_select :commit_update3_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, :blank => :label_no_change_option, :label => false %>
43
<br /><em><%= l(:text_comma_separated) %></em></p>
44

  
45
<p><%= setting_text_field :commit_update4_keywords, :size => 30 %>
46
&nbsp;<%= l(:label_applied_status) %>: <%= setting_select :commit_update4_status_id, [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, :label => false %>
47
&nbsp;<%= l(:field_done_ratio) %>: <%= setting_select :commit_update4_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, :blank => :label_no_change_option, :label => false %>
48
<br /><em><%= l(:text_comma_separated) %></em></p>
49

  
50
<p><%= setting_text_field :commit_update5_keywords, :size => 30 %>
51
&nbsp;<%= l(:label_applied_status) %>: <%= setting_select :commit_update5_status_id, [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, :label => false %>
52
&nbsp;<%= l(:field_done_ratio) %>: <%= setting_select :commit_update5_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, :blank => :label_no_change_option, :label => false %>
53
<br /><em><%= l(:text_comma_separated) %></em></p>
54

  
34 55
</fieldset>
35 56

  
36 57
<%= submit_tag l(:button_save) %>
redmine-1.0.4-commit-update/config/locales/en.yml 2011-01-21 16:31:45.953936700 -0700
316 316
  setting_autofetch_changesets: Autofetch commits
317 317
  setting_sys_api_enabled: Enable WS for repository management
318 318
  setting_commit_ref_keywords: Referencing keywords
319
  setting_commit_fix_keywords: Fixing keywords
319
  setting_commit_update1_keywords: Keywords
320
  setting_commit_update2_keywords: Keywords
321
  setting_commit_update3_keywords: Keywords
322
  setting_commit_update4_keywords: Keywords
323
  setting_commit_update5_keywords: Keywords
320 324
  setting_autologin: Autologin
321 325
  setting_date_format: Date format
322 326
  setting_time_format: Time format
......
857 861
  text_unallowed_characters: Unallowed characters
858 862
  text_comma_separated: Multiple values allowed (comma separated).
859 863
  text_line_separated: Multiple values allowed (one line for each value).
860
  text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages
864
  text_issues_ref_in_commit_messages: Referencing and updating issues in commit messages
861 865
  text_issue_added: "Issue {{id}} has been reported by {{author}}."
862 866
  text_issue_updated: "Issue {{id}} has been updated by {{author}}."
863 867
  text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
redmine-1.0.4-commit-update/config/settings.yml 2011-01-21 16:31:45.969561700 -0700
89 89
  default: 0
90 90
sys_api_key:
91 91
  default: ''
92
# commit actions
92 93
commit_ref_keywords:
93 94
  default: 'refs,references,IssueID'
94
commit_fix_keywords:
95
# commit update 1
96
commit_update1_keywords:
95 97
  default: 'fixes,closes'
96
commit_fix_status_id:
98
commit_update1_status_id:
97 99
  format: int
98 100
  default: 0
99
commit_fix_done_ratio:
101
commit_update1_done_ratio:
102
  default: 100
103
# commit update 2
104
commit_update2_keywords:
105
  default: ''
106
commit_update2_status_id:
107
  format: int
108
  default: 0
109
commit_update2_done_ratio:
110
  default: 100
111
# commit update 3
112
commit_update3_keywords:
113
  default: ''
114
commit_update3_status_id:
115
  format: int
116
  default: 0
117
commit_update3_done_ratio:
118
  default: 100
119
# commitupdate 4
120
commit_update4_keywords:
121
  default: ''
122
commit_update4_status_id:
123
  format: int
124
  default: 0
125
commit_update4_done_ratio:
126
  default: 100
127
# commit update 5
128
commit_update5_keywords:
129
  default: ''
130
commit_update5_status_id:
131
  format: int
132
  default: 0
133
commit_update5_done_ratio:
100 134
  default: 100
101 135
# autologin duration in days
102 136
# 0 means autologin is disabled
103 137

  
(1-1/4)