ehpt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0dc406a11a4ece9f21d00c1b887398922cd2aa6cd57fc85fb240d3ce53681e60
4
+ data.tar.gz: bf89bab4544bf000676c81a59be2bb8b3181b167345077fdf50c035c7bb8d710
5
+ SHA512:
6
+ metadata.gz: 4a06dd761b9e73760c2b68ee2c7522dbd0b73225c4954446b8f5807b8469a5e7830b7a6d17b0e0d84a0caa280e070d2c62665b5e91c26eaf4edd42297ded3a27
7
+ data.tar.gz: 82b086225a90066902af3acd57b75d26ecb4d0bd0a05b6b5fd39c145435a20bd7724544549150c14013bc04f454affcfcb1480a1179fba7319788de200e9596a
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'ehpt'
4
+
5
+ Ehpt.new(*ARGV).call
@@ -0,0 +1,34 @@
1
+ require 'csv'
2
+ require 'ehpt/get_project'
3
+ require 'ehpt/create_stories'
4
+
5
+ class Ehpt
6
+ attr_reader :csv_content, :project
7
+
8
+ def initialize(csv_file, token, project_id)
9
+ @csv_content = File.read(csv_file)
10
+ @project = get_project(token, project_id)
11
+ end
12
+
13
+ def call
14
+ stories_creator = Ehpt::CreateStories.new(csv_content, project)
15
+ stories_creator.call
16
+ if stories_creator.error?
17
+ raise StandardError, stories_creator.errors
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def get_project(token, project_id)
24
+ project_getter = Ehpt::GetProject.new(token, project_id)
25
+ project_getter.call
26
+
27
+ if project_getter.error?
28
+ raise StandardError, project_getter.errors
29
+ end
30
+
31
+ puts "Found project #{project_getter.data.name}"
32
+ project_getter.data
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ class Ehpt
2
+ class Base
3
+ attr_reader :data, :errors
4
+
5
+ def self.call(*args)
6
+ new(*args).call
7
+ end
8
+
9
+ def initialize(*args)
10
+ @data = nil
11
+ @errors = []
12
+ end
13
+
14
+ def success?
15
+ errors.empty?
16
+ end
17
+
18
+ def error?
19
+ !success?
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,67 @@
1
+ require 'csv'
2
+ require 'ehpt/base'
3
+ require 'ehpt/create_story'
4
+
5
+ class Ehpt
6
+ class CreateStories < Base
7
+ attr_reader :csv_content, :project
8
+
9
+ ARRAY_TYPE_ATTRIBUTES = %w[
10
+ labels tasks pull_requests branches blockers followers comments reviews
11
+ ]
12
+
13
+ INT_ARRAY_TYPE_ATTRIBUTES = %w[
14
+ owner_ids label_ids task_ids pull_request_ids branch_ids
15
+ blocker_ids follower_ids comment_ids review_ids
16
+ ]
17
+
18
+ INT_TYPE_ATTRIBUTES = %w[ project_id requested_by_id before_id after_id integration_id ]
19
+
20
+ FLOAT_TYPE_ATTRIBUES = %w[ estimate ]
21
+
22
+ def initialize(csv_content, project)
23
+ @csv_content = csv_content
24
+ @project = project
25
+ super
26
+ end
27
+
28
+ def call
29
+ validate_csv_content!
30
+ create_stories unless error?
31
+ puts "Done"
32
+ rescue StandardError => e
33
+ errors << e.message
34
+ end
35
+
36
+ private
37
+
38
+ def validate_csv_content!
39
+ if csv_content.blank?
40
+ @errors << 'CSV content is empty'
41
+ end
42
+ puts "Read CSV done"
43
+ end
44
+
45
+ def create_stories
46
+ CSV.parse(csv_content, headers: true) do |row|
47
+ story_attrs = create_story_attributes(row)
48
+ story_creator = Ehpt::CreateStory.new(project, story_attrs)
49
+ story_creator.call
50
+ if story_creator.error?
51
+ @errors = @errors.concat(story_creator.errors)
52
+ end
53
+ end
54
+ end
55
+
56
+ def create_story_attributes(row)
57
+ story_attrs = row.to_h.compact
58
+ story_attrs.each do |key, value|
59
+ story_attrs[key] = value.to_i if INT_TYPE_ATTRIBUTES.include?(key)
60
+ story_attrs[key] = value.to_f if FLOAT_TYPE_ATTRIBUES.include?(key)
61
+ story_attrs[key] = value.split(',') if ARRAY_TYPE_ATTRIBUTES.include?(key)
62
+ story_attrs[key] = value.split(',').map(&:to_i) if INT_ARRAY_TYPE_ATTRIBUTES.include?(key)
63
+ end
64
+ story_attrs
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,32 @@
1
+ require 'ehpt/base'
2
+
3
+ class Ehpt
4
+ class CreateStory < Base
5
+ attr_reader :project, :story_attrs
6
+
7
+ def initialize(project, story_attrs)
8
+ @project = project
9
+ @story_attrs = story_attrs
10
+ super
11
+ end
12
+
13
+ def call
14
+ create_story
15
+ prefix_story_name_with_id
16
+ puts "Created story: #{@story.name}"
17
+ rescue StandardError => e
18
+ errors << e.message
19
+ end
20
+
21
+ private
22
+
23
+ def create_story
24
+ @story = project.create_story(story_attrs)
25
+ end
26
+
27
+ def prefix_story_name_with_id
28
+ @story.name = [@story.id.to_s.split(//).last(3).join, @story.name].join(' - ')
29
+ @story.save
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ require 'tracker_api'
2
+ require 'ehpt/base'
3
+
4
+ class Ehpt
5
+ class GetProject < Base
6
+ attr_reader :token, :project_id
7
+
8
+ def initialize(token, project_id)
9
+ @token = token || ENV['PIVOTAL_TRACKER_TOKEN']
10
+ @project_id = project_id || ENV['PIVOTAL_TRACKER_PROJECT_ID']
11
+ super
12
+ end
13
+
14
+ def call
15
+ pt_client = TrackerApi::Client.new(token: token)
16
+ @data = pt_client.project(project_id)
17
+ rescue StandardError => e
18
+ @errors << e.message
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ehpt
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - phamhoaivu911
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 13.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 13.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.9.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 11.0.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 11.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: tracker_api
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.10.0
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '1.10'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 1.10.0
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.10'
75
+ - !ruby/object:Gem::Dependency
76
+ name: csv
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.1'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 3.1.2
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '3.1'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 3.1.2
95
+ description: A command line tool to create Pivotal Tracker stories from CSV file
96
+ email: ''
97
+ executables:
98
+ - ehpt
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - bin/ehpt
103
+ - lib/ehpt.rb
104
+ - lib/ehpt/base.rb
105
+ - lib/ehpt/create_stories.rb
106
+ - lib/ehpt/create_story.rb
107
+ - lib/ehpt/get_project.rb
108
+ homepage: https://github.com/phamhoaivu911/ehpt
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.0.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Employment Hero Pivotal Tracker
131
+ test_files: []