Merged trunk r1773.
git-svn-id: http://redmine.rubyforge.org/svn/branches/work@1774 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 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.
|
||||
|
||||
namespace :redmine do
|
||||
namespace :email do
|
||||
|
||||
desc <<-END_DESC
|
||||
Read an email from standard input.
|
||||
|
||||
Issue attributes control options:
|
||||
project=PROJECT identifier of the target project
|
||||
tracker=TRACKER name of the target tracker
|
||||
category=CATEGORY name of the target category
|
||||
priority=PRIORITY name of the target priority
|
||||
allow_override=ATTRS allow email content to override attributes
|
||||
specified by previous options
|
||||
ATTRS is a comma separated list of attributes
|
||||
|
||||
Examples:
|
||||
# No project specified. Emails MUST contain the 'Project' keyword:
|
||||
rake redmine:email:read RAILS_ENV="production" < raw_email
|
||||
|
||||
# Fixed project and default tracker specified, but emails can override
|
||||
# both tracker and priority attributes:
|
||||
rake redmine:email:read RAILS_ENV="production" \\
|
||||
project=foo \\
|
||||
tracker=bug \\
|
||||
allow_override=tracker,priority < raw_email
|
||||
END_DESC
|
||||
|
||||
task :read => :environment do
|
||||
options = { :issue => {} }
|
||||
%w(project tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
|
||||
options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
|
||||
|
||||
MailHandler.receive(STDIN.read, options)
|
||||
end
|
||||
|
||||
desc <<-END_DESC
|
||||
Read emails from an IMAP server.
|
||||
|
||||
Available IMAP options:
|
||||
host=HOST IMAP server host (default: 127.0.0.1)
|
||||
port=PORT IMAP server port (default: 143)
|
||||
ssl=SSL Use SSL? (default: false)
|
||||
username=USERNAME IMAP account
|
||||
password=PASSWORD IMAP password
|
||||
folder=FOLDER IMAP folder to read (default: INBOX)
|
||||
|
||||
Issue attributes control options:
|
||||
project=PROJECT identifier of the target project
|
||||
tracker=TRACKER name of the target tracker
|
||||
category=CATEGORY name of the target category
|
||||
priority=PRIORITY name of the target priority
|
||||
allow_override=ATTRS allow email content to override attributes
|
||||
specified by previous options
|
||||
ATTRS is a comma separated list of attributes
|
||||
|
||||
Examples:
|
||||
# No project specified. Emails MUST contain the 'Project' keyword:
|
||||
|
||||
rake redmine:email:receive_iamp RAILS_ENV="production" \\
|
||||
host=imap.foo.bar username=redmine@example.net password=xxx
|
||||
|
||||
|
||||
# Fixed project and default tracker specified, but emails can override
|
||||
# both tracker and priority attributes:
|
||||
|
||||
rake redmine:email:receive_iamp RAILS_ENV="production" \\
|
||||
host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\
|
||||
project=foo \\
|
||||
tracker=bug \\
|
||||
allow_override=tracker,priority
|
||||
END_DESC
|
||||
|
||||
task :receive_imap => :environment do
|
||||
imap_options = {:host => ENV['host'],
|
||||
:port => ENV['port'],
|
||||
:ssl => ENV['ssl'],
|
||||
:username => ENV['username'],
|
||||
:password => ENV['password'],
|
||||
:folder => ENV['folder']}
|
||||
|
||||
options = { :issue => {} }
|
||||
%w(project tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
|
||||
options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
|
||||
|
||||
Redmine::IMAP.check(imap_options, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -92,12 +92,17 @@ namespace :redmine do
|
||||
set_table_name :milestone
|
||||
|
||||
def due
|
||||
if read_attribute(:due) > 0
|
||||
if read_attribute(:due) && read_attribute(:due) > 0
|
||||
Time.at(read_attribute(:due)).to_date
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def description
|
||||
# Attribute is named descr in Trac v0.8.x
|
||||
has_attribute?(:descr) ? read_attribute(:descr) : read_attribute(:description)
|
||||
end
|
||||
end
|
||||
|
||||
class TracTicketCustom < ActiveRecord::Base
|
||||
@@ -126,6 +131,10 @@ namespace :redmine do
|
||||
File.open("#{trac_fullpath}", 'rb').read
|
||||
end
|
||||
|
||||
def description
|
||||
read_attribute(:description).to_s.slice(0,255)
|
||||
end
|
||||
|
||||
private
|
||||
def trac_fullpath
|
||||
attachment_type = read_attribute(:type)
|
||||
@@ -140,7 +149,10 @@ namespace :redmine do
|
||||
|
||||
# ticket changes: only migrate status changes and comments
|
||||
has_many :changes, :class_name => "TracTicketChange", :foreign_key => :ticket
|
||||
has_many :attachments, :class_name => "TracAttachment", :foreign_key => :id, :conditions => "#{TracMigrate::TracAttachment.table_name}.type = 'ticket'"
|
||||
has_many :attachments, :class_name => "TracAttachment",
|
||||
:finder_sql => "SELECT DISTINCT attachment.* FROM #{TracMigrate::TracAttachment.table_name}" +
|
||||
" WHERE #{TracMigrate::TracAttachment.table_name}.type = 'ticket'" +
|
||||
' AND #{TracMigrate::TracAttachment.table_name}.id = \'#{id}\''
|
||||
has_many :customs, :class_name => "TracTicketCustom", :foreign_key => :ticket
|
||||
|
||||
def ticket_type
|
||||
@@ -177,7 +189,10 @@ namespace :redmine do
|
||||
set_table_name :wiki
|
||||
set_primary_key :name
|
||||
|
||||
has_many :attachments, :class_name => "TracAttachment", :foreign_key => :id, :conditions => "#{TracMigrate::TracAttachment.table_name}.type = 'wiki'"
|
||||
has_many :attachments, :class_name => "TracAttachment",
|
||||
:finder_sql => "SELECT DISTINCT attachment.* FROM #{TracMigrate::TracAttachment.table_name}" +
|
||||
" WHERE #{TracMigrate::TracAttachment.table_name}.type = 'wiki'" +
|
||||
' AND #{TracMigrate::TracAttachment.table_name}.id = \'#{id}\''
|
||||
|
||||
def self.columns
|
||||
# Hides readonly Trac field to prevent clash with AR readonly? method (Rails 2.0)
|
||||
@@ -191,6 +206,10 @@ namespace :redmine do
|
||||
set_table_name :permission
|
||||
end
|
||||
|
||||
class TracSessionAttribute < ActiveRecord::Base
|
||||
set_table_name :session_attribute
|
||||
end
|
||||
|
||||
def self.find_or_create_user(username, project_member = false)
|
||||
return User.anonymous if username.blank?
|
||||
|
||||
@@ -198,10 +217,23 @@ namespace :redmine do
|
||||
if !u
|
||||
# Create a new user if not found
|
||||
mail = username[0,limit_for(User, 'mail')]
|
||||
if mail_attr = TracSessionAttribute.find_by_sid_and_name(username, 'email')
|
||||
mail = mail_attr.value
|
||||
end
|
||||
mail = "#{mail}@foo.bar" unless mail.include?("@")
|
||||
u = User.new :firstname => username[0,limit_for(User, 'firstname')].gsub(/[^\w\s\'\-]/i, '-'),
|
||||
:lastname => '-',
|
||||
:mail => mail.gsub(/[^-@a-z0-9\.]/i, '-')
|
||||
|
||||
name = username
|
||||
if name_attr = TracSessionAttribute.find_by_sid_and_name(username, 'name')
|
||||
name = name_attr.value
|
||||
end
|
||||
name =~ (/(.*)(\s+\w+)?/)
|
||||
fn = $1.strip
|
||||
ln = ($2 || '-').strip
|
||||
|
||||
u = User.new :mail => mail.gsub(/[^-@a-z0-9\.]/i, '-'),
|
||||
:firstname => fn[0, limit_for(User, 'firstname')].gsub(/[^\w\s\'\-]/i, '-'),
|
||||
:lastname => ln[0, limit_for(User, 'lastname')].gsub(/[^\w\s\'\-]/i, '-')
|
||||
|
||||
u.login = username[0,limit_for(User, 'login')].gsub(/[^a-z0-9_\-@\.]/i, '-')
|
||||
u.password = 'trac'
|
||||
u.admin = true if TracPermission.find_by_username_and_action(username, 'admin')
|
||||
@@ -233,7 +265,8 @@ namespace :redmine do
|
||||
text = text.gsub(/\[\"(.+)\".*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
|
||||
text = text.gsub(/\[wiki:\"(.+)\".*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
|
||||
text = text.gsub(/\[wiki:\"(.+)\".*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
|
||||
text = text.gsub(/\[wiki:([^\s\]]+).*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
|
||||
text = text.gsub(/\[wiki:([^\s\]]+)\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
|
||||
text = text.gsub(/\[wiki:([^\s\]]+)\s(.*)\]/) {|s| "[[#{$1.delete(',./?;|:')}|#{$2.delete(',./?;|:')}]]"}
|
||||
|
||||
# Links to pages UsingJustWikiCaps
|
||||
text = text.gsub(/([^!]|^)(^| )([A-Z][a-z]+[A-Z][a-zA-Z]+)/, '\\1\\2[[\3]]')
|
||||
@@ -408,6 +441,7 @@ namespace :redmine do
|
||||
a.file = attachment
|
||||
a.author = find_or_create_user(attachment.author)
|
||||
a.container = i
|
||||
a.description = attachment.description
|
||||
migrated_ticket_attachments += 1 if a.save
|
||||
end
|
||||
|
||||
@@ -456,6 +490,7 @@ namespace :redmine do
|
||||
a = Attachment.new :created_on => attachment.time
|
||||
a.file = attachment
|
||||
a.author = find_or_create_user(attachment.author)
|
||||
a.description = attachment.description
|
||||
a.container = p
|
||||
migrated_wiki_attachments += 1 if a.save
|
||||
end
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2008 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.
|
||||
|
||||
desc <<-END_DESC
|
||||
Send reminders about issues due in the next days.
|
||||
|
||||
Available options:
|
||||
* days => number of days to remind about (defaults to 7)
|
||||
* tracker => id of tracker (defaults to all trackers)
|
||||
* project => id or identifier of project (defaults to all projects)
|
||||
|
||||
Example:
|
||||
rake redmine:send_reminders days=7 RAILS_ENV="production"
|
||||
END_DESC
|
||||
|
||||
namespace :redmine do
|
||||
task :send_reminders => :environment do
|
||||
options = {}
|
||||
options[:days] = ENV['days'].to_i if ENV['days']
|
||||
options[:project] = ENV['project'] if ENV['project']
|
||||
options[:tracker] = ENV['tracker'].to_i if ENV['tracker']
|
||||
|
||||
Mailer.reminders(options)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
### From http://svn.geekdaily.org/public/rails/plugins/generally_useful/tasks/coverage_via_rcov.rake
|
||||
|
||||
### Inspired by http://blog.labratz.net/articles/2006/12/2/a-rake-task-for-rcov
|
||||
begin
|
||||
require 'rcov/rcovtask'
|
||||
|
||||
rcov_options = "--rails --aggregate test/coverage.data --exclude '/gems/'"
|
||||
|
||||
namespace :test do
|
||||
desc "Aggregate code coverage for all tests"
|
||||
Rcov::RcovTask.new('coverage') do |t|
|
||||
t.libs << 'test'
|
||||
t.test_files = FileList['test/{unit,integration,functional}/*_test.rb']
|
||||
t.verbose = true
|
||||
t.rcov_opts << rcov_options
|
||||
end
|
||||
|
||||
namespace :coverage do
|
||||
desc "Delete coverage test data"
|
||||
task :clean do
|
||||
rm_f "test/coverage.data"
|
||||
rm_rf "test/coverage"
|
||||
end
|
||||
|
||||
desc "Aggregate code coverage for all tests with HTML output"
|
||||
Rcov::RcovTask.new('html') do |t|
|
||||
t.libs << 'test'
|
||||
t.test_files = FileList['test/{unit,integration,functional}/*_test.rb']
|
||||
t.output_dir = "test/coverage"
|
||||
t.verbose = true
|
||||
t.rcov_opts << rcov_options
|
||||
end
|
||||
|
||||
desc "Open the HTML coverage report"
|
||||
task :show_results do
|
||||
system "open test/coverage/index.html"
|
||||
end
|
||||
|
||||
task :full => "test:coverage:clean"
|
||||
task :full => "test:coverage:html"
|
||||
task :full => "test:coverage:show_results"
|
||||
end
|
||||
end
|
||||
rescue LoadError
|
||||
# rcov not available
|
||||
end
|
||||
Reference in New Issue
Block a user