Skip to content

Instantly share code, notes, and snippets.

@skateinmars
Created August 14, 2008 12:18
Show Gist options
  • Save skateinmars/5422 to your computer and use it in GitHub Desktop.
Save skateinmars/5422 to your computer and use it in GitHub Desktop.
rake task for project creation in redmine
# Use with rake :
# rake redmine:project:create PROJECT=myproject SVNURL="scheme://myurl" SVNLOGIN="user" SVNPASSWD="xxx" USERS="john bob"
namespace :redmine do
namespace :project do
desc 'Create a project from ENV variables'
task :create => :environment do
if ENV['PROJECT'].blank?
print "Enter project name : "
identifier = STDIN.gets.chomp!
else
identifier = ENV['PROJECT']
end
svnurl = ENV['SVNURL']
svnlogin = ENV['SVNLOGIN']
svnpassword = ENV['SVNPASSWD']
public = 0
MYMODULES = ["issue_tracking", "time_tracking", "news", "documents", "wiki", "repository"]
TRACKER_BUG = Tracker.find_by_position(1)
TRACKER_FEATURE = Tracker.find_by_position(2)
users = ENV['USERS'].nil? ? [] : ENV['USERS'].split(' ')
manager = Role.find_by_name "Manager"
project = Project.new :name => identifier.humanize,
:identifier => identifier,
:description => '',
:is_public => public
project.enabled_module_names = MYMODULES
project.trackers << [TRACKER_BUG, TRACKER_FEATURE]
project.save
project.reload
users.each do |login|
user = User.find_by_login login
Member.create({:user => user, :project => project, :role => manager}) unless user.nil?
end
repos = Repository::Subversion.create({:project => project, :url => svnurl, :login => svnlogin, :password => svnpassword}) unless svnurl.nil?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment