ghuls 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cli/CHANGELOG.md +7 -0
- data/cli/lib/ghuls/cli.rb +28 -10
- data/utils/utilities.rb +89 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57fd274e8ef0970e5b162dd964a03e0d300d6776
|
4
|
+
data.tar.gz: 67102aa993294944e1a5a1c29438f4d2f0d0d7a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e29f031fcbaf92e49ce774f96a8e3c3443c138bcf00c27a11602cdfdfe246f7ced2f79e38af11f9d244718e81dace07e6a520028ee7598ed527e2177a814aa8d
|
7
|
+
data.tar.gz: e889f014e5b211e7d7faf488ba9fba4b791b7d17ec600d8e4ddccb006f41577b551ee3b8496562cabb5c6a90616905c1c4243ee325c30ce1c8e55f4ced6c6a33
|
data/cli/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
## Version 1
|
3
|
+
### Version 1.1.0
|
4
|
+
* Organizations that the -g user contributed to are now supported.
|
5
|
+
* Better error-type-thing reporting.
|
6
|
+
* Catches Octokit::Unauthorized errors and returns false when initializing the client.
|
7
|
+
* Fix user_exists? error catching minor syntax bug.
|
8
|
+
|
9
|
+
|
3
10
|
### Version 1.0.2
|
4
11
|
* Actually fix load path stuff again.
|
5
12
|
|
data/cli/lib/ghuls/cli.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'octokit'
|
2
2
|
require 'base64'
|
3
3
|
require 'rainbow'
|
4
|
-
require 'string-utility'
|
5
4
|
require_relative "#{Dir.pwd}/utils/utilities"
|
6
5
|
|
7
6
|
module GHULS
|
@@ -56,24 +55,43 @@ module GHULS
|
|
56
55
|
true if @opts[:token].nil? && @opts[:pass].nil?
|
57
56
|
end
|
58
57
|
|
58
|
+
def output(percents)
|
59
|
+
percents.each do |l, p|
|
60
|
+
color = Utilities.get_color_for_language(l.to_s, @colors)
|
61
|
+
puts Rainbow("#{l}: #{p}%").color(color)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def fail_after_analyze
|
66
|
+
puts 'Sorry, something went wrong.'
|
67
|
+
puts "We either could not find anyone under the name #{@opts[:get]}, " \
|
68
|
+
'or we could not find any data for them.'
|
69
|
+
puts 'Please try again with a different user. If you believe this is ' \
|
70
|
+
'an error, please report it to the developer.'
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
|
59
74
|
# Simply runs the program.
|
60
75
|
def run
|
61
76
|
puts @usage if failed?
|
62
77
|
puts @help if @opts[:help]
|
63
78
|
exit if failed?
|
64
79
|
puts "Getting language data for #{@opts[:get]}..."
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
80
|
+
user_percents = Utilities.analyze_user(@opts[:get], @gh)
|
81
|
+
org_percents = Utilities.analyze_orgs(@opts[:get], @gh)
|
82
|
+
|
83
|
+
if user_percents != false
|
84
|
+
output(user_percents)
|
85
|
+
if org_percents != false
|
86
|
+
puts 'Getting language data for their organizations...'
|
87
|
+
output(org_percents)
|
88
|
+
else
|
89
|
+
exit
|
71
90
|
end
|
72
91
|
else
|
73
|
-
|
74
|
-
'Please try again with a user that exists.'
|
75
|
-
exit
|
92
|
+
fail_after_analyze
|
76
93
|
end
|
94
|
+
exit
|
77
95
|
end
|
78
96
|
end
|
79
97
|
end
|
data/utils/utilities.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'octokit'
|
2
|
+
require 'string-utility'
|
2
3
|
|
3
4
|
module Utilities
|
4
5
|
# Gets the Octokit and colors for the program.
|
@@ -12,8 +13,12 @@ module Utilities
|
|
12
13
|
user = opts[:user]
|
13
14
|
gh = Octokit::Client.new(login: user, password: pass) if token.nil?
|
14
15
|
gh = Octokit::Client.new(access_token: token) unless token.nil?
|
15
|
-
|
16
|
-
|
16
|
+
begin
|
17
|
+
encoded = gh.contents('ozh/github-colors', path: 'colors.json')[:content]
|
18
|
+
colors = JSON.parse(Base64.decode64(encoded))
|
19
|
+
rescue Octokit::Unauthorized
|
20
|
+
return false
|
21
|
+
end
|
17
22
|
{ git: gh, colors: colors }
|
18
23
|
end
|
19
24
|
|
@@ -25,21 +30,54 @@ module Utilities
|
|
25
30
|
full.at(full.index(single) + 1)
|
26
31
|
end
|
27
32
|
|
33
|
+
# Gets whether or not the user exists.
|
34
|
+
# @param username [String] The user to check
|
35
|
+
# @param github [Octokit::Client] The instance of Octokit to use.
|
36
|
+
# @return [Boolean] True if it does, false if it doesn't.
|
28
37
|
def self.user_exists?(username, github)
|
29
38
|
begin
|
30
|
-
github.user(username)
|
39
|
+
github.user(username)
|
31
40
|
rescue Octokit::NotFound
|
32
41
|
return false
|
33
42
|
end
|
34
43
|
true
|
35
44
|
end
|
36
45
|
|
46
|
+
# Returns the repos in the user's organizations that they have actually
|
47
|
+
# contributed to.
|
48
|
+
# @param username [String] See #user_exists?
|
49
|
+
# @param github [Octokit::Client] See #user_exists?
|
50
|
+
# @return [Array] All the repository full names that the user has contributed
|
51
|
+
# to.
|
52
|
+
def self.get_org_repos(username, github)
|
53
|
+
orgs = github.organizations(username)
|
54
|
+
repos = []
|
55
|
+
orgs.each do |o|
|
56
|
+
repos += github.repositories(o[:login])
|
57
|
+
end
|
58
|
+
true_repos = []
|
59
|
+
repos.each do |r|
|
60
|
+
begin
|
61
|
+
is_collaborator = github.collaborator?(r[:full_name], username)
|
62
|
+
rescue Octokit::Forbidden
|
63
|
+
next
|
64
|
+
end
|
65
|
+
if is_collaborator
|
66
|
+
next if r[:fork]
|
67
|
+
true_repos.push(r[:full_name])
|
68
|
+
else
|
69
|
+
next
|
70
|
+
end
|
71
|
+
end
|
72
|
+
true_repos
|
73
|
+
end
|
74
|
+
|
37
75
|
# Gets the langauges and their bytes for the :user.
|
38
76
|
# @param username [String] The username to get info for.
|
39
77
|
# @param github [OctoKit::Client] The instance of Octokit::Client.
|
40
78
|
# @return [Hash] The languages and their bytes, as formatted as
|
41
79
|
# { :Ruby => 129890, :CoffeeScript => 5970 }
|
42
|
-
def self.
|
80
|
+
def self.get_user_langs(username, github)
|
43
81
|
repos = github.repositories(username)
|
44
82
|
langs = {}
|
45
83
|
repos.each do |r|
|
@@ -57,6 +95,23 @@ module Utilities
|
|
57
95
|
langs
|
58
96
|
end
|
59
97
|
|
98
|
+
def self.get_org_langs(username, github)
|
99
|
+
org_repos = get_org_repos(username, github)
|
100
|
+
langs = {}
|
101
|
+
org_repos.each do |r|
|
102
|
+
repo_langs = github.languages(r)
|
103
|
+
repo_langs.each do |l, b|
|
104
|
+
if langs[l].nil?
|
105
|
+
langs[l] = b
|
106
|
+
else
|
107
|
+
existing = langs[l]
|
108
|
+
langs[l] = existing + b
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
langs
|
113
|
+
end
|
114
|
+
|
60
115
|
# Gets the percentage for the given numbers.
|
61
116
|
# @param part [Fixnum] The partial value.
|
62
117
|
# @param whole [Fixnum] The whole value.
|
@@ -71,20 +126,39 @@ module Utilities
|
|
71
126
|
# @return [String] The 6 digit hexidecimal color.
|
72
127
|
# @return [Nil] If there is no defined color for the language.
|
73
128
|
def self.get_color_for_language(lang, colors)
|
74
|
-
|
129
|
+
if colors[lang]['color'].nil?
|
130
|
+
return StringUtility.random_color_six
|
131
|
+
else
|
132
|
+
return colors[lang]['color']
|
133
|
+
end
|
75
134
|
end
|
76
135
|
|
77
|
-
def self.
|
136
|
+
def self.get_language_percentages(langs)
|
137
|
+
total = 0
|
138
|
+
langs.each { |_, b| total += b }
|
139
|
+
lang_percents = {}
|
140
|
+
langs.each do |l, b|
|
141
|
+
percent = Utilities.calculate_percent(b, total.to_f)
|
142
|
+
lang_percents[l] = percent.round(2)
|
143
|
+
end
|
144
|
+
lang_percents
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.analyze_orgs(username, github)
|
78
148
|
if user_exists?(username, github)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
149
|
+
langs = get_org_langs(username, github)
|
150
|
+
return false if langs.empty?
|
151
|
+
get_language_percentages(langs)
|
152
|
+
else
|
153
|
+
false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.analyze_user(username, github)
|
158
|
+
if user_exists?(username, github)
|
159
|
+
langs = get_user_langs(username, github)
|
160
|
+
return false if langs.empty?
|
161
|
+
get_language_percentages(langs)
|
88
162
|
else
|
89
163
|
false
|
90
164
|
end
|