ehpt 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71cf3802e5a0eca6fc6ef48a373109b25096744bf3c0caec3122155165254c9c
4
- data.tar.gz: 2bab4a45d7746d7a76be9e644f12cb6fd12f25dc87544b6022f250f336d0dd04
3
+ metadata.gz: f3653e66627846fae073f4173a4f51cf683b76284d1b413095347c9f3462a94e
4
+ data.tar.gz: f8835fe7726e1f883e9f5608328e7257f06abdf0a8552cd1332662ad64e64ace
5
5
  SHA512:
6
- metadata.gz: 439ff764e4462ad0842539e76038c01325ab4e3b96376d2d316ee478336520c734401ed070833e96274fc43d89836d3fc245efc6f4e262a0440eef62231bdbc4
7
- data.tar.gz: 0a70b5c444573ae27b3a70a435457dace31a13bb404746cbeac85966bbab0a1d2586b8b3c49199acad620141b6ec7a605249d6f710d6f1fc882dc0fb602862af
6
+ metadata.gz: ae913c7ffbd558597ca0847638ffe32bdffdc8e5bf412c9352bfdd38faaa107809f8e092fbada9e68080f9704d2fc97f169b525e6cf68b10200978c106720b60
7
+ data.tar.gz: 63c49d8f401bf28dbdb407c00878f56d1fafe7b522211ea190197764a106b43d33253109df0fb67a95448892341fd5921986a96fb65e8548babacc7f39f5826a
data/bin/ehpt CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'ehpt'
4
4
 
5
- Ehpt.new(*ARGV).call
5
+ Ehpt.call(*ARGV)
data/lib/ehpt/base.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Ehpt
1
+ module Ehpt
2
2
  class Base
3
3
  attr_reader :data, :errors
4
4
 
@@ -18,5 +18,15 @@ class Ehpt
18
18
  def error?
19
19
  !success?
20
20
  end
21
+
22
+ def add_error(error)
23
+ if error.is_a?(Array)
24
+ error.each do |err|
25
+ add_error(err)
26
+ end
27
+ else
28
+ @errors << error
29
+ end
30
+ end
21
31
  end
22
32
  end
@@ -2,7 +2,7 @@ require 'csv'
2
2
  require 'ehpt/base'
3
3
  require 'ehpt/create_story'
4
4
 
5
- class Ehpt
5
+ module Ehpt
6
6
  class CreateStories < Base
7
7
  attr_reader :csv_file, :project
8
8
 
@@ -24,14 +24,16 @@ class Ehpt
24
24
  validate_csv_file!
25
25
  create_stories unless error?
26
26
  rescue StandardError => e
27
- errors << e.message
27
+ add_error(e.message)
28
28
  end
29
29
 
30
30
  private
31
31
 
32
32
  def validate_csv_file!
33
- @errors << 'Input file must be a csv file' if File.extname(csv_file) != '.csv'
34
- @errors << 'CSV content is empty' if File.zero?(csv_file)
33
+ if File.extname(csv_file) != '.csv'
34
+ add_error('Input file must be a csv file' )
35
+ end
36
+ add_error('CSV content is empty') if File.zero?(csv_file)
35
37
  end
36
38
 
37
39
  def create_stories
@@ -39,13 +41,14 @@ class Ehpt
39
41
  story_attrs = create_story_attributes(row)
40
42
  story_creator = Ehpt::CreateStory.new(project, story_attrs)
41
43
  story_creator.call
44
+
42
45
  if story_creator.success?
43
46
  puts "Created story: #{story_creator.data.name}"
44
47
  else
45
- @errors = @errors << {
48
+ add_error({
46
49
  row: row.to_h,
47
50
  errors: story_creator.errors
48
- }
51
+ })
49
52
  end
50
53
  end
51
54
  end
@@ -1,6 +1,6 @@
1
1
  require 'ehpt/base'
2
2
 
3
- class Ehpt
3
+ module Ehpt
4
4
  class CreateStory < Base
5
5
  attr_reader :project, :story_attrs
6
6
 
@@ -14,7 +14,7 @@ class Ehpt
14
14
  create_story
15
15
  prefix_story_name_with_id
16
16
  rescue StandardError => e
17
- errors << eval(e.message)[:body]
17
+ add_error(eval(e.message)[:body])
18
18
  end
19
19
 
20
20
  private
@@ -1,7 +1,7 @@
1
1
  require 'tracker_api'
2
2
  require 'ehpt/base'
3
3
 
4
- class Ehpt
4
+ module Ehpt
5
5
  class GetProject < Base
6
6
  attr_reader :token, :project_id
7
7
 
@@ -15,7 +15,7 @@ class Ehpt
15
15
  pt_client = TrackerApi::Client.new(token: token)
16
16
  @data = pt_client.project(project_id)
17
17
  rescue StandardError => e
18
- @errors << e.message
18
+ add_error(eval(e.message)[:body])
19
19
  end
20
20
  end
21
21
  end
data/lib/ehpt.rb CHANGED
@@ -3,35 +3,28 @@ require 'csv'
3
3
  require 'ehpt/get_project'
4
4
  require 'ehpt/create_stories'
5
5
 
6
- class Ehpt
7
- attr_reader :csv_file, :project
6
+ module Ehpt
7
+ def self.call(csv_file, token, project_id)
8
+ project_getter = Ehpt::GetProject.new(token, project_id)
9
+ project_getter.call
8
10
 
9
- def initialize(csv_file, token, project_id)
10
- @csv_file = csv_file
11
- @project = get_project_by(token, project_id)
12
- end
11
+ if project_getter.error?
12
+ puts "===== Errors ====="
13
+ pp project_getter.errors
14
+ return
15
+ end
16
+
17
+ puts "Found project: #{project_getter.data.name}"
18
+ project = project_getter.data
13
19
 
14
- def call
15
20
  stories_creator = Ehpt::CreateStories.new(csv_file, project)
16
21
  stories_creator.call
22
+
17
23
  puts "Done"
24
+
18
25
  if stories_creator.error?
19
26
  puts "===== Errors ====="
20
27
  pp stories_creator.errors
21
28
  end
22
29
  end
23
-
24
- private
25
-
26
- def get_project_by(token, project_id)
27
- project_getter = Ehpt::GetProject.new(token, project_id)
28
- project_getter.call
29
-
30
- if project_getter.error?
31
- raise StandardError, project_getter.errors
32
- end
33
-
34
- puts "Found project: #{project_getter.data.name}"
35
- project_getter.data
36
- end
37
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - phamhoaivu911