Skip to content

Commit

Permalink
chore: show loading spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
markokajzer committed Feb 9, 2024
1 parent 2dcfc1e commit 73d6a94
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ ruby "3.3.0"

gem "octokit"
gem "activesupport"

# Progress
gem "whirly"
gem "paint"

# Output
gem "terminal-table"

group :development do
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ GEM
base64
faraday (>= 1, < 3)
sawyer (~> 0.9)
paint (2.3.0)
parallel (1.24.0)
parser (3.2.2.4)
ast (~> 2.4.1)
Expand Down Expand Up @@ -137,6 +138,8 @@ GEM
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
whirly (0.3.0)
unicode-display_width (>= 1.1)

PLATFORMS
arm64-darwin-22
Expand All @@ -147,13 +150,15 @@ DEPENDENCIES
awesome_print
debug
octokit
paint
rspec
rubocop-rspec
simplecov
standard
terminal-table
timecop
webmock
whirly

RUBY VERSION
ruby 3.3.0p0
Expand Down
26 changes: 16 additions & 10 deletions bin/leaderboard
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
#!/usr/bin/env ruby

require "active_support"
require "awesome_print"
require "whirly"

require_relative "../lib/config"
require_relative "../lib/spinner"

require_relative "../lib/pulls"
require_relative "../lib/repository"
require_relative "../lib/reviews"

require_relative "../lib/formatter"


Config.initialize!

raise Config::ConfigurationError, "Access token is required" if Config.access_token.nil?
raise Config::ConfigurationError, "Repository is required" if Config.repositories.empty?

puts "Fetching pull requests..."
puts "Fetching pull requests for #{Config.repositories}..." if Config.log_level == :debug
puts "Fetching pull requests for #{Config.repositories.join(", ")}..." if Config.repositories.size > 1

pulls = Config.repositories.flat_map.with_index do |name, index|
puts "Fetching pull requests for #{name}... #{index + 1}/#{Config.repositories.size}" + " " * 10 + "\r" if Config.repositories.size > 1
pulls = Spinner.start do
Config.repositories.flat_map.with_index do |name, index|
Whirly.status = if Config.repositories.one?
"Fetching pull requests..."
else
"Fetching pull requests #{name}... (#{index + 1}/#{Config.repositories.size})"
end

Repository.new(name:).pulls
Repository.new(name:).pulls
end
end
puts
puts "Found #{pulls.size} pull requests."

reviews =
reviews = Spinner.start do
pulls.flat_map.with_index do |pull, index|
puts "Fetching reviews for all pull requests... #{index + 1}/#{pulls.size}" + " " * 10 + "\r"
Whirly.status = "Fetching reviews... (#{index + 1}/#{pulls.size})"

Reviews.for(pull:)
end
end
puts "Found #{reviews.size} reviews."
puts

puts Formatter.new(reviews).to_table
15 changes: 15 additions & 0 deletions lib/spinner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "whirly"

module Spinner
extend self

def start
result = nil

Whirly.start(spinner: "dots", stop: "✔") do
result = yield
end

result
end
end
18 changes: 18 additions & 0 deletions spec/spinner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "spinner"

RSpec.describe Spinner do
before do
allow(Whirly).to receive(:start).and_yield
end

it "shows the spinner" do
described_class.start { "result" }

expect(Whirly).to have_received(:start).with(spinner: "dots", stop: "✔")
end

it "returns the result of the block" do
expect(described_class.start { "result" })
.to eq("result")
end
end

0 comments on commit 73d6a94

Please sign in to comment.