Class: Legion::TTY::Background::GitHubProbe
- Inherits:
-
Object
- Object
- Legion::TTY::Background::GitHubProbe
- 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, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
#run_quick_async(queue) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(token: nil, logger: nil) ⇒ GitHubProbe
Returns a new instance of GitHubProbe.
15 16 17 18 |
# File 'lib/legion/tty/background/github_probe.rb', line 15 def initialize(token: nil, logger: nil) @log = logger @token = token || resolve_token end |
Instance Method Details
#run_async(queue, remotes: [], quick_profile: nil) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/legion/tty/background/github_probe.rb', line 43 def run_async(queue, remotes: [], quick_profile: nil) Thread.new do @log&.log('github', "probing with #{remotes.size} remotes: #{remotes.first(5).inspect}") @log&.log('github', "token: #{@token ? 'present' : 'NONE'}") @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 @log&.log('github', "probe complete in #{elapsed}ms") queue.push({ type: :github_probe_complete, data: result }) rescue StandardError => e @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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/legion/tty/background/github_probe.rb', line 21 def run_quick_async(queue) Thread.new do unless @token @log&.log('github', 'quick probe skipped (no token)') queue.push({ type: :github_quick_complete, data: nil }) return end @log&.log('github', 'quick probe: fetching /user + recent commits') t0 = Time.now result = fetch_quick_profile elapsed = ((Time.now - t0) * 1000).round @log&.log('github', "quick probe complete in #{elapsed}ms") queue.push({ type: :github_quick_complete, data: result }) rescue StandardError => e @log&.log('github', "quick probe ERROR: #{e.class}: #{e.}") queue.push({ type: :github_quick_error, error: e. }) end end |