職場でredmineをちょくちょく使っているのですが、ほんとにお手軽で便利なツールですね。

チケット一覧のチェックボックスって何のためにあるのかなー、と思っていたのですが、チェックしたチケットに大して右クリックが使えたのにはビックリしました.
VBでチケット登録する方法が公開されていたので、Rubyでマネしてみたらうごきました。

チケット一覧のチェックボックスって何のためにあるのかなー、と思っていたのですが、チェックしたチケットに大して右クリックが使えたのにはビックリしました.
VBでチケット登録する方法が公開されていたので、Rubyでマネしてみたらうごきました。
require 'rubygems'
require 'httpclient'
require 'tmail'
require 'kconv'
require 'cgi'
require 'csv'
class Ticket_poster
#global setting
def initialize(url, api_key, posted)
@url = url
@api_key = api_key
@posted = posted
end
def post_ticket(title, project, tracker, description)
body = "#{description} \r\nProject: #{project}\r\nTracker: #{tracker}\r\n 日本語"
# creating mail
mail = TMail::Mail.new
mail.to = 'admin@example.com'
mail.from = @posted
work = Kconv.tosjis(title).split(//,1).pack('m').chomp
mail.subject = "=?ISO-2022-JP?B?" + work.gsub('\n','') + "?="
mail.date = Time.now
mail.set_content_type 'text', 'plain', {'charset'=>'iso-2022-jp'}
mail.body = Kconv.tojis(body)
c = HTTPClient.new
c.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
postdata = { "key" => @api_key, "allow_override" => "tracker,category,prioity",
"email" => mail.to_s }
puts c.post_content(@url, postdata,
"content-type" => "application/x-www-form-urlencoded")
end
end
url = "https://example.com/mail_handler"
api_key = "hogehoge"
posted = "hoge@example.com"
title_ = "タイトル"
project_ = "doc-manage"
tracker_ = "バグ"
description_ = "行一\r\n行二"
#ticket post するオブジェクトを準備
poster = Ticket_poster.new(url, api_key, posted)
#第一引数にCSVファイル名を指定
#1カラム目にtitle
#2カラム目にproject
#3カラム目にtracker
#4カラム目にdescription
CSV.foreach(ARGV[0]){|row|
title = row[0].toutf8
project = row[1].toutf8
tracker = row[2].toutf8
description = row[3].toutf8
next if title == "title"
#postする
poster.post_ticket(title, project, tracker, description)
}
コメント