Created
August 22, 2015 08:14
-
-
Save vividtone/271a6a7ece6cfb5f565e to your computer and use it in GitHub Desktop.
CSVファイルを読み込んで、REST API経由でRedmineにウォッチャーを追加する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
# | |
# CSVファイルを読み込んで、REST API経由でRedmineにウォッチャーを追加する | |
# | |
# CSVファイルの形式: | |
# チケットID番号,ユーザーID番号 | |
# | |
# 実行方法: | |
# ruby add_redmine_watcher.rb csv_file_name | |
require 'rest-client' # gem install rest-client | |
require 'open-uri' | |
require 'json' | |
require 'csv' | |
REDMINE_USER = 'manager' # 「ウォッチャーの追加」権限が必要 | |
REDMINE_PASSWORD = 'manager' | |
REDMINE_URL = 'http://redmine.example.jp' | |
line_no = 0 | |
CSV.parse(ARGF.read) do |row| | |
line_no += 1 | |
(issue_id, user_id) = row | |
begin | |
RestClient::Request.execute( | |
:method => :post, | |
:url => "#{REDMINE_URL}/issues/#{issue_id}/watchers.json", | |
:user => REDMINE_USER, | |
:password => REDMINE_PASSWORD, | |
:payload => {:user_id => user_id}.to_json, | |
:headers => { | |
:content_type => 'application/json' | |
} | |
) | |
STDERR.puts "#{ARGF.filename}:#{line_no}: success" | |
rescue => e | |
STDERR.puts "#{ARGF.filename}:#{line_no}: error: #{e.message}: data = #{row.inspect}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment