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 +4 -4
- data/.gitignore +1 -0
- data/hub_store.gemspec +2 -1
- data/lib/hub_store.rb +0 -1
- data/lib/hub_store/cli.rb +2 -0
- data/lib/hub_store/importer.rb +14 -10
- data/lib/hub_store/insert.rb +2 -8
- data/lib/hub_store/pull_request.rb +1 -0
- data/lib/hub_store/ui.rb +18 -0
- data/lib/hub_store/version.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d608a1df55b59c1018630b8840b1265144cb43f4697f4e3939f79556efecb2d
|
4
|
+
data.tar.gz: d9dad1c9d112eede66045a65b255ee9107261b076c33f16217845ac69b51b1dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4058d615f51d8bd34135194c0aecf6a35042b445f1d9aa85ee7124ee5b2961143aecd6172bbffab0bd12553d0c287c85da308f8a931d27a706efd6448d14ba7e
|
7
|
+
data.tar.gz: f61d994ca4e4b20a744ee8f58dcfd01095b7b097feeff82ce8df6cb1e920a1e8203e213559c6bc8f96bb66f76833803dfe029ccb56576c36b31aa569ec8d063d
|
data/.gitignore
CHANGED
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.
|
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
data/lib/hub_store/cli.rb
CHANGED
data/lib/hub_store/importer.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/hub_store/insert.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/hub_store/ui.rb
ADDED
@@ -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
|
data/lib/hub_store/version.rb
CHANGED
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.
|
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-
|
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.
|
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.
|
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:
|