embulk-input-jira 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -5
  3. data/.travis.yml +4 -34
  4. data/CHANGELOG.md +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +5 -4
  7. data/build.gradle +116 -0
  8. data/config/checkstyle/checkstyle.xml +128 -0
  9. data/config/checkstyle/default.xml +108 -0
  10. data/gradle/wrapper/gradle-wrapper.jar +0 -0
  11. data/gradle/wrapper/gradle-wrapper.properties +5 -0
  12. data/gradlew +172 -0
  13. data/gradlew.bat +84 -0
  14. data/lib/embulk/guess/jira.rb +24 -0
  15. data/lib/embulk/input/jira.rb +3 -169
  16. data/src/main/java/org/embulk/input/jira/AuthenticateMethod.java +27 -0
  17. data/src/main/java/org/embulk/input/jira/Constant.java +17 -0
  18. data/src/main/java/org/embulk/input/jira/Issue.java +150 -0
  19. data/src/main/java/org/embulk/input/jira/JiraInputPlugin.java +226 -0
  20. data/src/main/java/org/embulk/input/jira/client/JiraClient.java +254 -0
  21. data/src/main/java/org/embulk/input/jira/util/JiraException.java +18 -0
  22. data/src/main/java/org/embulk/input/jira/util/JiraUtil.java +264 -0
  23. data/src/test/java/org/embulk/input/jira/IssueTest.java +278 -0
  24. data/src/test/java/org/embulk/input/jira/JiraInputPluginTest.java +204 -0
  25. data/src/test/java/org/embulk/input/jira/JiraPluginTestRuntime.java +133 -0
  26. data/src/test/java/org/embulk/input/jira/TestHelpers.java +41 -0
  27. data/src/test/java/org/embulk/input/jira/client/JiraClientTest.java +222 -0
  28. data/src/test/java/org/embulk/input/jira/util/JiraUtilTest.java +318 -0
  29. data/src/test/resources/config.yml +13 -0
  30. data/src/test/resources/issue_flatten.json +129 -0
  31. data/src/test/resources/issue_flatten_expected.json +73 -0
  32. data/src/test/resources/issue_get.json +36 -0
  33. data/src/test/resources/issue_get_expected.json +62 -0
  34. data/src/test/resources/jira_client.json +81 -0
  35. data/src/test/resources/jira_input_plugin.json +114 -0
  36. data/src/test/resources/jira_util.json +26 -0
  37. metadata +55 -175
  38. data/Gemfile +0 -3
  39. data/LICENSE +0 -13
  40. data/Rakefile +0 -15
  41. data/embulk-input-jira.gemspec +0 -27
  42. data/gemfiles/embulk-0.8.0-latest +0 -4
  43. data/gemfiles/embulk-0.8.7 +0 -4
  44. data/gemfiles/embulk-0.8.8 +0 -4
  45. data/gemfiles/embulk-latest +0 -4
  46. data/gemfiles/template.erb +0 -4
  47. data/lib/embulk/input/jira_api.rb +0 -9
  48. data/lib/embulk/input/jira_api/client.rb +0 -144
  49. data/lib/embulk/input/jira_api/issue.rb +0 -133
  50. data/lib/embulk/input/jira_input_plugin_utils.rb +0 -58
  51. data/spec/embulk/input/jira-input-plugin-utils_spec.rb +0 -89
  52. data/spec/embulk/input/jira_api/client_spec.rb +0 -224
  53. data/spec/embulk/input/jira_api/issue_spec.rb +0 -394
  54. data/spec/embulk/input/jira_spec.rb +0 -322
  55. data/spec/embulk_spec.rb +0 -32
  56. data/spec/spec_helper.rb +0 -26
  57. data/spec/support/stdout_and_err_capture.rb +0 -45
@@ -1,322 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Embulk::Input::Jira do
4
- let(:username) { "jira-user" }
5
- let(:password) { "password" }
6
- let(:uri) { "http://jira.example/" }
7
- let(:jql) { "PROJECT=#{project_name}" }
8
- let(:project_name) { "FOO" }
9
-
10
- describe ".transaction" do
11
- subject { described_class.transaction(config, &control) }
12
-
13
- let(:config) { Object.new } # add mock later
14
- let(:control) { Proc.new{|task, columns, count| } } # do nothing
15
-
16
- let(:task) do
17
- {
18
- username: username,
19
- password: password,
20
- uri: uri,
21
- jql: jql,
22
- attributes: {
23
- "project.key" => :string,
24
- "comment.total" => :long
25
- },
26
- retry_limit: 5,
27
- retry_initial_wait_sec: 1,
28
- }
29
- end
30
-
31
- let(:columns) do
32
- [
33
- {"name" => "project.key", "type" => "string"},
34
- {"name" => "comment.total", "type" => "long"}
35
- ]
36
- end
37
-
38
- let(:column_structs) do
39
- [
40
- Embulk::Column.new(nil, "project.key", :string),
41
- Embulk::Column.new(nil, "comment.total", :long)
42
- ]
43
- end
44
-
45
- before do
46
- allow(config).to receive(:param).with(:username, :string).and_return(username)
47
- allow(config).to receive(:param).with(:password, :string).and_return(password)
48
- allow(config).to receive(:param).with(:uri, :string).and_return(uri)
49
- allow(config).to receive(:param).with(:jql, :string).and_return(jql)
50
- allow(config).to receive(:param).with(:columns, :array).and_return(columns)
51
- allow(config).to receive(:param).with(:retry_limit, :integer, default: 5).and_return(5)
52
- allow(config).to receive(:param).with(:retry_initial_wait_sec, :integer, default: 1).and_return(1)
53
- end
54
-
55
- # NOTE: I should check other factor, but i don't know it...
56
- it "calls .resume method with proper parameters" do
57
- expect(described_class).to receive(:resume).with(task, column_structs, 1, &control)
58
- subject
59
- end
60
- end
61
-
62
- describe ".resume" do
63
- subject { described_class.resume(task, columns, count, &control) }
64
-
65
- let(:task) do
66
- {
67
- username: username,
68
- password: password,
69
- uri: uri,
70
- jql: jql,
71
- attributes: {
72
- "project.key" => :string,
73
- "comment.total" => :long
74
- }
75
- }
76
- end
77
-
78
- let(:columns) do
79
- [
80
- Embulk::Column.new(nil, "project.key", :string),
81
- Embulk::Column.new(nil, "comment.total", :long)
82
- ]
83
- end
84
-
85
- let(:count) { 1 }
86
- let(:control) { Proc.new{|task, columns, count| } } # do nothing
87
-
88
- let(:next_config_diff) { {} }
89
-
90
- it "returns next_config_diff" do
91
- expect(subject).to eq next_config_diff
92
- end
93
- end
94
-
95
- describe ".guess" do
96
- subject { described_class.guess(config) }
97
-
98
- let(:config) { Object.new } # add mock later
99
-
100
- let(:jira_api) { Embulk::Input::JiraApi::Client.new }
101
- let(:jira_issues) { [Embulk::Input::JiraApi::Issue.new(attributes)] }
102
- let(:attributes) do
103
- {
104
- "id" => "100",
105
- "jira_key" => "FOO-100",
106
- "fields" =>
107
- {
108
- "project" => {
109
- "name" => project_name,
110
- "key" => project_name,
111
- },
112
- "comment" => {
113
- "total" => 0,
114
- "comments" => []
115
- }
116
- }
117
- }
118
- end
119
-
120
- let(:guessed_config) do
121
- {
122
- "columns" => [
123
- {name: "comment.comments", type: :string},
124
- {name: "comment.total", type: :long},
125
- {name: "id", type: :long},
126
- {name: "key", type: :string},
127
- {name: "project.key", type: :string},
128
- {name: "project.name", type: :string},
129
- ]
130
- }
131
- end
132
-
133
- before do
134
- allow(jira_api).to receive(:check_user_credential).with(username).and_return(username)
135
- allow(jira_api).to receive(:search_issues).with(jql, max_results: described_class::GUESS_RECORDS_COUNT).and_return(jira_issues)
136
-
137
- allow(config).to receive(:param).with(:username, :string).and_return(username)
138
- allow(config).to receive(:param).with(:password, :string).and_return(password)
139
- allow(config).to receive(:param).with(:uri, :string).and_return(uri)
140
- allow(config).to receive(:param).with(:jql, :string).and_return(jql)
141
- allow(config).to receive(:param).with(:retry_limit, :integer, anything).and_return(0)
142
- allow(config).to receive(:param).with(:retry_initial_wait_sec, :integer, anything).and_return(0)
143
- end
144
-
145
- it "setup Embulk::Input::JiraApi::Client" do
146
- expect(Embulk::Input::JiraApi::Client).to receive(:setup).and_return(jira_api)
147
- subject
148
- end
149
-
150
- it "returns guessed config" do
151
- allow(Embulk::Input::JiraApi::Client).to receive(:setup).and_return(jira_api)
152
-
153
- expect(subject).to eq guessed_config
154
- end
155
- end
156
-
157
- describe "#init (.new)" do
158
- # NOTE: InputPlugin.initialize calls #init method.
159
-
160
- subject { described_class.new({}, nil, nil, nil) }
161
-
162
- it "setup Embulk::Input::JiraApi::Client" do
163
- expect(Embulk::Input::JiraApi::Client).to receive(:setup)
164
- subject
165
- end
166
-
167
- it "is a Embulk::InputPlugin" do
168
- allow(Embulk::Input::JiraApi::Client).to receive(:setup)
169
- expect(subject).to be_a(Embulk::InputPlugin)
170
- end
171
- end
172
-
173
- describe "#run" do
174
- subject do
175
- allow(plugin).to receive(:logger).and_return(::Logger.new(File::NULL))
176
- silence do
177
- plugin.run
178
- end
179
- end
180
-
181
- let(:plugin) { described_class.new(task, nil, nil, page_builder) }
182
- let(:jira_api) { Embulk::Input::JiraApi::Client.new }
183
- let(:jira_issues) do
184
- (1..total_count).map do |i|
185
- attributes = fields.merge("id" => i.to_s, "jira_key" => "FOO-#{i}")
186
-
187
- Embulk::Input::JiraApi::Issue.new(attributes)
188
- end
189
- end
190
-
191
- let(:total_count) { max_result + 10 }
192
- let(:max_result) { described_class::PER_PAGE }
193
-
194
-
195
- let(:page_builder) { Object.new } # add mock later
196
- let(:task) do
197
- {
198
- jql: jql,
199
- attributes: {"project.key" => "string"}
200
- }
201
- end
202
-
203
- let(:fields) do
204
- {
205
- "fields" =>
206
- {
207
- "project" => {
208
- "key" => project_name,
209
- },
210
- }
211
- }
212
- end
213
-
214
- let(:commit_report) { {} }
215
- let(:username) { "jira-user" }
216
-
217
- before do
218
- allow(jira_api).to receive(:preview?).and_return(false)
219
-
220
- # TODO: create stubs without each `it` expected
221
- allow(Embulk::Input::JiraApi::Client).to receive(:setup).and_return(jira_api)
222
- allow(jira_api).to receive(:check_user_credential).and_return(username)
223
-
224
- 0.step(total_count, max_result) do |start_at|
225
- issues = jira_issues[start_at..(start_at + max_result - 1)]
226
- allow(jira_api).to receive(:search_issues).with(jql, start_at: start_at).and_return(issues)
227
- end
228
- allow(jira_api).to receive(:total_count).and_return(total_count)
229
-
230
- allow(page_builder).to receive(:add).with([project_name])
231
- allow(page_builder).to receive(:finish)
232
- end
233
-
234
- it 'search JIRA issues' do
235
- expect(jira_api).to receive(:search_issues)
236
- subject
237
- end
238
-
239
- it 'page build and finish' do
240
- expect(page_builder).to receive(:add).with([project_name]).exactly(total_count).times
241
- expect(page_builder).to receive(:finish)
242
- subject
243
- end
244
-
245
- it 'returns commit report' do
246
- expect(subject).to eq commit_report
247
- end
248
-
249
- end
250
-
251
- describe "preview" do
252
- let(:plugin) { described_class.new(task, nil, nil, page_builder) }
253
- let(:task) do
254
- {
255
- jql: jql,
256
- attributes: {"project.key" => "string"}
257
- }
258
- end
259
- let(:page_builder) { double("page_builder") }
260
- let(:jira_api) { Embulk::Input::JiraApi::Client.new }
261
- let(:jira_issues) { [Embulk::Input::JiraApi::Issue.new(attributes)] }
262
- let(:username) { "jira-user" }
263
- let(:attributes) do
264
- {
265
- "id" => "100",
266
- "jira_key" => "FOO-100",
267
- "fields" =>
268
- {
269
- "project" => {
270
- "name" => project_name,
271
- "key" => project_name,
272
- },
273
- "comment" => {
274
- "total" => 0,
275
- "comments" => []
276
- }
277
- }
278
- }
279
- end
280
-
281
-
282
- subject { plugin.run }
283
-
284
- before do
285
- allow(Embulk::Input::JiraApi::Client).to receive(:setup).and_return(jira_api)
286
- allow(plugin).to receive(:logger).and_return(::Logger.new(File::NULL))
287
- allow(plugin).to receive(:preview?).and_return(true)
288
- allow(jira_api).to receive(:check_user_credential).and_return(username)
289
- allow(jira_api).to receive(:search_issues).and_return(jira_issues)
290
- allow(page_builder).to receive(:add)
291
- allow(page_builder).to receive(:finish)
292
- end
293
-
294
- it "max_results with PREVIEW_RECORDS_COUNT" do
295
- expect(jira_api).to receive(:search_issues).with(jql, max_results: Embulk::Input::Jira::PREVIEW_RECORDS_COUNT)
296
- subject
297
- end
298
-
299
- it "call page_builder.add and page_builder.finish" do
300
- expect(page_builder).to receive(:add).exactly(jira_issues.length).times
301
- expect(page_builder).to receive(:finish)
302
- subject
303
- end
304
- end
305
-
306
- describe ".logger" do
307
- let(:logger) { described_class.logger }
308
-
309
- subject { logger }
310
-
311
- it { is_expected.to be_a(Embulk::Logger) }
312
- end
313
-
314
- describe "#logger" do
315
- let(:instance) { described_class.new({}, nil, nil, nil) }
316
- let(:logger) { instance.logger }
317
-
318
- subject { logger }
319
-
320
- it { is_expected.to be_a(Embulk::Logger) }
321
- end
322
- end
@@ -1,32 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Embulk do
4
- describe "registerd jira as input plugin" do
5
- let(:config) { <<-YAML }
6
- in:
7
- type: jira
8
- YAML
9
- let(:config_file) { Tempfile.new("embulk-conf") }
10
-
11
- before do
12
- config_file.puts config
13
- config_file.close
14
- allow(org.embulk.spi.Exec).to receive(:isPreview).and_return(true)
15
- end
16
-
17
- subject {
18
- capture(:out) do
19
- # Skip this test because `embulk_run` has been removed
20
- # Embulk.run ["preview", config_file.path]
21
- end
22
- }
23
-
24
- it do
25
- # NOTE: can't stub `exit` so stubbing `raise`
26
- # https://github.com/embulk/embulk/blob/v0.6.9/lib/embulk/command/embulk_run.rb#L335
27
- allow(Embulk).to receive(:raise)
28
-
29
- is_expected.to_not include("InputPlugin 'jira' is not found.")
30
- end
31
- end
32
- end
@@ -1,26 +0,0 @@
1
- require "rubygems"
2
- require "bundler/setup"
3
-
4
- Bundler.require(:runtime, :development)
5
-
6
- require "embulk"
7
- Embulk.setup
8
-
9
- Dir["./spec/support/**/*.rb"].each{|file| require file }
10
-
11
- if ENV["COVERAGE"]
12
- if ENV["CI"]
13
- require "codeclimate-test-reporter"
14
- CodeClimate::TestReporter.start
15
- else
16
- require 'simplecov'
17
- SimpleCov.start 'test_frameworks'
18
- end
19
- end
20
-
21
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
22
- require "embulk/input/jira"
23
-
24
- RSpec.configure do |config|
25
- config.include StdoutAndErrCapture
26
- end
@@ -1,45 +0,0 @@
1
- module StdoutAndErrCapture
2
- def capture(output = :out, &block)
3
- _, out = swap_io(output, &block)
4
- out
5
- end
6
-
7
- def silence(&block)
8
- block_result = nil
9
- swap_io(:out) do
10
- block_result,_ = swap_io(:err, &block)
11
- end
12
- block_result
13
- end
14
-
15
- def swap_io(output = :out, &block)
16
- java_import 'java.io.PrintStream'
17
- java_import 'java.io.ByteArrayOutputStream'
18
- java_import 'java.lang.System'
19
-
20
- ruby_original_stream = output == :out ? $stdout.dup : $stderr.dup
21
- java_original_stream = System.send(output) # :out or :err
22
- ruby_buf = StringIO.new
23
- java_buf = ByteArrayOutputStream.new
24
-
25
- case output
26
- when :out
27
- $stdout = ruby_buf
28
- System.setOut(PrintStream.new(java_buf))
29
- when :err
30
- $stderr = ruby_buf
31
- System.setErr(PrintStream.new(java_buf))
32
- end
33
-
34
- [block.call, ruby_buf.string + java_buf.toString]
35
- ensure
36
- case output
37
- when :out
38
- $stdout = ruby_original_stream
39
- System.setOut(java_original_stream)
40
- when :err
41
- $stderr = ruby_original_stream
42
- System.setErr(java_original_stream)
43
- end
44
- end
45
- end