redcuine 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/Rakefile +7 -0
- data/VERSION +1 -1
- data/bin/redissue +1 -0
- data/lib/redcuine/active_resource_ext/print_rest.rb +3 -1
- data/lib/redcuine/base.rb +1 -1
- data/lib/redcuine/config_setup.rb +4 -3
- data/lib/redcuine/config_template.erb +4 -4
- data/lib/redcuine/issue.rb +24 -29
- data/lib/redcuine/optparser.rb +1 -1
- data/lib/redcuine.rb +0 -1
- data/redcuine.gemspec +13 -3
- data/test/config_setup_test.rb +9 -0
- data/test/issue_test.rb +106 -0
- data/test/optparser_test.rb +37 -0
- data/test/test_helper.rb +27 -0
- metadata +12 -5
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -12,3 +12,10 @@ begin
|
|
12
12
|
rescue LoadError
|
13
13
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
14
14
|
end
|
15
|
+
|
16
|
+
require 'rake/testtask'
|
17
|
+
Rake::TestTask.new do |t|
|
18
|
+
t.libs << "lib"
|
19
|
+
t.libs << "test"
|
20
|
+
t.test_files = FileList["test/*_test.rb"]
|
21
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/bin/redissue
CHANGED
@@ -2,7 +2,9 @@ module ActiveResource
|
|
2
2
|
class Connection
|
3
3
|
def request_with_print(method, path, *arguments)
|
4
4
|
puts "#{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}"
|
5
|
-
request_without_print(method, path, *arguments)
|
5
|
+
res = request_without_print(method, path, *arguments)
|
6
|
+
puts res if Redcuine::CONFIG["debug"]
|
7
|
+
return res
|
6
8
|
end
|
7
9
|
alias_method_chain :request, :print
|
8
10
|
end
|
data/lib/redcuine/base.rb
CHANGED
@@ -6,18 +6,19 @@ module Redcuine
|
|
6
6
|
module_function
|
7
7
|
|
8
8
|
def run
|
9
|
-
unless File.exists?(
|
9
|
+
unless File.exists?(CONF_FILE)
|
10
10
|
template = open(File.dirname(__FILE__) + '/config_template.erb').read
|
11
11
|
config = ERB.new(template, nil, '-').result(binding)
|
12
|
-
Dir.mkdir(CONF_DIR)
|
12
|
+
Dir.mkdir(CONF_DIR) unless File.exists?(CONF_DIR)
|
13
13
|
File.open(CONF_FILE, 'w', 0600) {|io|
|
14
14
|
io << config
|
15
15
|
}
|
16
16
|
|
17
17
|
puts "generated: ~/.redcuine/config.yml"
|
18
18
|
puts "Please setup it."
|
19
|
-
|
19
|
+
return false
|
20
20
|
end
|
21
|
+
return true
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/lib/redcuine/issue.rb
CHANGED
@@ -1,22 +1,19 @@
|
|
1
1
|
module Redcuine
|
2
2
|
class Issue < Base
|
3
|
+
@@default_param = {}
|
4
|
+
@@issue_attribute_keys = [:subject, :description, :tracker_id, :status_id,
|
5
|
+
:category_id, :assigned_to, :priority, :fixed_version,
|
6
|
+
:start_date, :due_date, :estimate_date, :done_ratio]
|
7
|
+
|
3
8
|
def self.run
|
4
9
|
if super
|
5
|
-
|
6
|
-
return
|
10
|
+
@@default_param = {:key => CONFIG["api_key"]} if CONFIG["enable_api_key"]
|
11
|
+
return self.send(CONFIG['rest_type'])
|
7
12
|
end
|
8
13
|
return false
|
9
14
|
end
|
10
15
|
|
11
|
-
def
|
12
|
-
if CONFIG["enable_api_key"]
|
13
|
-
@default_param = {:key => CONFIG["api_key"]}
|
14
|
-
else
|
15
|
-
@default_param = {}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def get
|
16
|
+
def self.get
|
20
17
|
CONFIG["id"] ? show(CONFIG["id"]) : index
|
21
18
|
rescue
|
22
19
|
puts $!.to_s
|
@@ -25,11 +22,9 @@ module Redcuine
|
|
25
22
|
return false
|
26
23
|
end
|
27
24
|
|
28
|
-
def post
|
29
|
-
keys = [:project_id
|
30
|
-
|
31
|
-
:start_date, :due_date, :estimate_date, :done_ratio]
|
32
|
-
opts = rest_options(keys, @default_param)
|
25
|
+
def self.post
|
26
|
+
keys = [:project_id] + @@issue_attribute_keys
|
27
|
+
opts = rest_options(keys, @@default_param)
|
33
28
|
issue = Resource::Issue.new(opts)
|
34
29
|
res = issue.save
|
35
30
|
puts res ? "Created issue!" : "Fail to create issue."
|
@@ -41,11 +36,9 @@ module Redcuine
|
|
41
36
|
return false
|
42
37
|
end
|
43
38
|
|
44
|
-
def put
|
45
|
-
keys =
|
46
|
-
|
47
|
-
:start_date, :due_date, :estimate_date, :done_ratio]
|
48
|
-
opts = rest_options(keys, @default_param)
|
39
|
+
def self.put
|
40
|
+
keys = @@issue_attribute_keys
|
41
|
+
opts = rest_options(keys, @@default_param)
|
49
42
|
issue = Resource::Issue.find(CONFIG["id"])
|
50
43
|
issue.load(opts)
|
51
44
|
res = issue.save
|
@@ -58,7 +51,7 @@ module Redcuine
|
|
58
51
|
return false
|
59
52
|
end
|
60
53
|
|
61
|
-
def delete
|
54
|
+
def self.delete
|
62
55
|
issue = Resource::Issue.find(CONFIG["id"])
|
63
56
|
res = issue.destroy
|
64
57
|
puts res ? "Destroyed issue!" : "Fail to destroy issue."
|
@@ -82,26 +75,28 @@ module Redcuine
|
|
82
75
|
puts "Please input --id."
|
83
76
|
return false
|
84
77
|
end
|
85
|
-
if CONFIG['rest_type'] == :post && CONFIG['project_id']
|
78
|
+
if CONFIG['rest_type'] == :post && CONFIG['project_id'].blank?
|
86
79
|
puts "Please input --project-id."
|
87
80
|
return false
|
88
81
|
end
|
89
82
|
return true
|
90
83
|
end
|
91
84
|
|
92
|
-
def show(id)
|
93
|
-
issue = Resource::Issue.find(CONFIG["id"], :params =>
|
85
|
+
def self.show(id)
|
86
|
+
issue = Resource::Issue.find(CONFIG["id"], :params => @@default_param)
|
94
87
|
print_get_format(issue)
|
88
|
+
return true
|
95
89
|
end
|
96
90
|
|
97
|
-
def index
|
91
|
+
def self.index
|
98
92
|
opts = rest_options([:project_id, :tracker_id, :assigned_to, :status_id],
|
99
|
-
|
93
|
+
@@default_param)
|
100
94
|
res = Resource::Issue.find(:all, :params => opts)
|
101
|
-
res.each {|issue| print_get_format(issue)}
|
95
|
+
res.each {|issue| print_get_format(issue)} if res
|
96
|
+
return true
|
102
97
|
end
|
103
98
|
|
104
|
-
def print_get_format(issue)
|
99
|
+
def self.print_get_format(issue)
|
105
100
|
puts "- id: #{issue.id}"
|
106
101
|
%w(project status priority author assigned_to fixed_version).each do |k|
|
107
102
|
if issue.respond_to?(k)
|
data/lib/redcuine/optparser.rb
CHANGED
@@ -31,7 +31,7 @@ module Redcuine
|
|
31
31
|
opt.program_name = 'redissue'
|
32
32
|
|
33
33
|
default_opts(opt)
|
34
|
-
%w(id subject
|
34
|
+
%w(id subject description tracker-id status-id category-id assigned-to
|
35
35
|
priority fixed-version start-date due-date estimate-date
|
36
36
|
done-ratio site project-id).each do |k|
|
37
37
|
src = <<-SRC
|
data/lib/redcuine.rb
CHANGED
data/redcuine.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{redcuine}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Narihiro Nakmaura"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-30}
|
13
13
|
s.default_executable = %q{redissue}
|
14
14
|
s.description = %q{CUI toolkit for Redmine}
|
15
15
|
s.email = %q{authornari@gmail.com}
|
@@ -32,12 +32,22 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/redcuine/issue.rb",
|
33
33
|
"lib/redcuine/optparser.rb",
|
34
34
|
"lib/redcuine/resource.rb",
|
35
|
-
"redcuine.gemspec"
|
35
|
+
"redcuine.gemspec",
|
36
|
+
"test/config_setup_test.rb",
|
37
|
+
"test/issue_test.rb",
|
38
|
+
"test/optparser_test.rb",
|
39
|
+
"test/test_helper.rb"
|
36
40
|
]
|
37
41
|
s.homepage = %q{https://github.com/authorNari/redcuine}
|
38
42
|
s.require_paths = ["lib"]
|
39
43
|
s.rubygems_version = %q{1.3.7}
|
40
44
|
s.summary = %q{CUI toolkit for Redmine}
|
45
|
+
s.test_files = [
|
46
|
+
"test/config_setup_test.rb",
|
47
|
+
"test/issue_test.rb",
|
48
|
+
"test/optparser_test.rb",
|
49
|
+
"test/test_helper.rb"
|
50
|
+
]
|
41
51
|
|
42
52
|
if s.respond_to? :specification_version then
|
43
53
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/test/issue_test.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class IssueTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
Redcuine::CONFIG["site"] = "http://localhost:3000/"
|
7
|
+
Redcuine::CONFIG["user"] = "user"
|
8
|
+
Redcuine::CONFIG["password"] = "password"
|
9
|
+
Redcuine::CONFIG["rest_type"] = :get
|
10
|
+
Redcuine::Issue.class_variable_set("@@default_param", {})
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_run
|
14
|
+
stub(Redcuine::Resource::Issue).find{[]}
|
15
|
+
assert_equal true, Redcuine::Issue.run
|
16
|
+
assert_equal({},
|
17
|
+
Redcuine::Issue.class_variable_get("@@default_param"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_run_with_api_key
|
21
|
+
stub(Redcuine::Resource::Issue).find{[]}
|
22
|
+
Redcuine::CONFIG["enable_api_key"] = true
|
23
|
+
assert_equal true, Redcuine::Issue.run
|
24
|
+
assert_equal({:key => Redcuine::CONFIG["api_key"]},
|
25
|
+
Redcuine::Issue.class_variable_get("@@default_param"))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_get
|
29
|
+
@opts = nil
|
30
|
+
stub(Redcuine::Resource::Issue).find{|_, o| @opts = o; []}
|
31
|
+
Redcuine::CONFIG["rest_type"] = :get
|
32
|
+
Redcuine::CONFIG["project_id"] = "1"
|
33
|
+
Redcuine::CONFIG["tracker_id"] = "2"
|
34
|
+
Redcuine::CONFIG["assigned_to"] = "3"
|
35
|
+
Redcuine::CONFIG["status_id"] = "4"
|
36
|
+
assert_equal true, Redcuine::Issue.run
|
37
|
+
assert_equal({:params => {:project_id => "1",
|
38
|
+
:tracker_id => "2",
|
39
|
+
:assigned_to => "3",
|
40
|
+
:status_id => "4"}},
|
41
|
+
@opts)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_get_with_id
|
45
|
+
@id = nil
|
46
|
+
stub(Redcuine::Resource::Issue).find do |id|
|
47
|
+
@id = id
|
48
|
+
OpenStruct.new
|
49
|
+
end
|
50
|
+
Redcuine::CONFIG["rest_type"] = :get
|
51
|
+
Redcuine::CONFIG["id"] = "1"
|
52
|
+
assert_equal true, Redcuine::Issue.run
|
53
|
+
assert_equal("1", @id)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_post
|
57
|
+
@opt = nil
|
58
|
+
stub(Redcuine::Resource::Issue).new do |opt|
|
59
|
+
@opt = opt
|
60
|
+
o = Object.new
|
61
|
+
o.instance_eval("def save; true; end")
|
62
|
+
o
|
63
|
+
end
|
64
|
+
Redcuine::CONFIG["rest_type"] = :post
|
65
|
+
Redcuine::CONFIG["project_id"] = "1"
|
66
|
+
keys = [:subject, :description, :tracker_id, :status_id,
|
67
|
+
:category_id, :assigned_to, :priority, :fixed_version,
|
68
|
+
:start_date, :due_date, :estimate_date, :done_ratio]
|
69
|
+
keys.each do |k|
|
70
|
+
Redcuine::CONFIG[k.to_s] = true
|
71
|
+
end
|
72
|
+
assert_equal true, Redcuine::Issue.run
|
73
|
+
assert_equal([], keys - @opt.keys)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_post_fail
|
77
|
+
Redcuine::CONFIG["rest_type"] = :post
|
78
|
+
assert_equal false, Redcuine::Issue.run
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_put
|
82
|
+
stub(Redcuine::Resource::Issue).find do |id|
|
83
|
+
@id = id
|
84
|
+
@obj = Object.new
|
85
|
+
@obj.instance_eval("def save; true; end")
|
86
|
+
@obj.instance_eval("def load(args); @opt = args; end")
|
87
|
+
@obj
|
88
|
+
end
|
89
|
+
Redcuine::CONFIG["rest_type"] = :put
|
90
|
+
Redcuine::CONFIG["id"] = "1"
|
91
|
+
keys = [:subject, :description, :tracker_id, :status_id,
|
92
|
+
:category_id, :assigned_to, :priority, :fixed_version,
|
93
|
+
:start_date, :due_date, :estimate_date, :done_ratio]
|
94
|
+
keys.each do |k|
|
95
|
+
Redcuine::CONFIG[k.to_s] = true
|
96
|
+
end
|
97
|
+
assert_equal true, Redcuine::Issue.run
|
98
|
+
assert_equal("1", @id)
|
99
|
+
assert_equal([], keys - @obj.instance_variable_get("@opt").keys)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_put_fail
|
103
|
+
Redcuine::CONFIG["rest_type"] = :put
|
104
|
+
assert_equal false, Redcuine::Issue.run
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class OptParserTest < Test::Unit::TestCase
|
4
|
+
def test_parse_default_opts
|
5
|
+
Redcuine::OptParser.issue_parse!(%w(-p))
|
6
|
+
assert_equal :post, Redcuine::CONFIG["rest_type"]
|
7
|
+
Redcuine::OptParser.issue_parse!(%w(-g))
|
8
|
+
assert_equal :get, Redcuine::CONFIG["rest_type"]
|
9
|
+
Redcuine::OptParser.issue_parse!(%w(-u))
|
10
|
+
assert_equal :put, Redcuine::CONFIG["rest_type"]
|
11
|
+
Redcuine::OptParser.issue_parse!(%w(-d))
|
12
|
+
assert_equal :delete, Redcuine::CONFIG["rest_type"]
|
13
|
+
|
14
|
+
Redcuine::OptParser.issue_parse!(%w(--post))
|
15
|
+
assert_equal :post, Redcuine::CONFIG["rest_type"]
|
16
|
+
Redcuine::OptParser.issue_parse!(%w(--get))
|
17
|
+
assert_equal :get, Redcuine::CONFIG["rest_type"]
|
18
|
+
Redcuine::OptParser.issue_parse!(%w(--put))
|
19
|
+
assert_equal :put, Redcuine::CONFIG["rest_type"]
|
20
|
+
Redcuine::OptParser.issue_parse!(%w(--delete))
|
21
|
+
assert_equal :delete, Redcuine::CONFIG["rest_type"]
|
22
|
+
|
23
|
+
Redcuine::OptParser.issue_parse!(%w(--debug))
|
24
|
+
assert_equal true, Redcuine::CONFIG["debug"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_issue_parse
|
28
|
+
opts = %w(id subject description tracker-id status-id
|
29
|
+
category-id assigned-to priority fixed-version
|
30
|
+
start-date due-date estimate-date done-ratio site project-id)
|
31
|
+
args = opts.map{|k| ["--#{k}", k]}.flatten
|
32
|
+
Redcuine::OptParser.issue_parse!(args)
|
33
|
+
opts.each do |o|
|
34
|
+
assert_equal o, Redcuine::CONFIG[o.gsub("-", "_")]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "tmpdir"
|
3
|
+
require "rr"
|
4
|
+
|
5
|
+
module Redcuine
|
6
|
+
CONF_DIR = Dir.tmpdir
|
7
|
+
CONF_FILE = File.join(Redcuine::CONF_DIR, '__recuine_test__config.yml')
|
8
|
+
end
|
9
|
+
require "redcuine"
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
super
|
14
|
+
setup_with_clear_config
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
super
|
19
|
+
FileUtils.rm(Redcuine::CONF_FILE) if File.exist?(Redcuine::CONF_FILE)
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup_with_clear_config
|
23
|
+
Redcuine::CONFIG.clear
|
24
|
+
end
|
25
|
+
|
26
|
+
include RR::Adapters::RRMethods
|
27
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Narihiro Nakmaura
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-30 00:00:00 +09:00
|
18
18
|
default_executable: redissue
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -56,6 +56,10 @@ files:
|
|
56
56
|
- lib/redcuine/optparser.rb
|
57
57
|
- lib/redcuine/resource.rb
|
58
58
|
- redcuine.gemspec
|
59
|
+
- test/config_setup_test.rb
|
60
|
+
- test/issue_test.rb
|
61
|
+
- test/optparser_test.rb
|
62
|
+
- test/test_helper.rb
|
59
63
|
has_rdoc: true
|
60
64
|
homepage: https://github.com/authorNari/redcuine
|
61
65
|
licenses: []
|
@@ -88,5 +92,8 @@ rubygems_version: 1.3.7
|
|
88
92
|
signing_key:
|
89
93
|
specification_version: 3
|
90
94
|
summary: CUI toolkit for Redmine
|
91
|
-
test_files:
|
92
|
-
|
95
|
+
test_files:
|
96
|
+
- test/config_setup_test.rb
|
97
|
+
- test/issue_test.rb
|
98
|
+
- test/optparser_test.rb
|
99
|
+
- test/test_helper.rb
|