ki_middleman 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/assets/default_transforms.rb +2 -2
- data/bin/ki_middleman +14 -6
- data/ki_middleman.gemspec +1 -0
- data/lib/ki_middleman/config.rb +5 -1
- data/lib/ki_middleman/version.rb +1 -1
- data/lib/ki_middleman.rb +1 -1
- data/spec/integration/convert_spec.rb +22 -2
- metadata +24 -13
@@ -1,8 +1,8 @@
|
|
1
1
|
from :youtrack_issue do |issue|
|
2
2
|
to :pivotal_story do
|
3
3
|
{
|
4
|
-
"name" => "[#{issue
|
5
|
-
"description" =>"Youtrack: #{issue
|
4
|
+
"name" => "[#{issue.id}] #{issue.summary}",
|
5
|
+
"description" =>"Youtrack: #{issue.issue_url}\n#{issue.description}",
|
6
6
|
"requested_by" => "Kiseru",
|
7
7
|
"story_type" => "bug"
|
8
8
|
}
|
data/bin/ki_middleman
CHANGED
@@ -24,13 +24,21 @@ main do |arg|
|
|
24
24
|
if options[:init]
|
25
25
|
init
|
26
26
|
elsif options[:to]
|
27
|
-
|
27
|
+
begin
|
28
|
+
pretty = $stdout.tty?
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
output_type = options[:to]
|
31
|
+
config = KiMiddleman::Config.from_file(Kiseru::ConfigDir.new.file('transforms.rb'))
|
32
|
+
input = MultiJson.load($stdin.read)
|
33
|
+
output = config.convert_data_to_format(input, output_type)
|
34
|
+
$stdout.write MultiJson.dump(output, :pretty => pretty)
|
35
|
+
rescue MultiJson::DecodeError => e
|
36
|
+
$stderr.puts "Invalid JSON"
|
37
|
+
exit 1
|
38
|
+
rescue KiMiddleman::ConfigError => e
|
39
|
+
$stderr.puts e.message
|
40
|
+
exit 1
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
data/ki_middleman.gemspec
CHANGED
data/lib/ki_middleman/config.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module KiMiddleman
|
2
2
|
|
3
|
+
class ConfigError < StandardError; end;
|
4
|
+
|
3
5
|
class Config
|
4
6
|
|
5
7
|
def self.from_file(path)
|
@@ -13,6 +15,7 @@ module KiMiddleman
|
|
13
15
|
|
14
16
|
def detect_from_format(data)
|
15
17
|
@from_format = data['ki_type']
|
18
|
+
raise ConfigError, "Cannot convert from unknown type. Include 'ki_type' in JSON" if @from_format.nil?
|
16
19
|
end
|
17
20
|
|
18
21
|
def set_parsing_context
|
@@ -27,8 +30,9 @@ module KiMiddleman
|
|
27
30
|
self.detect_from_format(data)
|
28
31
|
@format_to_evaluate = format
|
29
32
|
self.set_evaluation_context
|
33
|
+
raise ConfigError, "No transform from '#{@from_format}' found." unless @mapping.has_key?(@from_format.to_sym)
|
30
34
|
evaluation_context = @mapping[@from_format.to_sym][:outer_block]
|
31
|
-
converted_data = evaluation_context.call data
|
35
|
+
converted_data = evaluation_context.call Map.new(data)
|
32
36
|
converted_data['ki_type'] = format
|
33
37
|
|
34
38
|
converted_data
|
data/lib/ki_middleman/version.rb
CHANGED
data/lib/ki_middleman.rb
CHANGED
@@ -34,8 +34,28 @@ JSON
|
|
34
34
|
output['summary'].should == "[123] Something broke"
|
35
35
|
end
|
36
36
|
|
37
|
-
it "
|
38
|
-
|
37
|
+
it "can use . syntax" do
|
38
|
+
config = KiMiddleman::Config.parse <<-RUBY
|
39
|
+
from(:bug) do |bug|
|
40
|
+
to(:story) do
|
41
|
+
{
|
42
|
+
'summary' => bug.name
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
RUBY
|
47
|
+
input_json =<<-JSON
|
48
|
+
{
|
49
|
+
"ki_type" : "bug",
|
50
|
+
"name" : "Hello"
|
51
|
+
}
|
52
|
+
JSON
|
53
|
+
|
54
|
+
input = MultiJson.load(input_json)
|
55
|
+
|
56
|
+
output = config.convert_data_to_format(input, 'story')
|
57
|
+
|
58
|
+
output['summary'].should == "Hello"
|
39
59
|
end
|
40
60
|
|
41
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ki_middleman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-08-15 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
17
|
-
requirement: &
|
17
|
+
requirement: &70310574886120 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70310574886120
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: methadone
|
28
|
-
requirement: &
|
28
|
+
requirement: &70310574885700 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,21 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70310574885700
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: map
|
39
|
+
requirement: &70310574885280 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70310574885280
|
37
48
|
- !ruby/object:Gem::Dependency
|
38
49
|
name: debugger
|
39
|
-
requirement: &
|
50
|
+
requirement: &70310574884860 !ruby/object:Gem::Requirement
|
40
51
|
none: false
|
41
52
|
requirements:
|
42
53
|
- - ! '>='
|
@@ -44,10 +55,10 @@ dependencies:
|
|
44
55
|
version: '0'
|
45
56
|
type: :development
|
46
57
|
prerelease: false
|
47
|
-
version_requirements: *
|
58
|
+
version_requirements: *70310574884860
|
48
59
|
- !ruby/object:Gem::Dependency
|
49
60
|
name: rake
|
50
|
-
requirement: &
|
61
|
+
requirement: &70310586012480 !ruby/object:Gem::Requirement
|
51
62
|
none: false
|
52
63
|
requirements:
|
53
64
|
- - ! '>='
|
@@ -55,10 +66,10 @@ dependencies:
|
|
55
66
|
version: '0'
|
56
67
|
type: :development
|
57
68
|
prerelease: false
|
58
|
-
version_requirements: *
|
69
|
+
version_requirements: *70310586012480
|
59
70
|
- !ruby/object:Gem::Dependency
|
60
71
|
name: simplecov
|
61
|
-
requirement: &
|
72
|
+
requirement: &70310586012060 !ruby/object:Gem::Requirement
|
62
73
|
none: false
|
63
74
|
requirements:
|
64
75
|
- - ! '>='
|
@@ -66,10 +77,10 @@ dependencies:
|
|
66
77
|
version: '0'
|
67
78
|
type: :development
|
68
79
|
prerelease: false
|
69
|
-
version_requirements: *
|
80
|
+
version_requirements: *70310586012060
|
70
81
|
- !ruby/object:Gem::Dependency
|
71
82
|
name: rspec
|
72
|
-
requirement: &
|
83
|
+
requirement: &70310586011640 !ruby/object:Gem::Requirement
|
73
84
|
none: false
|
74
85
|
requirements:
|
75
86
|
- - ! '>='
|
@@ -77,7 +88,7 @@ dependencies:
|
|
77
88
|
version: '0'
|
78
89
|
type: :development
|
79
90
|
prerelease: false
|
80
|
-
version_requirements: *
|
91
|
+
version_requirements: *70310586011640
|
81
92
|
description: Transforms JSON into other JSON
|
82
93
|
email:
|
83
94
|
- ben@freeagent.com
|