ghuls-lib 1.1.1 → 1.1.2
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/lib/ghuls/lib.rb +47 -7
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67ca5effd388bccc1045323ba0a05507c566f682
|
4
|
+
data.tar.gz: b93f7737533f3ac78d65fa01502d55cee400f7b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0057082b97bed7d49c6c6d75a67c9bd351b30430d0b332f6a38f63de3dd7b8a1750a4ebaf3ad6b48ff11fc40271247180c7299cb18da752f14f67592e374f95
|
7
|
+
data.tar.gz: 0a138e32b0fdc2eff4486742bfab2acb45684cab1deeba9007ff74bff35b840e2e0eb14277f24a0835dbbb89dd00a786d58e7aaa298fa344bd9aaab61299fef1
|
data/lib/ghuls/lib.rb
CHANGED
@@ -45,6 +45,20 @@ module GHULS
|
|
45
45
|
true
|
46
46
|
end
|
47
47
|
|
48
|
+
# Gets the username and checks if it exists in the process.
|
49
|
+
# @param userid [Fixnum] The user ID.
|
50
|
+
# @param github [Octokit::Client] See #user_exists?
|
51
|
+
# @return [String] The username
|
52
|
+
# @return [Boolean] False if it does not exist.
|
53
|
+
def self.get_user_and_check(userid, github)
|
54
|
+
begin
|
55
|
+
username = github.user(userid)
|
56
|
+
rescue Octokit::NotFound
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
username[:login]
|
60
|
+
end
|
61
|
+
|
48
62
|
# Returns the repos in the user's organizations that they have actually
|
49
63
|
# contributed to.
|
50
64
|
# @param username [String] See #user_exists?
|
@@ -72,9 +86,9 @@ module GHULS
|
|
72
86
|
true_repos
|
73
87
|
end
|
74
88
|
|
75
|
-
# Gets the langauges and their bytes for the
|
76
|
-
# @param username [String]
|
77
|
-
# @param github [
|
89
|
+
# Gets the langauges and their bytes for the user.
|
90
|
+
# @param username [String] See #user_exists?
|
91
|
+
# @param github [Octokit::Client] See #user_exists?
|
78
92
|
# @return [Hash] The languages and their bytes, as formatted as
|
79
93
|
# { :Ruby => 129890, :CoffeeScript => 5970 }
|
80
94
|
def self.get_user_langs(username, github)
|
@@ -95,6 +109,10 @@ module GHULS
|
|
95
109
|
langs
|
96
110
|
end
|
97
111
|
|
112
|
+
# Gets the languages and their bytes for the user's organizations.
|
113
|
+
# @param username [String] See #user_exists?
|
114
|
+
# @param github [Octokit::Client] See #user_exists?
|
115
|
+
# @return [Hash] See #get_user_langs
|
98
116
|
def self.get_org_langs(username, github)
|
99
117
|
org_repos = get_org_repos(username, github)
|
100
118
|
langs = {}
|
@@ -133,6 +151,10 @@ module GHULS
|
|
133
151
|
end
|
134
152
|
end
|
135
153
|
|
154
|
+
# Gets the percentages for each language in a hash.
|
155
|
+
# @param langs [Hash] The language hash obtained by the get_langs methods.
|
156
|
+
# @return [Hash] The language percentages formatted as
|
157
|
+
# { Ruby: 50%, CoffeeScript: 50% }
|
136
158
|
def self.get_language_percentages(langs)
|
137
159
|
total = 0
|
138
160
|
langs.each { |_, b| total += b }
|
@@ -144,6 +166,11 @@ module GHULS
|
|
144
166
|
lang_percents
|
145
167
|
end
|
146
168
|
|
169
|
+
# Performs the main analysis of the user's organizations.
|
170
|
+
# @param username [String] See #user_exists?
|
171
|
+
# @param github [Octokit::Client] See #user_exists?
|
172
|
+
# @return [Hash] See #get_language_percentages
|
173
|
+
# @return [Boolean] False if user_exists? returns false.
|
147
174
|
def self.analyze_orgs(username, github)
|
148
175
|
if user_exists?(username, github)
|
149
176
|
langs = get_org_langs(username, github)
|
@@ -154,6 +181,11 @@ module GHULS
|
|
154
181
|
end
|
155
182
|
end
|
156
183
|
|
184
|
+
# Performs the main analysis of the user.
|
185
|
+
# @param username [String] See #user_exists?
|
186
|
+
# @param github [Octokit::Client] See #user_exists?
|
187
|
+
# @return [Hash] See #analyze_orgs
|
188
|
+
# @return [Boolean] See #analyze_orgs
|
157
189
|
def self.analyze_user(username, github)
|
158
190
|
if user_exists?(username, github)
|
159
191
|
langs = get_user_langs(username, github)
|
@@ -165,14 +197,22 @@ module GHULS
|
|
165
197
|
end
|
166
198
|
|
167
199
|
using StringUtility
|
200
|
+
# Gets a random GitHub user that actually has data to analyze.
|
201
|
+
# Must always get a user that exists and has repositories, so it will
|
202
|
+
# go through a loop infinitely until it gets one. Uses the GitHub Search
|
203
|
+
# to find the maximum number of users, which may not be the best way to do
|
204
|
+
# it. However, none of the documented GitHub APIs show that we can get the
|
205
|
+
# total number of GitHub users.
|
206
|
+
# @param github [Octokit::Client] See #user_exists?
|
207
|
+
# @return [String] A random username.
|
168
208
|
def self.get_random_user(github)
|
169
209
|
source = open('https://github.com/search?utf8=%E2%9C%93&q=repos%3A%3E-1' \
|
170
210
|
'&type=Users&ref=searchresults').read
|
171
|
-
|
172
|
-
while
|
211
|
+
continue = false
|
212
|
+
while continue == false
|
173
213
|
userid = rand(source[/Showing (.*?) available users/, 1].to_i_separated)
|
174
|
-
user =
|
175
|
-
|
214
|
+
user = get_user_and_check(userid, github)
|
215
|
+
continue = true if user != false && !get_user_langs(user, github).empty?
|
176
216
|
end
|
177
217
|
user
|
178
218
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghuls-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Foster
|
@@ -69,3 +69,4 @@ signing_key:
|
|
69
69
|
specification_version: 4
|
70
70
|
summary: The library used for and by the GHULS applications.
|
71
71
|
test_files: []
|
72
|
+
has_rdoc:
|