##// END OF EJS Templates
Merged r9734 from trunk (#11032)...
Merged r9734 from trunk (#11032) fix project list is not shown on Email notifications. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.0-stable@9739 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r9492:a59257dfb69c
r9556:07edb105181f
Show More
reposman.rb
288 lines | 10.4 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
Changes ruby bang path to #!/usr/bin/env ruby (#1876)....
r2015 #!/usr/bin/env ruby
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
Jean-Philippe Lang
Use optparse instead rdoc/usage in reposman (#10837)....
r9465 require 'optparse'
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 require 'find'
require 'etc'
Jean-Philippe Lang
Use optparse instead rdoc/usage in reposman (#10837)....
r9465 Version = "1.4"
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem )
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
$verbose = 0
$quiet = false
$redmine_host = ''
$repos_base = ''
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 $svn_owner = 'root'
Nicolas Chuche
Fixed: add group option to set the repository gid. Default is root (#2747)...
r2416 $svn_group = 'root'
Nicolas Chuche
bug when using apache authentication method...
r989 $use_groupid = true
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 $svn_url = false
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 $test = false
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 $force = false
$scm = 'Subversion'
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
Jean-Philippe Lang
reposman: change #log arguments....
r1873 def log(text, options={})
level = options[:level] || 0
Nicolas Chuche
bugfix...
r1858 puts text unless $quiet or level > $verbose
Jean-Philippe Lang
reposman: change #log arguments....
r1873 exit 1 if options[:exit]
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 def system_or_raise(command)
raise "\"#{command}\" failed" unless system command
end
module SCM
module Subversion
def self.create(path)
system_or_raise "svnadmin create #{path}"
end
end
module Git
def self.create(path)
Dir.mkdir path
Dir.chdir(path) do
system_or_raise "git --bare init --shared"
Jean-Philippe Lang
Slight change on git repository creation command....
r1874 system_or_raise "git update-server-info"
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 end
end
end
end
Jean-Philippe Lang
Use optparse instead rdoc/usage in reposman (#10837)....
r9465 def read_key_from_file(filename)
begin
$api_key = File.read(filename).strip
rescue Exception => e
$stderr.puts "Unable to read the key from #{filename}: #{e.message}"
exit 1
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
end
Jean-Philippe Lang
Use optparse instead rdoc/usage in reposman (#10837)....
r9465 def set_scm(scm)
Jean-Philippe Lang
Fixed #set_scm in reposman (#10837)....
r9492 $scm = scm.capitalize
Jean-Philippe Lang
Use optparse instead rdoc/usage in reposman (#10837)....
r9465 unless SUPPORTED_SCM.include?($scm)
log("Invalid SCM: #{$scm}\nValid SCM are: #{SUPPORTED_SCM.join(', ')}", :exit => true)
end
end
optparse = OptionParser.new do |opts|
opts.banner = "Usage: reposman.rb [OPTIONS...] -s [DIR] -r [HOST] -k [KEY]"
opts.separator("")
Jean-Philippe Lang
Adds script synopsis....
r9491 opts.separator("Manages your repositories with Redmine.")
opts.separator("")
Jean-Philippe Lang
Use optparse instead rdoc/usage in reposman (#10837)....
r9465 opts.separator("Required arguments:")
Jean-Philippe Lang
Fixed reposman arguments parsing (#10837)....
r9490 opts.on("-s", "--svn-dir DIR", "use DIR as base directory for svn repositories") {|v| $repos_base = v}
opts.on("-r", "--redmine-host HOST","assume Redmine is hosted on HOST. Examples:",
Jean-Philippe Lang
Formatting....
r9466 " -r redmine.example.net",
" -r http://redmine.example.net",
" -r https://redmine.example.net") {|v| $redmine_host = v}
opts.on("-k", "--key KEY", "use KEY as the Redmine API key",
"(you can use --key-file option as an alternative)") {|v| $api_key = v}
Jean-Philippe Lang
Use optparse instead rdoc/usage in reposman (#10837)....
r9465 opts.separator("")
opts.separator("Options:")
opts.on("-o", "--owner OWNER", "owner of the repository. using the rails login",
"allows users to browse the repository within",
"Redmine even for private projects. If you want to",
"share repositories through Redmine.pm, you need",
"to use the apache owner.") {|v| $svn_owner = v; $use_groupid = false}
opts.on("-g", "--group GROUP", "group of the repository (default: root)") {|v| $svn_group = v; $use_groupid = false}
opts.on("-u", "--url URL", "the base url Redmine will use to access your",
"repositories. This option is used to register",
"the repositories in Redmine automatically. The",
"project identifier will be appended to this url.",
"Examples:",
" -u https://example.net/svn",
" -u file:///var/svn/",
"if this option isn't set, reposman won't register",
"the repositories in Redmine") {|v| $svn_url = v}
opts.on( "--scm SCM", "the kind of SCM repository you want to create",
"(and register) in Redmine (default: Subversion).",
"reposman is able to create Git and Subversion",
"repositories.",
"For all other kind, you must specify a --command",
"option") {|v| set_scm(v)}
opts.on("-c", "--command COMMAND", "use this command instead of `svnadmin create` to",
"create a repository. This option can be used to",
"create repositories other than subversion and git",
"kind.",
"This command override the default creation for",
"git and subversion.") {|v| $command = v}
opts.on( "--key-file FILE", "path to a file that contains the Redmine API key",
"(use this option instead of --key if you don't",
"want the key to appear in the command line)") {|v| read_key_from_file(v)}
opts.on("-t", "--test", "only show what should be done") {$test = true}
opts.on("-f", "--force", "force repository creation even if the project", "repository is already declared in Redmine") {$force = true}
opts.on("-v", "--verbose", "verbose") {$verbose += 1}
opts.on("-V", "--version", "show version and exit") {puts Version; exit}
Jean-Philippe Lang
Formatting....
r9466 opts.on("-h", "--help", "show help and exit") {puts opts; exit 1}
opts.on("-q", "--quiet", "no log") {$quiet = true}
Jean-Philippe Lang
Use optparse instead rdoc/usage in reposman (#10837)....
r9465 opts.separator("")
opts.separator("Examples:")
opts.separator(" reposman.rb --svn-dir=/var/svn --redmine-host=redmine.host")
opts.separator(" reposman.rb -s /var/git -r redmine.host -u http://git.host --scm git")
opts.separator("")
opts.separator("You can find more information on the redmine's wiki:\nhttp://www.redmine.org/projects/redmine/wiki/HowTos")
opts.summary_width = 25
end
optparse.parse!
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 if $test
log("running in test mode")
end
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 # Make sure command is overridden if SCM vendor is not handled internally (for the moment Subversion and Git)
if $command.nil?
begin
scm_module = SCM.const_get($scm)
rescue
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("Please use --command option to specify how to create a #{$scm} repository.", :exit => true)
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 end
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 end
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 $svn_url += "/" if $svn_url and not $svn_url.match(/\/$/)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 if ($redmine_host.empty? or $repos_base.empty?)
Jean-Philippe Lang
Use optparse instead rdoc/usage in reposman (#10837)....
r9465 puts "Some arguments are missing. Use reposman.rb --help for getting help."
exit 1
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
unless File.directory?($repos_base)
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("directory '#{$repos_base}' doesn't exists", :exit => true)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 begin
Jean-Philippe Lang
Fixed: deprecation warning in reposman.rb (#4736)....
r3264 require 'active_resource'
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 rescue LoadError
log("This script requires activeresource.\nRun 'gem install activeresource' to install it.", :exit => true)
end
Jean-Philippe Lang
Adds a user-agent to reposman (#6735)....
r4174 class Project < ActiveResource::Base
self.headers["User-agent"] = "Redmine repository manager/#{Version}"
Jean-Philippe Lang
Set format for activeresource client in reposman....
r7835 self.format = :xml
Jean-Philippe Lang
Adds a user-agent to reposman (#6735)....
r4174 end
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("querying Redmine for projects...", :level => 1);
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
$redmine_host.gsub!(/^/, "http://") unless $redmine_host.match("^https?://")
$redmine_host.gsub!(/\/$/, '')
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 Project.site = "#{$redmine_host}/sys";
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
begin
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 # Get all active projects that have the Repository module enabled
Jean-Philippe Lang
Adds on optional API key to repositories management controller and reposman.rb....
r3087 projects = Project.find(:all, :params => {:key => $api_key})
Jean-Philippe Lang
Adds an explicit message for when reposman gets a 403....
r7838 rescue ActiveResource::ForbiddenAccess
log("Request was denied by your Redmine server. Make sure that 'WS for repository management' is enabled in application settings and that you provided the correct API key.")
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 rescue => e
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 log("Unable to connect to #{Project.site}: #{e}", :exit => true)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
if projects.nil?
Jean-Philippe Lang
Adds an explicit message for when reposman gets a 403....
r7838 log('No project found, perhaps you forgot to "Enable WS for repository management"', :exit => true)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 end
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("retrieved #{projects.size} projects", :level => 1)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 def set_owner_and_rights(project, repos_path, &block)
Jean-Philippe Lang
Fixed windows detection in reposman.rb (#8003)....
r5112 if mswin?
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 yield if block_given?
else
Nicolas Chuche
Fixed: add group option to set the repository gid. Default is root (#2747)...
r2416 uid, gid = Etc.getpwnam($svn_owner).uid, ($use_groupid ? Etc.getgrnam(project.identifier).gid : Etc.getgrnam($svn_group).gid)
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 right = project.is_public ? 0775 : 0770
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 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)
Jean-Philippe Lang
Fixed windows platform detection in reposman.rb (#5039)....
r3457 mswin? ?
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 $svn_owner :
Toshi MARUYAMA
remove trailing white-spaces and empty lines from extra/svn/reposman.rb....
r5705 Etc.getpwuid( File.stat(file).uid ).name
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 end
Toshi MARUYAMA
remove trailing white-spaces and empty lines from extra/svn/reposman.rb....
r5705
Jean-Philippe Lang
Fixed windows platform detection in reposman.rb (#5039)....
r3457 def mswin?
(RUBY_PLATFORM =~ /(:?mswin|mingw)/) || (RUBY_PLATFORM == 'java' && (ENV['OS'] || ENV['os']) =~ /windows/i)
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 projects.each do |project|
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("treating project #{project.name}", :level => 1)
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847
if project.identifier.empty?
log("\tno identifier for project #{project.name}")
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 next
Toshi MARUYAMA
reposman: allow underscores in project identifiers (#1363)...
r9143 elsif not project.identifier.match(/^[a-z0-9\-_]+$/)
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 log("\tinvalid identifier for project #{project.name} : #{project.identifier}");
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 next;
end
Jean-Philippe Lang
Make --command option usable on Windows....
r1875 repos_path = File.join($repos_base, project.identifier).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
if File.directory?(repos_path)
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 # 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 == $svn_owner
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 if $test
log("\tchange mode on #{repos_path}")
next
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 begin
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 set_owner_and_rights(project, repos_path)
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 rescue Errno::EPERM => e
log("\tunable to change mode on #{repos_path} : #{e}\n")
next
end
log("\tmode change on #{repos_path}");
else
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 # if repository is already declared in redmine, we don't create
# unless user use -f with reposman
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 if $force == false and project.respond_to?(:repository)
Jean-Philippe Lang
reposman: change #log arguments....
r1873 log("\trepository for project #{project.identifier} already exists in Redmine", :level => 1)
Jean-Philippe Lang
Merged nbc branch @ r1812 (commit access permission and reposman improvements)....
r1812 next
end
Nicolas Chuche
* add Redmine.pm to authenticate with mod_perl...
r903 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 #{$svn_url}#{project.identifier}") if $svn_url;
next
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826
begin
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 set_owner_and_rights(project, repos_path) do
Nicolas Chuche
* reposman can create git repository with "--scm git" option...
r1864 if scm_module.nil?
system_or_raise "#{$command} #{repos_path}"
else
scm_module.create(repos_path)
end
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 rescue => e
log("\tunable to create #{repos_path} : #{e}\n")
next
end
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 if $svn_url
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 begin
Jean-Philippe Lang
Adds on optional API key to repositories management controller and reposman.rb....
r3087 project.post(:repository, :vendor => $scm, :repository => {:url => "#{$svn_url}#{project.identifier}"}, :key => $api_key)
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}");
Jean-Philippe Lang
Replaces the repositories management SOAP API with a simple REST API....
r2374 rescue => e
log("\trepository #{repos_path} not registered in Redmine: #{e.message}");
Jean-Philippe Lang
SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created....
r847 end
end
Jean-Philippe Lang
Added reposman Ruby version (Nicolas Chuche)....
r826 log("\trepository #{repos_path} created");
end
end