Class: Spill::Collectors::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/spill/collectors/github.rb

Constant Summary collapse

MAX_PAGES =
3
PAGE_SIZE =
100
SEARCH_PAGE_SIZE =
100
OPEN_PR_GRACE_SECONDS =

An open PR is shown in Doing only if created in-window or up to 14 days before it.

14 * 86_400
DEFAULT_RUNNER =
lambda do |args|
  out, _err, status = Open3.capture3("gh", *args)
  [ out, status.success? ]
rescue Errno::ENOENT
  [ "", false ]
end

Instance Method Summary collapse

Constructor Details

#initialize(runner: DEFAULT_RUNNER) ⇒ Github

Returns a new instance of Github.



21
22
23
# File 'lib/spill/collectors/github.rb', line 21

def initialize(runner: DEFAULT_RUNNER)
  @runner = runner
end

Instance Method Details

#collect(window:, scope: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/spill/collectors/github.rb', line 25

def collect(window:, scope: nil)
   = 
  return nil if .nil?

  raw = fetch_raw_events()
  return nil if raw.nil?

  events = raw.filter_map { |item| map_event(item) }
              .select { |event| event.timestamp >= window.since }
  events = dedupe_commented(events)

  open_prs = open_pr_events(, window)
  return nil if open_prs.nil?

  merged_prs = merged_pr_events(, window)
  return nil if merged_prs.nil?

  opened_prs = opened_pr_events(, window)
  return nil if opened_prs.nil?

  events.concat(open_prs)
  events.concat(merged_prs)
  events.concat(opened_prs)
  events = dedupe_search_capped(events)
  events << truncation_event(raw) if truncated?(raw, window)
  events = apply_scope(events, scope) unless scope.nil?
  events
rescue StandardError
  nil
end