Class: Changeset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Changeset
- Defined in:
- app/models/changeset.rb
Constant Summary collapse
- TIMELOG_RE =
/ ( ((\d+)(h|hours?))((\d+)(m|min)?)? | ((\d+)(h|hours?|m|min)) | (\d+):(\d+) | (\d+([\.,]\d+)?)h? ) /x
Class Method Summary collapse
-
.normalize_comments(str, encoding) ⇒ Object
Strips and reencodes a commit log before insertion into the database.
Instance Method Summary collapse
- #after_create ⇒ Object
- #author ⇒ Object
- #before_create ⇒ Object
- #committed_on=(date) ⇒ Object
-
#create_change(change) ⇒ Object
Creates a new Change from it’s common parameters.
-
#format_identifier ⇒ Object
Returns the readable identifier.
-
#identifier ⇒ Object
Returns the identifier of this changeset; depending on repository backends.
- #long_comments ⇒ Object
-
#next ⇒ Object
Returns the next changeset.
-
#previous ⇒ Object
Returns the previous changeset.
- #project ⇒ Object
- #revision=(r) ⇒ Object
- #scan_comment_for_issue_ids ⇒ Object
- #short_comments ⇒ Object
- #text_tag ⇒ Object
Class Method Details
.normalize_comments(str, encoding) ⇒ Object
Strips and reencodes a commit log before insertion into the database
241 242 243 |
# File 'app/models/changeset.rb', line 241 def self.normalize_comments(str, encoding) Changeset.to_utf8(str.to_s.strip, encoding) end |
Instance Method Details
#after_create ⇒ Object
88 89 90 |
# File 'app/models/changeset.rb', line 88 def after_create scan_comment_for_issue_ids end |
#author ⇒ Object
78 79 80 |
# File 'app/models/changeset.rb', line 78 def user || committer.to_s.split('<').first end |
#before_create ⇒ Object
82 83 84 85 86 |
# File 'app/models/changeset.rb', line 82 def before_create self.committer = self.class.to_utf8(self.committer, repository.repo_log_encoding) self.comments = self.class.normalize_comments(self.comments, repository.repo_log_encoding) self.user = repository.find_committer_user(self.committer) end |
#committed_on=(date) ⇒ Object
60 61 62 63 |
# File 'app/models/changeset.rb', line 60 def committed_on=(date) self.commit_date = date super end |
#create_change(change) ⇒ Object
Creates a new Change from it’s common parameters
161 162 163 164 165 166 167 |
# File 'app/models/changeset.rb', line 161 def create_change(change) Change.create(:changeset => self, :action => change[:action], :path => change[:path], :from_path => change[:from_path], :from_revision => change[:from_revision]) end |
#format_identifier ⇒ Object
Returns the readable identifier
66 67 68 69 70 71 72 |
# File 'app/models/changeset.rb', line 66 def format_identifier if repository.class.respond_to? :format_changeset_identifier repository.class.format_changeset_identifier self else identifier end end |
#identifier ⇒ Object
Returns the identifier of this changeset; depending on repository backends
52 53 54 55 56 57 58 |
# File 'app/models/changeset.rb', line 52 def identifier if repository.class.respond_to? :changeset_identifier repository.class.changeset_identifier self else revision.to_s end end |
#long_comments ⇒ Object
138 139 140 |
# File 'app/models/changeset.rb', line 138 def long_comments @long_comments || split_comments.last end |
#next ⇒ Object
Returns the next changeset
156 157 158 |
# File 'app/models/changeset.rb', line 156 def next @next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC') end |
#previous ⇒ Object
Returns the previous changeset
151 152 153 |
# File 'app/models/changeset.rb', line 151 def previous @previous ||= Changeset.find(:first, :conditions => ['id < ? AND repository_id = ?', self.id, self.repository_id], :order => 'id DESC') end |
#project ⇒ Object
74 75 76 |
# File 'app/models/changeset.rb', line 74 def project repository.project end |
#revision=(r) ⇒ Object
47 48 49 |
# File 'app/models/changeset.rb', line 47 def revision=(r) write_attribute :revision, (r.nil? ? nil : r.to_s) end |
#scan_comment_for_issue_ids ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/changeset.rb', line 104 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) ref_keywords_any = ref_keywords.delete('*') # keywords used to fix issues fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip) 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,;&]+#\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 referenced_issues << issue fix_issue(issue) if fix_keywords.include?(action.to_s.downcase) log_time(issue, hours) if hours && Setting.commit_logtime_enabled? end end end referenced_issues.uniq! self.issues = referenced_issues unless referenced_issues.empty? end |
#short_comments ⇒ Object
134 135 136 |
# File 'app/models/changeset.rb', line 134 def short_comments @short_comments || split_comments.first end |
#text_tag ⇒ Object
142 143 144 145 146 147 148 |
# File 'app/models/changeset.rb', line 142 def text_tag if scmid? "commit:#{scmid}" else "r#{revision}" end end |