hub_store 0.5.0 → 0.6.0

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: 6a563df0ec7313beaea07c489b97458c9598f43d4a2ec408a421fa1e8af98ec9
4
- data.tar.gz: 853e8cbf787e7a406965a4b3c8566d17e17dfb67d2b2104bb1fdfeb6a691c7f8
3
+ metadata.gz: 9d608a1df55b59c1018630b8840b1265144cb43f4697f4e3939f79556efecb2d
4
+ data.tar.gz: d9dad1c9d112eede66045a65b255ee9107261b076c33f16217845ac69b51b1dd
5
5
  SHA512:
6
- metadata.gz: 79b7350946f4fdb4acb5508df53a33f4f76baf6e172c8d79cad078807e4a276099d908e708738264512cd5f72b16c4563633ed21286e7e887062aa46b268ef33
7
- data.tar.gz: 37163e98c43ede5aef32c78a3c0f026f2c6d2856140b5c34c808629975498457fc8064f15cfc26dc2cbece1353bea769c65a3e50980621da8ff5ba8bfdab28fb
6
+ metadata.gz: 4058d615f51d8bd34135194c0aecf6a35042b445f1d9aa85ee7124ee5b2961143aecd6172bbffab0bd12553d0c287c85da308f8a931d27a706efd6448d14ba7e
7
+ data.tar.gz: f61d994ca4e4b20a744ee8f58dcfd01095b7b097feeff82ce8df6cb1e920a1e8203e213559c6bc8f96bb66f76833803dfe029ccb56576c36b31aa569ec8d063d
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  /db
11
11
  *.csv
12
12
  Gemfile.lock
13
+ *.log
data/hub_store.gemspec CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_dependency "activerecord"
33
33
  spec.add_dependency "dotenv"
34
- spec.add_dependency "hub_link", ">= 0.4"
34
+ spec.add_dependency "hub_link", ">= 0.6"
35
35
  spec.add_dependency "sqlite3"
36
+ spec.add_dependency "tty-spinner"
36
37
  end
data/lib/hub_store.rb CHANGED
@@ -5,7 +5,6 @@ require "hub_store/exporter"
5
5
 
6
6
  module HubStore
7
7
  class Error < StandardError; end
8
-
9
8
  # Set up database
10
9
  ActiveRecord::Base.establish_connection(
11
10
  adapter: "sqlite3",
data/lib/hub_store/cli.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "hub_store/ui"
2
+
1
3
  module HubStore
2
4
  class Cli
3
5
  def self.run(*args)
@@ -6,13 +6,15 @@ require "hub_store/review_request"
6
6
 
7
7
  module HubStore
8
8
  class Importer
9
- def initialize(repo:, start_date: nil)
9
+ def initialize(repo:, start_date: nil, ui: Ui.new)
10
10
  @repo = repo
11
- @start_date = start_date || 2.years.ago
11
+ @start_date = (start_date || 2.years.ago).to_date
12
+ @ui = ui
12
13
  end
13
14
 
14
15
  def run
15
16
  stream.in_batches do |batch|
17
+ ui.log "\n-- #{batch.query} --"
16
18
  import_prs(batch)
17
19
  import_reviews(batch)
18
20
  import_review_requests(batch)
@@ -21,34 +23,36 @@ module HubStore
21
23
 
22
24
  private
23
25
 
24
- attr_reader :repo, :start_date
26
+ attr_reader :repo, :start_date, :ui
25
27
 
26
28
  def import_prs(batch)
29
+ ui.start("Importing PRs")
30
+
27
31
  batch.pull_requests.each do |row|
28
32
  Insert.new(row: row, target: PullRequest).run
29
33
  end
30
34
 
31
- log "Imported #{PullRequest.count} PRs so far"
35
+ ui.stop("Total: #{PullRequest.count}")
32
36
  end
33
37
 
34
38
  def import_reviews(batch)
39
+ ui.start("Importing reviews")
40
+
35
41
  batch.reviews.each do |row|
36
42
  Insert.new(row: row, target: Review).run
37
43
  end
38
44
 
39
- log "Imported #{Review.count} reviews so far"
45
+ ui.stop("Total: #{Review.count}")
40
46
  end
41
47
 
42
48
  def import_review_requests(batch)
49
+ ui.start("Importing review requests")
50
+
43
51
  batch.review_requests.each do |row|
44
52
  Insert.new(row: row, target: ReviewRequest).run
45
53
  end
46
54
 
47
- log "Imported #{ReviewRequest.count} review requests so far"
48
- end
49
-
50
- def log(msg)
51
- puts msg
55
+ ui.stop("Total: #{ReviewRequest.count}")
52
56
  end
53
57
 
54
58
  def stream
@@ -7,8 +7,6 @@ module HubStore
7
7
 
8
8
  def run
9
9
  record.update! importable_attributes
10
- rescue ActiveRecord::RecordNotUnique
11
- Rails.logger.warn "Skipping duplicate record ##{row[:id]}"
12
10
  end
13
11
 
14
12
  private
@@ -22,15 +20,11 @@ module HubStore
22
20
  end
23
21
 
24
22
  def importable_attributes
25
- normalized_attributes.slice(*target_columns)
26
- end
27
-
28
- def normalized_attributes
29
- row.transform_keys { |key| key.to_s.chomp("?") }
23
+ row.slice(*target_columns)
30
24
  end
31
25
 
32
26
  def target_columns
33
- target.columns.map(&:name)
27
+ target.columns.map(&:name).map(&:to_sym)
34
28
  end
35
29
 
36
30
  attr_reader :row, :target
@@ -3,6 +3,7 @@ require "active_record"
3
3
  module HubStore
4
4
  class PullRequest < ActiveRecord::Base
5
5
  scope :recently_updated_first, -> { order(updated_at: :desc) }
6
+ validates :repo, presence: true
6
7
 
7
8
  def self.for(repo)
8
9
  where(repo: repo)
@@ -0,0 +1,18 @@
1
+ require "tty/spinner"
2
+
3
+ module HubStore
4
+ class Ui
5
+ def start(msg)
6
+ @spinner = TTY::Spinner.new(":spinner #{msg}...", format: :dots_3)
7
+ @spinner.auto_spin
8
+ end
9
+
10
+ def stop(msg)
11
+ @spinner.success("(#{msg})")
12
+ end
13
+
14
+ def log(msg)
15
+ puts msg
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module HubStore
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hub_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-14 00:00:00.000000000 Z
11
+ date: 2019-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '0.4'
131
+ version: '0.6'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '0.4'
138
+ version: '0.6'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: sqlite3
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: tty-spinner
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description:
154
168
  email:
155
169
  - jens@balvig.com
@@ -178,6 +192,7 @@ files:
178
192
  - lib/hub_store/pull_request.rb
179
193
  - lib/hub_store/review.rb
180
194
  - lib/hub_store/review_request.rb
195
+ - lib/hub_store/ui.rb
181
196
  - lib/hub_store/version.rb
182
197
  homepage: https://balvig.com
183
198
  licenses: