ehpt 1.0.1 → 1.0.2

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: 0fb8d4c1fb9c87fd89ae55444f3f8cd7f3a7bc83e6de0924b91f0d1930ee8908
4
- data.tar.gz: 5a5c317ffd25042a9aeede1dc8fe1f8122188f1e8a41ecd5245a1ae620ce6990
3
+ metadata.gz: 278b527d924ee5cef6328be96682e18250fa30d449cec2a8f9aa3abe4ec35603
4
+ data.tar.gz: 65736a6878779bda11a0d3a33d979855058a2035666b810cfa262ebbb13f8c4d
5
5
  SHA512:
6
- metadata.gz: 89956c440258c42310af997979c343152222469cc01f801fbf53558edee233d5a1cc976a80a2c6c013dd4cd52705553bc8ae7fa038dd953be51ba7a9fd00a7b1
7
- data.tar.gz: b41201119b1f05296d1c9ed1a2e84de882b523d3512c6c157fd97eefa5e5159f2475d378eeea003b2547eb966a1d16042e43e4b3b641a8d32e3994b23d3a7c96
6
+ metadata.gz: 2849d58b9de11b409b8b0e4adc251f8d6894c5fb3472f9db448234a5922c77bf9cad5f1ba4e42136c45cc423b8ea308033a55f1367e9e5ba58e7d2fac3ff0c9e
7
+ data.tar.gz: fbb28dd01aa013215d0fdd3defa1ae7313395725ab7455dca5f02285dd93856ec9a78b1bdca5abe0c47f381a3f0847c9b33ee4778232f92b0d565c9a9fed2664
data/lib/ehpt.rb CHANGED
@@ -3,24 +3,25 @@ require 'ehpt/get_project'
3
3
  require 'ehpt/create_stories'
4
4
 
5
5
  class Ehpt
6
- attr_reader :csv_content, :project
6
+ attr_reader :csv_file, :project
7
7
 
8
8
  def initialize(csv_file, token, project_id)
9
- @csv_content = File.read(csv_file)
10
- @project = get_project(token, project_id)
9
+ @csv_file = csv_file
10
+ @project = get_project_by(token, project_id)
11
11
  end
12
12
 
13
13
  def call
14
- stories_creator = Ehpt::CreateStories.new(csv_content, project)
14
+ stories_creator = Ehpt::CreateStories.new(csv_file, project)
15
15
  stories_creator.call
16
+ puts "Done"
16
17
  if stories_creator.error?
17
- raise StandardError, stories_creator.errors
18
+ puts "Errors: #{stories_creator.errors}"
18
19
  end
19
20
  end
20
21
 
21
22
  private
22
23
 
23
- def get_project(token, project_id)
24
+ def get_project_by(token, project_id)
24
25
  project_getter = Ehpt::GetProject.new(token, project_id)
25
26
  project_getter.call
26
27
 
@@ -28,7 +29,7 @@ class Ehpt
28
29
  raise StandardError, project_getter.errors
29
30
  end
30
31
 
31
- puts "Found project #{project_getter.data.name}"
32
+ puts "Found project: #{project_getter.data.name}"
32
33
  project_getter.data
33
34
  end
34
35
  end
@@ -4,7 +4,7 @@ require 'ehpt/create_story'
4
4
 
5
5
  class Ehpt
6
6
  class CreateStories < Base
7
- attr_reader :csv_content, :project
7
+ attr_reader :csv_file, :project
8
8
 
9
9
  ARRAY_TYPE_ATTRIBUTES = %w[ labels tasks pull_requests branches blockers comments reviews ]
10
10
 
@@ -14,35 +14,34 @@ class Ehpt
14
14
 
15
15
  FLOAT_TYPE_ATTRIBUES = %w[ estimate ]
16
16
 
17
- def initialize(csv_content, project)
18
- @csv_content = csv_content
17
+ def initialize(csv_file, project)
18
+ @csv_file = csv_file
19
19
  @project = project
20
20
  super
21
21
  end
22
22
 
23
23
  def call
24
- validate_csv_content!
24
+ validate_csv_file!
25
25
  create_stories unless error?
26
- puts "Done"
27
26
  rescue StandardError => e
28
27
  errors << e.message
29
28
  end
30
29
 
31
30
  private
32
31
 
33
- def validate_csv_content!
34
- if csv_content.blank?
35
- @errors << 'CSV content is empty'
36
- end
37
- puts "Read CSV done"
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)
38
35
  end
39
36
 
40
37
  def create_stories
41
- CSV.parse(csv_content, headers: true) do |row|
38
+ CSV.foreach(csv_file, headers: true) do |row|
42
39
  story_attrs = create_story_attributes(row)
43
40
  story_creator = Ehpt::CreateStory.new(project, story_attrs)
44
41
  story_creator.call
45
- if story_creator.error?
42
+ if story_creator.success?
43
+ puts "Created story: #{story_creator.data.name}"
44
+ else
46
45
  @errors = @errors.concat(story_creator.errors)
47
46
  end
48
47
  end
@@ -13,7 +13,6 @@ class Ehpt
13
13
  def call
14
14
  create_story
15
15
  prefix_story_name_with_id
16
- puts "Created story: #{@story.name}"
17
16
  rescue StandardError => e
18
17
  errors << e.message
19
18
  end
@@ -21,12 +20,12 @@ class Ehpt
21
20
  private
22
21
 
23
22
  def create_story
24
- @story = project.create_story(story_attrs)
23
+ @data = project.create_story(story_attrs)
25
24
  end
26
25
 
27
26
  def prefix_story_name_with_id
28
- @story.name = [@story.id.to_s.split(//).last(3).join, @story.name].join(' - ')
29
- @story.save
27
+ @data.name = [@data.id.to_s.split(//).last(3).join, @data.name].join(' - ')
28
+ @data.save
30
29
  end
31
30
  end
32
31
  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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - phamhoaivu911