有人可以看看我的 rakefile 的语法吗?

发布于 2024-07-07 11:17:34 字数 3112 浏览 9 评论 0原文

我正在尝试为Redmine 编写一个导入rakefile。 它在轨道上使用红宝石。 我不是 Rails 开发人员,但我们确实喜欢使用 redmine 进行项目和问题管理。

require 'rubygmes'
require 'fastercsv'

# csv issues import for redmine
# Will convert a csv into a issues bulkloader into redmine
# Column names
# row[0]=Nb Number,row[1]=Product,row[2]=Element,row[3]=Type,row[4]=Queue,
# row[5]=KeyWord,row[6]=Responsible,row[7]=Case Descriptions,row[8]=Days,
# row[9]=Planned Delivery,row[10]=Version
#


desc <<-END_DESC
Bulk loading of issues from a CSV file.

Available options:
  * filepath    => path to the text file.
  * project     => id or identifier of project

Example:
  rake redmine:csv_import filepath="~/import.csv" project="askiavista"
END_DESC

namespace :redmine do
    task :csv_import => :environment do
    @firstrow = true
    @count = 1

    FasterCSV.foreach(ENV['filepath']) do |row|
        if not firstrow
            @i = Issue.new
                @i.project = Project.find_by_name(ENV['project'])
                # If not a feature it's a bug
                if row[3].contains("SUG")
                    @i.tracker = Tracker.find_by_id(2)
                else
                    @i.tracker = Tracker.find_by_id(1)
                end

                if row[4].contains("TOP PRIORITY")
                    @i.priority = Enumeration.find_by_id(7)
                elseif row[4].contains("HIGH PRIORITY")
                    @i.priority = Enumeration.find_by_id(5)
                elseif row[4].contains("MEDIUM PRIORITY")
                    @i.priority = Enumeration.find_by_id(4)
                else
                    @i.priority = Enumeration.find_by_id(3)
                end

                @i.author = Users.find(5)
                @i.subject = truncate(row[4], 50)
                @i.description = row[4]
                @i.status = IssuesStatus.find_by_id(1)
            @i.save
            count += 1
        end
        firstrow = nil
    end
    end
end

当我运行它时,出现此错误:

    (in /var/lib/redmine-0.7-dev)
rake aborted!
Don't know how to build task 'redmine:csv_import.rake'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1634:in `[]'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1930:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

我环顾四周,看到其他用户也遇到此问题,但没有找到解决方案。 这应该是一个快速脚本,可以将数百个错误和功能导入到 redmine 中。

我已经更新了我的 rakefile。 新错误。 我想这可能是我正在寻找的文本模式。 我不确定 ruby​​ 是否有“包含”方法来搜索字符串中的关键字。

I'm trying to write an import rakefile for Redmine. It uses ruby on rails. I'm not a rails developer but we do like using redmine for project and issues management.

require 'rubygmes'
require 'fastercsv'

# csv issues import for redmine
# Will convert a csv into a issues bulkloader into redmine
# Column names
# row[0]=Nb Number,row[1]=Product,row[2]=Element,row[3]=Type,row[4]=Queue,
# row[5]=KeyWord,row[6]=Responsible,row[7]=Case Descriptions,row[8]=Days,
# row[9]=Planned Delivery,row[10]=Version
#


desc <<-END_DESC
Bulk loading of issues from a CSV file.

Available options:
  * filepath    => path to the text file.
  * project     => id or identifier of project

Example:
  rake redmine:csv_import filepath="~/import.csv" project="askiavista"
END_DESC

namespace :redmine do
    task :csv_import => :environment do
    @firstrow = true
    @count = 1

    FasterCSV.foreach(ENV['filepath']) do |row|
        if not firstrow
            @i = Issue.new
                @i.project = Project.find_by_name(ENV['project'])
                # If not a feature it's a bug
                if row[3].contains("SUG")
                    @i.tracker = Tracker.find_by_id(2)
                else
                    @i.tracker = Tracker.find_by_id(1)
                end

                if row[4].contains("TOP PRIORITY")
                    @i.priority = Enumeration.find_by_id(7)
                elseif row[4].contains("HIGH PRIORITY")
                    @i.priority = Enumeration.find_by_id(5)
                elseif row[4].contains("MEDIUM PRIORITY")
                    @i.priority = Enumeration.find_by_id(4)
                else
                    @i.priority = Enumeration.find_by_id(3)
                end

                @i.author = Users.find(5)
                @i.subject = truncate(row[4], 50)
                @i.description = row[4]
                @i.status = IssuesStatus.find_by_id(1)
            @i.save
            count += 1
        end
        firstrow = nil
    end
    end
end

When I ran it I get this error:

    (in /var/lib/redmine-0.7-dev)
rake aborted!
Don't know how to build task 'redmine:csv_import.rake'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1634:in `[]'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1930:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

I've looked around and I see other users with this problem but no solution is found. This is supposed to be a quick script to import a few hundred bugs and features into redmine.

I've updated my rakefile. New error. I think it might be the text patterns I'm looking for. I'm not sure if ruby has a "contains" methods to search a string for keyword.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然#的苍凉 2024-07-14 11:17:34

您缺少

end

关闭名称空间所需的信息。

添加额外内容

end

要修复,请在文件末尾

you are missing the

end

required to close the namespace.

To fix, put an extra

end

at the end of the file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文