Class: Changeset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Changeset
- Defined in:
- app/models/changeset.rb
Class Method Summary (collapse)
-
+ (Object) normalize_comments(str)
Strips and reencodes a commit log before insertion into the database.
Instance Method Summary (collapse)
- - (Object) after_create
- - (Object) author
- - (Object) before_create
- - (Object) comments=(comment)
- - (Object) committed_on=(date)
- - (Object) long_comments
-
- (Object) next
Returns the next changeset.
-
- (Object) previous
Returns the previous changeset.
- - (Object) project
- - (Object) revision=(r)
- - (Object) scan_comment_for_issue_ids
- - (Object) short_comments
Class Method Details
+ (Object) normalize_comments(str)
Strips and reencodes a commit log before insertion into the database
144 145 146 |
# File 'app/models/changeset.rb', line 144 def self.normalize_comments(str) to_utf8(str.to_s.strip) end |
Instance Method Details
- (Object) after_create
69 70 71 |
# File 'app/models/changeset.rb', line 69 def after_create scan_comment_for_issue_ids end |
- (Object) author
61 62 63 |
# File 'app/models/changeset.rb', line 61 def user || committer.to_s.split('<').first end |
- (Object) before_create
65 66 67 |
# File 'app/models/changeset.rb', line 65 def before_create self.user = repository.find_committer_user(committer) end |
- (Object) comments=(comment)
48 49 50 |
# File 'app/models/changeset.rb', line 48 def comments=(comment) write_attribute(:comments, Changeset.normalize_comments(comment)) end |
- (Object) committed_on=(date)
52 53 54 55 |
# File 'app/models/changeset.rb', line 52 def committed_on=(date) self.commit_date = date super end |
- (Object) long_comments
129 130 131 |
# File 'app/models/changeset.rb', line 129 def long_comments @long_comments || split_comments.last end |
- (Object) next
Returns the next changeset
139 140 141 |
# File 'app/models/changeset.rb', line 139 def next @next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC') end |
- (Object) previous
Returns the previous changeset
134 135 136 |
# File 'app/models/changeset.rb', line 134 def previous @previous ||= Changeset.find(:first, :conditions => ['id < ? AND repository_id = ?', self.id, self.repository_id], :order => 'id DESC') end |
- (Object) project
57 58 59 |
# File 'app/models/changeset.rb', line 57 def project repository.project end |
- (Object) revision=(r)
44 45 46 |
# File 'app/models/changeset.rb', line 44 def revision=(r) write_attribute :revision, (r.nil? ? nil : r.to_s) end |
- (Object) scan_comment_for_issue_ids
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/changeset.rb', line 74 def scan_comment_for_issue_ids return if comments.blank? # keywords used to reference issues ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip) # keywords used to fix issues fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip) # status and optional done ratio applied fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id) done_ratio = Setting.commit_fix_done_ratio.blank? ? nil : Setting.commit_fix_done_ratio.to_i kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|") return if kw_regexp.blank? referenced_issues = [] if ref_keywords.delete('*') # find any issue ID in the comments target_issue_ids = [] comments.scan(%r{([\s\(,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] } referenced_issues += repository.project.issues.find_all_by_id(target_issue_ids) end comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match| action = match[0] target_issue_ids = match[1].scan(/\d+/) target_issues = repository.project.issues.find_all_by_id(target_issue_ids) if fix_status && fix_keywords.include?(action.downcase) # update status of issues logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug? target_issues.each do |issue| # the issue may have been updated by the closure of another one (eg. duplicate) issue.reload # don't change the status is the issue is closed next if issue.status.is_closed? csettext = "r#{self.revision}" if self.scmid && (! (csettext =~ /^r[0-9]+$/)) csettext = "commit:\"#{self.scmid}\"" end journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, csettext)) issue.status = fix_status issue.done_ratio = done_ratio if done_ratio issue.save Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') end end referenced_issues += target_issues end self.issues = referenced_issues.uniq end |
- (Object) short_comments
125 126 127 |
# File 'app/models/changeset.rb', line 125 def short_comments @short_comments || split_comments.first end |