Class: Legion::TTY::Background::GitHubProbe
- Inherits:
-
Object
- Object
- Legion::TTY::Background::GitHubProbe
- Includes:
- Logging::Helper
- Defined in:
- lib/legion/tty/background/github_probe.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- API_BASE =
'https://api.github.com'- USER_AGENT =
'legion-tty/github-probe'
Instance Method Summary collapse
-
#initialize(token: nil, logger: nil) ⇒ GitHubProbe
constructor
A new instance of GitHubProbe.
-
#run_async(queue, remotes: [], quick_profile: nil) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#run_quick_async(queue) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(token: nil, logger: nil) ⇒ GitHubProbe
Returns a new instance of GitHubProbe.
18 19 20 21 |
# File 'lib/legion/tty/background/github_probe.rb', line 18 def initialize(token: nil, logger: nil) @boot_log = logger @token = token || resolve_token end |
Instance Method Details
#run_async(queue, remotes: [], quick_profile: nil) ⇒ Object
rubocop:disable Metrics/AbcSize
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/legion/tty/background/github_probe.rb', line 46 def run_async(queue, remotes: [], quick_profile: nil) Thread.new do @boot_log&.log('github', "probing with #{remotes.size} remotes: #{remotes.first(5).inspect}") @boot_log&.log('github', "token: #{@token ? 'present' : 'NONE'}") @boot_log&.log('github', "quick_profile: #{quick_profile ? 'reusing' : 'none'}") t0 = Time.now result = if @token build_authenticated_result(remotes, quick_profile: quick_profile) else build_public_result(remotes) end elapsed = ((Time.now - t0) * 1000).round @boot_log&.log('github', "probe complete in #{elapsed}ms") queue.push({ type: :github_probe_complete, data: result }) rescue StandardError => e @boot_log&.log('github', "ERROR: #{e.class}: #{e.}") queue.push({ type: :github_error, error: e. }) end end |
#run_quick_async(queue) ⇒ Object
rubocop:disable Metrics/AbcSize
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/legion/tty/background/github_probe.rb', line 24 def run_quick_async(queue) Thread.new do unless @token @boot_log&.log('github', 'quick probe skipped (no token)') queue.push({ type: :github_quick_complete, data: nil }) return end @boot_log&.log('github', 'quick probe: fetching /user + recent commits') t0 = Time.now result = fetch_quick_profile elapsed = ((Time.now - t0) * 1000).round @boot_log&.log('github', "quick probe complete in #{elapsed}ms") queue.push({ type: :github_quick_complete, data: result }) rescue StandardError => e @boot_log&.log('github', "quick probe ERROR: #{e.class}: #{e.}") queue.push({ type: :github_quick_error, error: e. }) end end |