Patch #1783 ยป autorepo.diff
| app/apis/sys_api.rb | ||
|---|---|---|
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class ResultElement < ActionWebService::Struct
|
||
|
member :project, Project
|
||
|
member :repository, Repository
|
||
|
end
|
||
|
class SysApi < ActionWebService::API::Base
|
||
|
api_method :projects,
|
||
|
:expects => [],
|
||
|
:returns => [[Project]]
|
||
|
:returns => [[ResultElement]],
|
||
|
api_method :repository_created,
|
||
|
:expects => [:string, :string],
|
||
|
:returns => [:int]
|
||
| app/controllers/repositories_controller.rb | ||
|---|---|---|
|
if !@repository
|
||
|
@repository = Repository.factory(params[:repository_scm])
|
||
|
@repository.project = @project
|
||
|
@repository.auto = params[:repository_auto]
|
||
|
end
|
||
|
if request.post?
|
||
|
@repository.attributes = params[:repository]
|
||
| app/controllers/sys_controller.rb | ||
|---|---|---|
|
before_invocation :check_enabled
|
||
|
|
||
|
# Returns the projects list, with their repositories
|
||
|
# Bug ! the list of repositories is not returned
|
||
|
def projects
|
||
|
Project.find(:all, :include => :repository)
|
||
|
projects = Project.find(:all, :include => :repository)
|
||
|
resultArray = []
|
||
|
projects.each do |project|
|
||
|
resultElement = ResultElement.new
|
||
|
resultElement.project = project
|
||
|
resultElement.repository = project.repository
|
||
|
resultArray << resultElement
|
||
|
end
|
||
|
resultArray
|
||
|
end
|
||
|
# Registers a repository for the given project identifier
|
||
|
# (Subversion specific)
|
||
|
def repository_created(identifier, url)
|
||
|
project = Project.find_by_identifier(identifier)
|
||
|
# Do not create the repository if the project has already one
|
||
|
return 0 unless project && project.repository.nil?
|
||
|
logger.debug "Repository for #{project.name} was created"
|
||
|
repository = Repository.factory('Subversion', :project => project, :url => url)
|
||
|
repository.save
|
||
|
if project && project.repository.auto
|
||
|
repository = project.repository
|
||
|
repository.url = url
|
||
|
logger.debug "Repository for #{project.name} was created"
|
||
|
repository.save
|
||
|
end
|
||
|
repository.id || 0
|
||
|
end
|
||
| app/helpers/repositories_helper.rb | ||
|---|---|---|
|
str
|
||
|
end
|
||
|
|
||
|
def repository_field_tags(form, repository)
|
||
|
method = repository.class.name.demodulize.underscore + "_field_tags"
|
||
|
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
|
||
|
end
|
||
|
|
||
|
def repository_field_tags(form, repository)
|
||
|
if repository
|
||
|
method = repository.class.name.demodulize.underscore + "_field_tags"
|
||
|
if !repository.auto || (repository.nil? || repository.new_record?)
|
||
|
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
|
||
|
end
|
||
|
end
|
||
|
def repository_auto(repository)
|
||
|
check_box ('repository', 'auto',
|
||
|
:checked => (repository.nil? || repository.new_record?) ? false : repository.auto,
|
||
|
:disabled => (repository && !repository.new_record?),
|
||
|
:onclick => "if (this.checked) {Element.hide('url_fields');} else {Element.show('url_fields');}" )
|
||
|
end
|
||
|
def scm_select_tag(repository)
|
||
|
container = [[]]
|
||
|
REDMINE_SUPPORTED_SCM.each {|scm| container << ["Repository::#{scm}".constantize.scm_name, scm]}
|
||
|
select_tag('repository_scm',
|
||
|
options_for_select(container, repository.class.name.demodulize),
|
||
|
:disabled => (repository && !repository.new_record?),
|
||
|
:onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
|
||
|
:onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
|
||
|
)
|
||
|
end
|
||
|
|
||
| app/models/repository/bazaar.rb | ||
|---|---|---|
|
class Repository::Bazaar < Repository
|
||
|
attr_protected :root_url
|
||
|
validates_presence_of :url
|
||
|
validates_presence_of :url, :unless => Proc.new { |repository| repository.auto }
|
||
|
def scm_adapter
|
||
|
Redmine::Scm::Adapters::BazaarAdapter
|
||
| app/models/repository/cvs.rb | ||
|---|---|---|
|
require 'digest/sha1'
|
||
|
class Repository::Cvs < Repository
|
||
|
validates_presence_of :url, :root_url
|
||
|
validates_presence_of :url, :root_url, :unless => Proc.new { |repository| repository.auto }
|
||
|
def scm_adapter
|
||
|
Redmine::Scm::Adapters::CvsAdapter
|
||
| app/models/repository/darcs.rb | ||
|---|---|---|
|
require 'redmine/scm/adapters/darcs_adapter'
|
||
|
class Repository::Darcs < Repository
|
||
|
validates_presence_of :url
|
||
|
validates_presence_of :url, :unless => Proc.new { |repository| repository.auto }
|
||
|
def scm_adapter
|
||
|
Redmine::Scm::Adapters::DarcsAdapter
|
||
| app/models/repository/git.rb | ||
|---|---|---|
|
class Repository::Git < Repository
|
||
|
attr_protected :root_url
|
||
|
validates_presence_of :url
|
||
|
validates_presence_of :url, :unless => Proc.new { |repository| repository.auto }
|
||
|
def scm_adapter
|
||
|
Redmine::Scm::Adapters::GitAdapter
|
||
| app/models/repository/mercurial.rb | ||
|---|---|---|
|
class Repository::Mercurial < Repository
|
||
|
attr_protected :root_url
|
||
|
validates_presence_of :url
|
||
|
validates_presence_of :url, :unless => Proc.new { |repository| repository.auto }
|
||
|
def scm_adapter
|
||
|
Redmine::Scm::Adapters::MercurialAdapter
|
||
| app/models/repository/subversion.rb | ||
|---|---|---|
|
class Repository::Subversion < Repository
|
||
|
attr_protected :root_url
|
||
|
validates_presence_of :url
|
||
|
validates_format_of :url, :with => /^(http|https|svn|svn\+ssh|file):\/\/.+/i
|
||
|
validates_presence_of :url, :unless => Proc.new { |repository| repository.auto }
|
||
|
validates_format_of :url, :with => /^(http|https|svn|svn\+ssh|file):\/\/.+/i, :unless => Proc.new { |repository| repository.auto }
|
||
|
def scm_adapter
|
||
|
Redmine::Scm::Adapters::SubversionAdapter
|
||
| app/views/projects/settings/_repository.rhtml | ||
|---|---|---|
|
<div class="box tabular">
|
||
|
<p><label><%= l(:label_scm) %></label><%= scm_select_tag(@repository) %></p>
|
||
|
<%= repository_field_tags(f, @repository) if @repository %>
|
||
|
<p><label><%= l(:label_scm_auto) %></label><%= repository_auto(@repository) %></p>
|
||
|
<div id="url_fields"><%= repository_field_tags(f, @repository) %></div>
|
||
|
</div>
|
||
|
<div class="contextual">
|
||
| db/migrate/094_add_automatic_repository_column.rb | ||
|---|---|---|
|
class AddAutomaticRepositoryColumn < ActiveRecord::Migration
|
||
|
def self.up
|
||
|
add_column :repositories, :auto, :boolean, :default => false, :null => false
|
||
|
end
|
||
|
def self.down
|
||
|
remove_column :repositories, :auto
|
||
|
end
|
||
|
end
|
||
| extra/svn/reposmangen.rb | ||
|---|---|---|
|
#!/usr/bin/ruby
|
||
|
# == Synopsis
|
||
|
#
|
||
|
# reposman: manages your svn repositories with Redmine
|
||
|
#
|
||
|
# == Usage
|
||
|
#
|
||
|
# reposman [ -h | --help ] [ -v | --verbose ] [ -V | --version ] [ -q | --quiet ] -s /var/svn -r redmine.host.org
|
||
|
# example: reposman --svn-dir=/var/svn --redmine-host=redmine.mydomain.foo
|
||
|
# reposman -s /var/svn -r redmine.mydomain.foo
|
||
|
#
|
||
|
# == Arguments (mandatory)
|
||
|
#
|
||
|
# -s, --svn-dir=DIR
|
||
|
# use DIR as base directory for svn repositories
|
||
|
#
|
||
|
# -r, --redmine-host=HOST
|
||
|
# assume Redmine is hosted on HOST.
|
||
|
# you can use :
|
||
|
# * -r redmine.mydomain.foo (will add http://)
|
||
|
# * -r http://redmine.mydomain.foo
|
||
|
# * -r https://mydomain.foo/redmine
|
||
|
#
|
||
|
# == Options
|
||
|
#
|
||
|
# -o, --owner=OWNER
|
||
|
# owner of the repository. using the rails login allow user to browse
|
||
|
# the repository in Redmine even for private project
|
||
|
#
|
||
|
# -u, --url=URL
|
||
|
# the base url Redmine will use to access your repositories. This
|
||
|
# will be used to register the repository in Redmine so that user
|
||
|
# doesn't need to do anything. reposman will add the identifier to this url :
|
||
|
#
|
||
|
# -u https://my.svn.server/my/reposity/root # if the repository can be access by http
|
||
|
# -u file:///var/svn/ # if the repository is local
|
||
|
# if this option isn't set, reposman won't register the repository
|
||
|
#
|
||
|
# -t, --test
|
||
|
# only show what should be done
|
||
|
#
|
||
|
# -h, --help:
|
||
|
# show help and exit
|
||
|
#
|
||
|
# -v, --verbose
|
||
|
# verbose
|
||
|
#
|
||
|
# -V, --version
|
||
|
# print version and exit
|
||
|
#
|
||
|
# -q, --quiet
|
||
|
# no log
|
||
|
#
|
||
|
require 'getoptlong'
|
||
|
require 'rdoc/usage'
|
||
|
require 'soap/wsdlDriver'
|
||
|
require 'find'
|
||
|
require 'etc'
|
||
|
require 'yaml'
|
||
|
Version = "1.0"
|
||
|
opts = GetoptLong.new(
|
||
|
['--conf', '-c', GetoptLong::REQUIRED_ARGUMENT],
|
||
|
['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT],
|
||
|
['--owner', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
||
|
['--url', '-u', GetoptLong::REQUIRED_ARGUMENT],
|
||
|
['--test', '-t', GetoptLong::NO_ARGUMENT],
|
||
|
['--verbose', '-v', GetoptLong::NO_ARGUMENT],
|
||
|
['--version', '-V', GetoptLong::NO_ARGUMENT],
|
||
|
['--help' , '-h', GetoptLong::NO_ARGUMENT],
|
||
|
['--quiet' , '-q', GetoptLong::NO_ARGUMENT]
|
||
|
)
|
||
|
$conffile = "config.yml"
|
||
|
$verbose = 0
|
||
|
$quiet = false
|
||
|
$redmine_host = ''
|
||
|
$vcs_owner = 'root'
|
||
|
$use_groupid = true
|
||
|
$test = false
|
||
|
def log(text,level=0, exit=false)
|
||
|
return if $quiet or level > $verbose
|
||
|
puts text
|
||
|
exit 1 if exit
|
||
|
end
|
||
|
begin
|
||
|
opts.each do |opt, arg|
|
||
|
case opt
|
||
|
when '--conf'; $conffile = arg.dup
|
||
|
when '--redmine-host'; $redmine_host = arg.dup
|
||
|
when '--owner'; $vcs_owner = arg.dup; $use_groupid = false;
|
||
|
when '--verbose'; $verbose += 1
|
||
|
when '--test'; $test = true
|
||
|
when '--version'; puts Version; exit
|
||
|
when '--help'; RDoc::usage
|
||
|
when '--quiet'; $quiet = true
|
||
|
end
|
||
|
end
|
||
|
rescue
|
||
|
exit 1
|
||
|
end
|
||
|
if File.exist?($conffile)
|
||
|
config = open($conffile) {|f| YAML.load(f) }
|
||
|
else
|
||
|
config = {
|
||
|
"Git" => {"url" => "http://example.org/git",
|
||
|
"base" => "/path/to/git" } ,
|
||
|
"Subversion" => {
|
||
|
"url" => "http://subversion.example.org/",
|
||
|
"base" => "/path/to/subversion" }
|
||
|
}
|
||
|
open('config.yml', 'w') {|f| YAML.dump(config, f)}
|
||
|
log("Creating stub config file. Please edit it.",-1,true)
|
||
|
end
|
||
|
log("running in test mode") if $test
|
||
|
RDoc::usage if $redmine_host.empty?
|
||
|
log("querying Redmine for projects...", 1);
|
||
|
$redmine_host.gsub!(/^/, "http://") unless $redmine_host.match("^https?://")
|
||
|
$redmine_host.gsub!(/\/$/, '')
|
||
|
wsdl_url = "#{$redmine_host}/sys/service.wsdl";
|
||
|
begin
|
||
|
soap = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver
|
||
|
rescue => e
|
||
|
log("Unable to connect to #{wsdl_url} : #{e}", 0, true)
|
||
|
end
|
||
|
projects = soap.Projects
|
||
|
if projects.nil?
|
||
|
log('no project found, perhaps you forgot to "Enable WS for repository management"', 0, true)
|
||
|
end
|
||
|
log("retrieved #{projects.size} projects", 1)
|
||
|
def set_owner_and_rights(project, repos_path, &block)
|
||
|
if RUBY_PLATFORM =~ /mswin/
|
||
|
yield if block_given?
|
||
|
else
|
||
|
uid = Etc.getpwnam($vcs_owner).uid
|
||
|
# if the gid is 0 I get an exception...
|
||
|
#gid = $use_groupid ? Etc.getgrnam(project.identifier).gid : 0
|
||
|
gid = 0
|
||
|
right = project.is_public ? 0775 : 0770
|
||
|
yield if block_given?
|
||
|
Find.find(repos_path) do |f|
|
||
|
File.chmod right, f
|
||
|
File.chown uid, gid, f
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def other_read_right?(file)
|
||
|
(File.stat(file).mode & 0007).zero? ? false : true
|
||
|
end
|
||
|
def owner_name(file)
|
||
|
RUBY_PLATFORM =~ /mswin/ ?
|
||
|
$vcs_owner :
|
||
|
Etc.getpwuid( File.stat(file).uid ).name
|
||
|
end
|
||
|
projects.each do |element|
|
||
|
project = element.project
|
||
|
repository = element.repository
|
||
|
repos_type = repository["type"]
|
||
|
repos_base = config["#{repos_type}"]["base"]
|
||
|
repos_url = config["#{repos_type}"]["url"]
|
||
|
repos_url += "/" if repos_url and not repos_url.match(/\/$/)
|
||
|
repos_path = repos_base + "/" + project.identifier
|
||
|
unless File.directory?(repos_base)
|
||
|
log("directory '#{repos_base}' doesn't exists", 0, true)
|
||
|
end
|
||
|
log("treating project #{project.name}", 1)
|
||
|
if project.identifier.empty?
|
||
|
log("\tno identifier for project #{project.name}")
|
||
|
next
|
||
|
elsif not project.identifier.match(/^[a-z0-9\-]+$/)
|
||
|
log("\tinvalid identifier for project #{project.name} : #{project.identifier}");
|
||
|
next;
|
||
|
end
|
||
|
|
||
|
if repository.auto
|
||
|
if File.directory?(repos_path)
|
||
|
# we must verify that repository has the good owner and the good
|
||
|
# rights before leaving
|
||
|
other_read = other_read_right?(repos_path)
|
||
|
owner = owner_name(repos_path)
|
||
|
next if project.is_public == other_read and owner == $vcs_owner
|
||
|
if $test
|
||
|
log("\tchange mode on #{repos_path}")
|
||
|
next
|
||
|
end
|
||
|
begin
|
||
|
set_owner_and_rights(project, repos_path)
|
||
|
rescue Errno::EPERM => e
|
||
|
log("\tunable to change mode on #{repos_path} : #{e}\n")
|
||
|
next
|
||
|
end
|
||
|
log("\tmode change on #{repos_path}");
|
||
|
else
|
||
|
# the directory repos_path doesn't exist
|
||
|
project.is_public ? File.umask(0002) : File.umask(0007)
|
||
|
if $test
|
||
|
log("\tcreate repository #{repos_path}")
|
||
|
log("\trepository #{repos_path} registered in Redmine with url #{repos_url}#{project.identifier}") if repos_url;
|
||
|
next
|
||
|
end
|
||
|
begin
|
||
|
Dir.mkdir(repos_path) unless test(?d, repos_path)
|
||
|
set_owner_and_rights(project, repos_path) do
|
||
|
case "#{repos_type}"
|
||
|
when "Subversion":
|
||
|
raise "svnadmin create #{repos_path} failed" unless system("svnadmin", "create", repos_path)
|
||
|
when "Git":
|
||
|
Dir.chdir(repos_path) do
|
||
|
raise "git create #{repos_path} failed" unless system("git-init-db", "--shared")
|
||
|
end
|
||
|
else
|
||
|
raise "unknown cvs type #{repos_type}"
|
||
|
end
|
||
|
end
|
||
|
rescue => e
|
||
|
Dir.rmdir(repos_path)
|
||
|
log("\tunable to create #{repos_path} : #{e}\n")
|
||
|
next
|
||
|
end
|
||
|
if repos_url
|
||
|
ret = soap.RepositoryCreated project.identifier, "#{repos_url}#{project.identifier}"
|
||
|
if ret > 0
|
||
|
log("\trepository #{repos_path} registered in Redmine with url #{repos_url}#{project.identifier}");
|
||
|
else
|
||
|
log("\trepository #{repos_path} not registered in Redmine. Look in your log to find why.");
|
||
|
end
|
||
|
end
|
||
|
log("\trepository #{repos_path} created");
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| lang/en.yml | ||
|---|---|---|
|
label_general: General
|
||
|
label_more: More
|
||
|
label_scm: SCM
|
||
|
label_scm_auto: Create Repository
|
||
|
label_plugins: Plugins
|
||
|
label_ldap_authentication: LDAP authentication
|
||
|
label_downloads_abbr: D/L
|
||
| lib/redmine/scm/adapters/abstract_adapter.rb | ||
|---|---|---|
|
end
|
||
|
|
||
|
class AbstractAdapter #:nodoc:
|
||
|
def initialize(url, root_url=nil, login=nil, password=nil)
|
||
|
def initialize(url=nil, root_url=nil, login=nil, password=nil)
|
||
|
@url = url
|
||
|
@login = login if login && !login.empty?
|
||
|
@password = (password || "") if @login
|
||