Class: Repository
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Repository
- Defined in:
- app/models/repository.rb
Overview
redMine - project management software Copyright (C) 2006-2007 Jean-Philippe Lang
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Direct Known Subclasses
Bazaar, Cvs, Darcs, Filesystem, Git, Mercurial, Subversion
Defined Under Namespace
Classes: Bazaar, Cvs, Darcs, Filesystem, Git, Mercurial, Subversion
Class Method Summary (collapse)
- + (Object) available_scm
- + (Object) factory(klass_name, *args)
-
+ (Object) fetch_changesets
fetch new changesets for all repositories can be called periodically by an external script eg.
-
+ (Object) scan_changesets_for_issue_ids
scan changeset comments to find related and fixed issues for all repositories.
- + (Object) scm_name
Instance Method Summary (collapse)
- - (Object) cat(path, identifier = nil)
-
- (Object) changesets_for_path(path, options = {})
Default behaviour: we search in cached changesets.
-
- (Object) committer_ids=(h)
Maps committers username to a user ids.
-
- (Object) committers
Returns an array of committers usernames and associated user_id.
- - (Object) diff(path, rev, rev_to)
- - (Object) entries(path = nil, identifier = nil)
- - (Object) entry(path = nil, identifier = nil)
-
- (Object) find_committer_user(committer)
Returns the Redmine User corresponding to the given committer It will return nil if the committer is not yet mapped and if no User with the same username or email was found.
- - (Object) latest_changeset
- - (Object) properties(path, identifier = nil)
-
- (Object) relative_path(path)
Returns a path relative to the url of the repository.
-
- (Object) root_url=(arg)
Removes leading and trailing whitespace.
- - (Object) scan_changesets_for_issue_ids
- - (Object) scm
- - (Object) scm_name
- - (Boolean) supports_annotate?
- - (Boolean) supports_cat?
-
- (Object) url=(arg)
Removes leading and trailing whitespace.
Class Method Details
+ (Object) available_scm
155 156 157 |
# File 'app/models/repository.rb', line 155 def self.available_scm subclasses.collect {|klass| [klass.scm_name, klass.name]} end |
+ (Object) factory(klass_name, *args)
159 160 161 162 163 164 |
# File 'app/models/repository.rb', line 159 def self.factory(klass_name, *args) klass = "Repository::#{klass_name}".constantize klass.new(*args) rescue nil end |
+ (Object) fetch_changesets
fetch new changesets for all repositories can be called periodically by an external script eg. ruby script/runner "Repository.fetch_changesets"
142 143 144 |
# File 'app/models/repository.rb', line 142 def self.fetch_changesets find(:all).each(&:fetch_changesets) end |
+ (Object) scan_changesets_for_issue_ids
scan changeset comments to find related and fixed issues for all repositories
147 148 149 |
# File 'app/models/repository.rb', line 147 def self.scan_changesets_for_issue_ids find(:all).each(&:scan_changesets_for_issue_ids) end |
+ (Object) scm_name
151 152 153 |
# File 'app/models/repository.rb', line 151 def self.scm_name 'Abstract' end |
Instance Method Details
- (Object) cat(path, identifier = nil)
70 71 72 |
# File 'app/models/repository.rb', line 70 def cat(path, identifier=nil) scm.cat(path, identifier) end |
- (Object) changesets_for_path(path, options = {})
Default behaviour: we search in cached changesets
79 80 81 82 83 84 85 |
# File 'app/models/repository.rb', line 79 def changesets_for_path(path, ={}) path = "/#{path}" unless path.starts_with?('/') Change.find(:all, :include => {:changeset => :user}, :conditions => ["repository_id = ? AND path = ?", id, path], :order => "committed_on DESC, #{Changeset.table_name}.id DESC", :limit => [:limit]).collect(&:changeset) end |
- (Object) committer_ids=(h)
Maps committers username to a user ids
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/models/repository.rb', line 106 def committer_ids=(h) if h.is_a?(Hash) committers.each do |committer, user_id| new_user_id = h[committer] if new_user_id && (new_user_id.to_i != user_id.to_i) new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil) Changeset.update_all("user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }", ["repository_id = ? AND committer = ?", id, committer]) end end @committers = nil true else false end end |
- (Object) committers
Returns an array of committers usernames and associated user_id
101 102 103 |
# File 'app/models/repository.rb', line 101 def committers @committers ||= Changeset.connection.select_rows("SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}") end |
- (Object) diff(path, rev, rev_to)
74 75 76 |
# File 'app/models/repository.rb', line 74 def diff(path, rev, rev_to) scm.diff(path, rev, rev_to) end |
- (Object) entries(path = nil, identifier = nil)
62 63 64 |
# File 'app/models/repository.rb', line 62 def entries(path=nil, identifier=nil) scm.entries(path, identifier) end |
- (Object) entry(path = nil, identifier = nil)
58 59 60 |
# File 'app/models/repository.rb', line 58 def entry(path=nil, identifier=nil) scm.entry(path, identifier) end |
- (Object) find_committer_user(committer)
Returns the Redmine User corresponding to the given committer It will return nil if the committer is not yet mapped and if no User with the same username or email was found
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/repository.rb', line 125 def find_committer_user(committer) if committer c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user) if c && c.user c.user elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/ username, email = $1.strip, $3 u = User.find_by_login(username) u ||= User.find_by_mail(email) unless email.blank? u end end end |
- (Object) latest_changeset
92 93 94 |
# File 'app/models/repository.rb', line 92 def latest_changeset @latest_changeset ||= changesets.find(:first) end |
- (Object) properties(path, identifier = nil)
66 67 68 |
# File 'app/models/repository.rb', line 66 def properties(path, identifier=nil) scm.properties(path, identifier) end |
- (Object) relative_path(path)
Returns a path relative to the url of the repository
88 89 90 |
# File 'app/models/repository.rb', line 88 def relative_path(path) path end |
- (Object) root_url=(arg)
Removes leading and trailing whitespace
36 37 38 |
# File 'app/models/repository.rb', line 36 def root_url=(arg) write_attribute(:root_url, arg ? arg.to_s.strip : nil) end |
- (Object) scan_changesets_for_issue_ids
96 97 98 |
# File 'app/models/repository.rb', line 96 def scan_changesets_for_issue_ids self.changesets.each(&:scan_comment_for_issue_ids) end |
- (Object) scm
40 41 42 43 44 |
# File 'app/models/repository.rb', line 40 def scm @scm ||= self.scm_adapter.new url, root_url, login, password update_attribute(:root_url, @scm.root_url) if root_url.blank? @scm end |
- (Object) scm_name
46 47 48 |
# File 'app/models/repository.rb', line 46 def scm_name self.class.scm_name end |
- (Boolean) supports_annotate?
54 55 56 |
# File 'app/models/repository.rb', line 54 def supports_annotate? scm.supports_annotate? end |
- (Boolean) supports_cat?
50 51 52 |
# File 'app/models/repository.rb', line 50 def supports_cat? scm.supports_cat? end |
- (Object) url=(arg)
Removes leading and trailing whitespace
31 32 33 |
# File 'app/models/repository.rb', line 31 def url=(arg) write_attribute(:url, arg ? arg.to_s.strip : nil) end |