@@ -84,9 +84,6 class Changeset < ActiveRecord::Base | |||||
84 | ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip) |
|
84 | ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip) | |
85 | # keywords used to fix issues |
|
85 | # keywords used to fix issues | |
86 | fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip) |
|
86 | fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip) | |
87 | # status and optional done ratio applied |
|
|||
88 | fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id) |
|
|||
89 | done_ratio = Setting.commit_fix_done_ratio.blank? ? nil : Setting.commit_fix_done_ratio.to_i |
|
|||
90 |
|
87 | |||
91 | kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|") |
|
88 | kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|") | |
92 | return if kw_regexp.blank? |
|
89 | return if kw_regexp.blank? | |
@@ -104,7 +101,7 class Changeset < ActiveRecord::Base | |||||
104 | action = match[0] |
|
101 | action = match[0] | |
105 | target_issue_ids = match[1].scan(/\d+/) |
|
102 | target_issue_ids = match[1].scan(/\d+/) | |
106 | target_issues = find_referenced_issues_by_id(target_issue_ids) |
|
103 | target_issues = find_referenced_issues_by_id(target_issue_ids) | |
107 | if fix_status && fix_keywords.include?(action.downcase) |
|
104 | if fix_keywords.include?(action.downcase) && fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id) | |
108 | # update status of issues |
|
105 | # update status of issues | |
109 | logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug? |
|
106 | logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug? | |
110 | target_issues.each do |issue| |
|
107 | target_issues.each do |issue| | |
@@ -118,7 +115,9 class Changeset < ActiveRecord::Base | |||||
118 | end |
|
115 | end | |
119 | journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, csettext)) |
|
116 | journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, csettext)) | |
120 | issue.status = fix_status |
|
117 | issue.status = fix_status | |
121 | issue.done_ratio = done_ratio if done_ratio |
|
118 | unless Setting.commit_fix_done_ratio.blank? | |
|
119 | issue.done_ratio = Setting.commit_fix_done_ratio.to_i | |||
|
120 | end | |||
122 | Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update, |
|
121 | Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update, | |
123 | { :changeset => self, :issue => issue }) |
|
122 | { :changeset => self, :issue => issue }) | |
124 | issue.save |
|
123 | issue.save | |
@@ -127,7 +126,8 class Changeset < ActiveRecord::Base | |||||
127 | referenced_issues += target_issues |
|
126 | referenced_issues += target_issues | |
128 | end |
|
127 | end | |
129 |
|
128 | |||
130 |
|
|
129 | referenced_issues.uniq! | |
|
130 | self.issues = referenced_issues unless referenced_issues.empty? | |||
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | def short_comments |
|
133 | def short_comments | |
@@ -158,6 +158,7 class Changeset < ActiveRecord::Base | |||||
158 | # Finds issues that can be referenced by the commit message |
|
158 | # Finds issues that can be referenced by the commit message | |
159 | # i.e. issues that belong to the repository project, a subproject or a parent project |
|
159 | # i.e. issues that belong to the repository project, a subproject or a parent project | |
160 | def find_referenced_issues_by_id(ids) |
|
160 | def find_referenced_issues_by_id(ids) | |
|
161 | return [] if ids.compact.empty? | |||
161 | Issue.find_all_by_id(ids, :include => :project).select {|issue| |
|
162 | Issue.find_all_by_id(ids, :include => :project).select {|issue| | |
162 | project == issue.project || project.is_ancestor_of?(issue.project) || project.is_descendant_of?(issue.project) |
|
163 | project == issue.project || project.is_ancestor_of?(issue.project) || project.is_descendant_of?(issue.project) | |
163 | } |
|
164 | } |
@@ -136,6 +136,7 class Repository < ActiveRecord::Base | |||||
136 | end |
|
136 | end | |
137 | end |
|
137 | end | |
138 | @committers = nil |
|
138 | @committers = nil | |
|
139 | @found_committer_users = nil | |||
139 | true |
|
140 | true | |
140 | else |
|
141 | else | |
141 | false |
|
142 | false | |
@@ -146,16 +147,22 class Repository < ActiveRecord::Base | |||||
146 | # It will return nil if the committer is not yet mapped and if no User |
|
147 | # It will return nil if the committer is not yet mapped and if no User | |
147 | # with the same username or email was found |
|
148 | # with the same username or email was found | |
148 | def find_committer_user(committer) |
|
149 | def find_committer_user(committer) | |
149 |
|
|
150 | unless committer.blank? | |
|
151 | @found_committer_users ||= {} | |||
|
152 | return @found_committer_users[committer] if @found_committer_users.has_key?(committer) | |||
|
153 | ||||
|
154 | user = nil | |||
150 | c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user) |
|
155 | c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user) | |
151 | if c && c.user |
|
156 | if c && c.user | |
152 | c.user |
|
157 | user = c.user | |
153 | elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/ |
|
158 | elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/ | |
154 | username, email = $1.strip, $3 |
|
159 | username, email = $1.strip, $3 | |
155 | u = User.find_by_login(username) |
|
160 | u = User.find_by_login(username) | |
156 | u ||= User.find_by_mail(email) unless email.blank? |
|
161 | u ||= User.find_by_mail(email) unless email.blank? | |
157 | u |
|
162 | user = u | |
158 | end |
|
163 | end | |
|
164 | @found_committer_users[committer] = user | |||
|
165 | user | |||
159 | end |
|
166 | end | |
160 | end |
|
167 | end | |
161 |
|
168 |
@@ -286,21 +286,23 module Redmine | |||||
286 | end |
|
286 | end | |
287 |
|
287 | |||
288 | def save(repo) |
|
288 | def save(repo) | |
289 | if repo.changesets.find_by_scmid(scmid.to_s).nil? |
|
289 | Changeset.transaction do | |
290 |
changeset = Changeset. |
|
290 | changeset = Changeset.new( | |
291 | :repository => repo, |
|
291 | :repository => repo, | |
292 | :revision => identifier, |
|
292 | :revision => identifier, | |
293 | :scmid => scmid, |
|
293 | :scmid => scmid, | |
294 | :committer => author, |
|
294 | :committer => author, | |
295 | :committed_on => time, |
|
295 | :committed_on => time, | |
296 | :comments => message) |
|
296 | :comments => message) | |
297 |
|
297 | |||
298 | paths.each do |file| |
|
298 | if changeset.save | |
299 |
|
|
299 | paths.each do |file| | |
300 |
|
|
300 | Change.create( | |
301 |
|
|
301 | :changeset => changeset, | |
302 |
|
|
302 | :action => file[:action], | |
303 | end |
|
303 | :path => file[:path]) | |
|
304 | end | |||
|
305 | end | |||
304 | end |
|
306 | end | |
305 | end |
|
307 | end | |
306 | end |
|
308 | end |
General Comments 0
You need to be logged in to leave comments.
Login now