reponaut 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/reponaut +19 -1
- data/features/count.feature +17 -25
- data/features/help.feature +36 -21
- data/features/list.feature +210 -8
- data/features/step_definitions/github_steps.rb +5 -0
- data/lib/reponaut.rb +14 -1
- data/lib/reponaut/command.rb +37 -0
- data/lib/reponaut/commands/count.rb +41 -0
- data/lib/reponaut/commands/list.rb +40 -0
- data/lib/reponaut/ext/ENV.rb +9 -0
- data/lib/reponaut/ext/mercenary.rb +16 -0
- data/lib/reponaut/github.rb +37 -7
- data/lib/reponaut/presenter.rb +30 -0
- data/lib/reponaut/sorter.rb +29 -0
- data/lib/reponaut/version.rb +1 -1
- data/reponaut.gemspec +9 -3
- data/spec/fixtures/rate_limiting.json +4 -0
- data/spec/fixtures/repos/mdippery/Smyck-Color-Scheme.json +266 -0
- data/spec/fixtures/repos/mdippery/dnsimple-python.json +266 -0
- data/spec/fixtures/repos/mdippery/nginx.vim.json +266 -0
- data/spec/fixtures/repos/mdippery/staticgenerator.json +266 -0
- data/spec/reponaut/github_spec.rb +9 -0
- data/spec/reponaut/presenter_spec.rb +59 -0
- data/spec/reponaut/sorter_spec.rb +64 -0
- metadata +41 -12
- data/lib/reponaut/application.rb +0 -99
data/lib/reponaut/application.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'slop'
|
2
|
-
require 'reponaut/github'
|
3
|
-
require 'reponaut/version'
|
4
|
-
require 'reponaut/ext/hash'
|
5
|
-
|
6
|
-
module Reponaut
|
7
|
-
class Application
|
8
|
-
class << self
|
9
|
-
def run
|
10
|
-
opts = Slop.parse do |o|
|
11
|
-
o.banner = 'Usage: reponaut [OPTIONS] USERNAME [LANGUAGE]'
|
12
|
-
o.separator ''
|
13
|
-
o.separator 'Options:'
|
14
|
-
|
15
|
-
o.bool '-c', '--count', 'Sort by repo count'
|
16
|
-
o.bool '-f', '--ignore-forks', 'Ignore forked repos'
|
17
|
-
|
18
|
-
o.on '-h', '--help' do
|
19
|
-
puts o
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
|
23
|
-
o.on '--version' do
|
24
|
-
puts "reponaut, version #{Reponaut::VERSION}"
|
25
|
-
exit
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
username = opts.arguments.first
|
30
|
-
unless username
|
31
|
-
$stderr.puts opts
|
32
|
-
exit 1
|
33
|
-
end
|
34
|
-
|
35
|
-
if opts.arguments.count > 1 && opts.count?
|
36
|
-
$stderr.puts 'Cannot pass -c when filtering by language'
|
37
|
-
exit 2
|
38
|
-
end
|
39
|
-
|
40
|
-
gh = Reponaut::GitHub::Client.new(username)
|
41
|
-
repos = gh.repos.reject { |r| r.language.nil? }
|
42
|
-
repos = repos.find_all { |r| r.source? } if opts.ignore_forks?
|
43
|
-
if opts.arguments.count > 1
|
44
|
-
print_repos(username, opts.arguments[1], repos)
|
45
|
-
else
|
46
|
-
print_repo_counts(username, repos, opts.count?)
|
47
|
-
end
|
48
|
-
rescue Reponaut::GitHub::NoSuchUserError => e
|
49
|
-
$stderr.puts "No such user: #{e}"
|
50
|
-
exit 4
|
51
|
-
rescue Slop::UnknownOption => e
|
52
|
-
$stderr.puts e
|
53
|
-
$stderr.puts 'Run `reponaut --help` for help information'
|
54
|
-
exit 2
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def print_repos(username, language, repos)
|
60
|
-
repos = repos.select { |r| r.language.downcase == language.downcase }
|
61
|
-
if repos.empty?
|
62
|
-
$stderr.puts "#{username} has no repositories written in #{language}"
|
63
|
-
exit 4
|
64
|
-
end
|
65
|
-
repos.sort.each do |r|
|
66
|
-
line = r.name
|
67
|
-
line = "#{line} -> #{r.upstream}" if r.fork?
|
68
|
-
puts line
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def print_repo_counts(username, repos, sort_by_count)
|
73
|
-
if repos.count < 1
|
74
|
-
$stderr.puts "#{username} has no repositories"
|
75
|
-
exit 3
|
76
|
-
end
|
77
|
-
stats = Reponaut::StatisticsCalculator.new(repos)
|
78
|
-
counts = stats.language_counts.pairs
|
79
|
-
counts = if sort_by_count
|
80
|
-
counts.sort do |a, b|
|
81
|
-
res = b[1] <=> a[1]
|
82
|
-
if res == 0
|
83
|
-
a[0] <=> b[0]
|
84
|
-
else
|
85
|
-
res
|
86
|
-
end
|
87
|
-
end
|
88
|
-
else
|
89
|
-
counts.sort { |a, b| a[0] <=> b[0] }
|
90
|
-
end
|
91
|
-
longest_label = counts.map { |e| e[0].length }.max
|
92
|
-
longest_count = counts.map { |e| e[1].to_s.length }.max
|
93
|
-
counts.each do |e|
|
94
|
-
printf "%-*s %*d\n", longest_label, e[0], longest_count, e[1]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|