hub_link 0.11.0 → 0.12.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
  SHA1:
3
- metadata.gz: 55820ffa015f5004c8f88f16f18a55a617926a95
4
- data.tar.gz: 89d401fa82ab3d62a7c78df1f2dd8a45ceae2e2a
3
+ metadata.gz: ca30700c01889aa81a758897b9ed2045326fc007
4
+ data.tar.gz: 927b8700754db70fd474635aa22cbadd5e2d68f3
5
5
  SHA512:
6
- metadata.gz: 6c213375c41d32eeeebd6f0867ce64eadcfa0e47b19664603c3f584e64093f645fc9f6408f321765a3dd271dd1e71c3de05d2f9fd30a5a264ede25b9737786b8
7
- data.tar.gz: 171461c43bb35bc5b2db94ccde9c971094bc6d255cfd37c5b73502ece8b0b2c31fb45dee039cf03108b9a21a9c666e1ef6b9a5b6d6f4db99619024e27b024cd2
6
+ metadata.gz: ed4acda89cfe380cd64cf031a3be42d23340a297025fb48e625c50f720d997eefcdc031ca1cfe1e5a612caca131c7427188f0ae8e3e14ca9455c9dc6e1aaf24c
7
+ data.tar.gz: 8c8faa99fdb7f301f7c2a0c72d1e38bb5adc14f0efb39b6dcf8ef6d25983b1603ac2615f20c930567d2b3a0cb55253e1b7a905508f57b87a82d9dc2f7ae419d7
data/README.md CHANGED
@@ -17,9 +17,9 @@ Then you can do:
17
17
  stream = HubLink::Stream.new("balvig/hub_link", start_date: 3.months.ago)
18
18
 
19
19
  stream.in_batches do |batch|
20
- batch.prs # => [{ id: 34, merge_time: 6400, ... }]
21
- batch.reviews # => [{ id: 54, reviewer: "balvig", approval: true, ... }]
22
20
  batch.review_requests # => [{ digest: "a45bfa...", reviewer: "balvig", ... }]
21
+ batch.reviews # => [{ id: 54, reviewer: "balvig", approval: true, ... }]
22
+ batch.prs # => [{ id: 34, merge_time: 6400, ... }]
23
23
  end
24
24
  ```
25
25
 
@@ -7,12 +7,13 @@ require "hub_link/slicer"
7
7
  module HubLink
8
8
  module Api
9
9
  class PullRequest < SimpleDelegator
10
- def self.search(filter)
10
+ def self.search(filter, auto_paginate: true)
11
+ Octokit.auto_paginate = auto_paginate
11
12
  Octokit.search_issues(filter).items.map { |item| new(item) }
12
13
  end
13
14
 
14
15
  def self.oldest(repo:)
15
- search("type:pr sort:updated-asc repo:#{repo}").first
16
+ search("type:pr sort:updated-asc repo:#{repo}", auto_paginate: false).first
16
17
  end
17
18
 
18
19
  def submitter
@@ -100,7 +101,7 @@ module HubLink
100
101
  end
101
102
 
102
103
  def first_review
103
- reviews.first
104
+ reviews.find(&:submitted?)
104
105
  end
105
106
 
106
107
  def extended_data
@@ -12,11 +12,21 @@ module HubLink
12
12
  end
13
13
 
14
14
  def invalid?
15
- bot? || driveby? || draft?
15
+ bot?
16
+ end
17
+
18
+ def submitted?
19
+ !draft?
20
+ end
21
+
22
+ def submitted_at
23
+ if submitted?
24
+ super
25
+ end
16
26
  end
17
27
 
18
28
  def to_h
19
- Slicer.new(self, columns: %i(id pull_request_id submitted_at reviewer approval?)).to_h
29
+ Slicer.new(self, columns: %i(id pull_request_id submitted_at reviewer approval? state)).to_h
20
30
  end
21
31
 
22
32
  private
@@ -25,10 +35,6 @@ module HubLink
25
35
  BOTS.include?(reviewer)
26
36
  end
27
37
 
28
- def driveby?
29
- state == "COMMENTED"
30
- end
31
-
32
38
  def draft?
33
39
  state == "PENDING"
34
40
  end
@@ -0,0 +1,23 @@
1
+ # https://gist.github.com/nilbus/6385142
2
+ module HubLink
3
+ class Callbacks
4
+ def initialize(block)
5
+ block&.call(self)
6
+ end
7
+
8
+ def callback(message, *args)
9
+ callbacks[message]&.call(*args)
10
+ end
11
+
12
+ def method_missing(m, *args, &block)
13
+ block ? callbacks[m] = block : super
14
+ self
15
+ end
16
+
17
+ private
18
+
19
+ def callbacks
20
+ @callbacks ||= {}
21
+ end
22
+ end
23
+ end
@@ -6,7 +6,6 @@ module HubLink
6
6
  class Configuration
7
7
  def apply
8
8
  Octokit.middleware = middleware
9
- Octokit.auto_paginate = true
10
9
  end
11
10
 
12
11
  private
@@ -0,0 +1,46 @@
1
+ require "hub_link"
2
+ require "hub_link/callbacks"
3
+ require "hub_link/insert"
4
+
5
+ module HubLink
6
+ class Importer
7
+ delegate :callback, to: :callbacks
8
+
9
+ def self.run(*args, &block)
10
+ new(*args, &block).run
11
+ end
12
+
13
+ def initialize(repo:, start_date:, resources:, &block)
14
+ @repo = repo.to_s
15
+ @start_date = start_date
16
+ @resources = resources
17
+ @callbacks = Callbacks.new(block)
18
+ end
19
+
20
+ def run
21
+ stream.in_batches do |batch|
22
+ callback(:init, batch.query)
23
+
24
+ resources.each do |source, target|
25
+ callback(:start, source)
26
+ import batch.fetch(source), to: target
27
+ callback(:finish, target.count)
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :repo, :start_date, :resources, :callbacks
35
+
36
+ def import(records, to:)
37
+ records.each do |row|
38
+ Insert.new(row: row, target: to).run
39
+ end
40
+ end
41
+
42
+ def stream
43
+ @_stream ||= Stream.new(repo, start_date: start_date)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ module HubLink
2
+ class Insert
3
+ delegate :primary_key, to: :target
4
+
5
+ def initialize(row:, target:)
6
+ @row = row
7
+ @target = target
8
+ end
9
+
10
+ def run
11
+ record.update! importable_attributes
12
+ end
13
+
14
+ private
15
+
16
+ def record
17
+ target.find_or_initialize_by(primary_key => primary_key_value)
18
+ end
19
+
20
+ def primary_key_value
21
+ row[primary_key]
22
+ end
23
+
24
+ def importable_attributes
25
+ row.slice(*target_columns)
26
+ end
27
+
28
+ def target_columns
29
+ target.columns.map(&:name).map(&:to_sym)
30
+ end
31
+
32
+ attr_reader :row, :target
33
+ end
34
+ end
@@ -8,7 +8,7 @@ module HubLink
8
8
  end
9
9
 
10
10
  def to_h
11
- normalized_attributes
11
+ normalized_attributes.with_indifferent_access
12
12
  end
13
13
 
14
14
  private
@@ -10,8 +10,9 @@ module HubLink
10
10
  end
11
11
 
12
12
  def in_batches(&block)
13
- queries.each do |query|
14
- yield Batch.new(query)
13
+ start_date.step(end_date, batch_size) do |date|
14
+ range = "#{date}..#{date + (batch_size - 1)}"
15
+ yield Batch.new "type:pr updated:#{range} repo:#{repo}"
15
16
  end
16
17
  end
17
18
 
@@ -23,14 +24,8 @@ module HubLink
23
24
  Api::PullRequest.oldest(repo: repo)&.updated_at
24
25
  end
25
26
 
26
- def queries
27
- start_date.step(end_date, batch_size).map do |date|
28
- "type:pr updated:#{date}..#{date + (batch_size - 1)} repo:#{repo}"
29
- end
30
- end
31
-
32
27
  def end_date
33
- Date.tomorrow
28
+ @_end_date ||= Date.tomorrow
34
29
  end
35
30
  end
36
31
  end
@@ -1,3 +1,3 @@
1
1
  module HubLink
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hub_link
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.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-05-15 00:00:00.000000000 Z
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -158,8 +158,11 @@ files:
158
158
  - lib/hub_link/api/review.rb
159
159
  - lib/hub_link/api/review_request.rb
160
160
  - lib/hub_link/batch.rb
161
+ - lib/hub_link/callbacks.rb
161
162
  - lib/hub_link/configuration.rb
162
163
  - lib/hub_link/core_ext/float.rb
164
+ - lib/hub_link/importer.rb
165
+ - lib/hub_link/insert.rb
163
166
  - lib/hub_link/slicer.rb
164
167
  - lib/hub_link/stream.rb
165
168
  - lib/hub_link/version.rb