ghuls 1.3.0 → 1.4.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 → CHANGELOG.md} +0 -0
- data/bin/ghuls +2 -2
- data/{cli/lib → lib}/ghuls/cli.rb +6 -4
- data/lib/ghuls.rb +1 -0
- metadata +33 -6
- data/cli/lib/ghuls.rb +0 -2
- data/utils/utilities.rb +0 -164
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f6d5c7d684db6106c93dd68df4b8dbfff31fb81
|
4
|
+
data.tar.gz: a9bdddbf1aefbe8f0073cb6fdc02935d3056096f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53476ef791abc37e6fb268c027315ee647afd179efbe36027753d5062ec4b174abc8a335a4b8b09bfeb1bafcaf7fdfe5fb282e9e9ba7a8267878398219c3b4f8
|
7
|
+
data.tar.gz: 019bc62be666c3d4e22144812cb104e143053ca8c70877bc220589fb6e121ff89a0793f3888498b1171ce28907ba3732ea80e39e4d2624d9f98439de52206afa
|
File without changes
|
data/bin/ghuls
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
path = File.expand_path('
|
4
|
+
path = File.expand_path('../lib', __FILE__)
|
5
5
|
$LOAD_PATH.unshift(path)
|
6
6
|
|
7
|
-
|
7
|
+
require_relative '../lib/ghuls'
|
8
8
|
|
9
9
|
cli = GHULS::CLI.new
|
10
10
|
cli.run
|
@@ -2,7 +2,7 @@ require 'octokit'
|
|
2
2
|
require 'base64'
|
3
3
|
require 'rainbow'
|
4
4
|
require 'progress_bar'
|
5
|
-
|
5
|
+
require 'ghuls'
|
6
6
|
|
7
7
|
module GHULS
|
8
8
|
class CLI
|
@@ -17,6 +17,7 @@ module GHULS
|
|
17
17
|
when '-t', '--token' then @opts[:token] = Utilities.get_next(arg, args)
|
18
18
|
when '-g', '--get' then @opts[:get] = Utilities.get_next(arg, args)
|
19
19
|
when '-d', '--debug' then @opts[:debug] = true
|
20
|
+
when '-r', '--random' then @opts[:get] = nil
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -38,14 +39,15 @@ module GHULS
|
|
38
39
|
}
|
39
40
|
|
40
41
|
@usage = 'Usage: ghuls [-h] [-un] username [-pw] password [-t] token ' \
|
41
|
-
'[-g] username'
|
42
|
+
'[-g] username [-r] [-d]'
|
42
43
|
@help = "-h, --help Show helpful information.\n" \
|
43
44
|
"-d, --debug Provide debug information.\n" \
|
44
45
|
"-un, --user The username to log in as.\n" \
|
45
46
|
"-pw, --pass The password for that username.\n" \
|
46
47
|
'-t, --token The token to log in as. This will be preferred ' \
|
47
48
|
"over username and password authentication.\n" \
|
48
|
-
|
49
|
+
"-g, --get The username/organization to analyze.\n" \
|
50
|
+
"-r, --random Use a random user.\n"
|
49
51
|
|
50
52
|
parse_options(args)
|
51
53
|
@bar = ProgressBar.new(5) if @opts[:debug]
|
@@ -65,7 +67,6 @@ module GHULS
|
|
65
67
|
# @return [Boolean] False if it did not fail, true if it did.
|
66
68
|
def failed?
|
67
69
|
false if @opts[:help]
|
68
|
-
|
69
70
|
true if @opts[:get].nil?
|
70
71
|
true if @opts[:token].nil? && @opts[:user].nil?
|
71
72
|
true if @opts[:token].nil? && @opts[:pass].nil?
|
@@ -93,6 +94,7 @@ module GHULS
|
|
93
94
|
puts @help if @opts[:help]
|
94
95
|
exit if failed?
|
95
96
|
increment
|
97
|
+
@opts[:get] = Utilities.get_random_user(@gh) if @opts[:get].nil?
|
96
98
|
user_percents = Utilities.analyze_user(@opts[:get], @gh)
|
97
99
|
increment
|
98
100
|
org_percents = Utilities.analyze_orgs(@opts[:get], @gh)
|
data/lib/ghuls.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'ghuls/cli'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghuls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Foster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ghuls-lib
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: progress_bar
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: Getting GitHub repository language data by user! It also has a web alternative
|
56
84
|
at http://ghuls.herokuapp.com
|
57
85
|
email: elifosterwy@gmail.com
|
@@ -60,11 +88,10 @@ executables:
|
|
60
88
|
extensions: []
|
61
89
|
extra_rdoc_files: []
|
62
90
|
files:
|
91
|
+
- CHANGELOG.md
|
63
92
|
- bin/ghuls
|
64
|
-
-
|
65
|
-
-
|
66
|
-
- cli/lib/ghuls/cli.rb
|
67
|
-
- utils/utilities.rb
|
93
|
+
- lib/ghuls.rb
|
94
|
+
- lib/ghuls/cli.rb
|
68
95
|
homepage: http://ghuls.herokuapp.com
|
69
96
|
licenses: []
|
70
97
|
metadata: {}
|
data/cli/lib/ghuls.rb
DELETED
data/utils/utilities.rb
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
require 'octokit'
|
2
|
-
require 'string-utility'
|
3
|
-
|
4
|
-
module Utilities
|
5
|
-
# Gets the Octokit and colors for the program.
|
6
|
-
# @param opts [Hash] The options to use. The ones that are used by this method
|
7
|
-
# are: :token, :pass, and :user.
|
8
|
-
# @return [Hash] A hash containing objects formatted as
|
9
|
-
# { git: Octokit::Client, colors: JSON }
|
10
|
-
def self.configure_stuff(opts = {})
|
11
|
-
token = opts[:token]
|
12
|
-
pass = opts[:pass]
|
13
|
-
user = opts[:user]
|
14
|
-
gh = Octokit::Client.new(login: user, password: pass) if token.nil?
|
15
|
-
gh = Octokit::Client.new(access_token: token) unless token.nil?
|
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
|
22
|
-
{ git: gh, colors: colors }
|
23
|
-
end
|
24
|
-
|
25
|
-
# Gets the next value in an array.
|
26
|
-
# @param single [Any] The current value.
|
27
|
-
# @param full [Array] The main array to parse.
|
28
|
-
# @return [Any] The next value in the array.
|
29
|
-
def self.get_next(single, full)
|
30
|
-
full.at(full.index(single) + 1)
|
31
|
-
end
|
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.
|
37
|
-
def self.user_exists?(username, github)
|
38
|
-
begin
|
39
|
-
github.user(username)
|
40
|
-
rescue Octokit::NotFound
|
41
|
-
return false
|
42
|
-
end
|
43
|
-
true
|
44
|
-
end
|
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
|
-
next if r[:fork]
|
61
|
-
contributors = github.contributors(r[:full_name])
|
62
|
-
contributors.each do |c|
|
63
|
-
if c[:login] == username
|
64
|
-
true_repos.push(r[:full_name])
|
65
|
-
else
|
66
|
-
next
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
true_repos
|
71
|
-
end
|
72
|
-
|
73
|
-
# Gets the langauges and their bytes for the :user.
|
74
|
-
# @param username [String] The username to get info for.
|
75
|
-
# @param github [OctoKit::Client] The instance of Octokit::Client.
|
76
|
-
# @return [Hash] The languages and their bytes, as formatted as
|
77
|
-
# { :Ruby => 129890, :CoffeeScript => 5970 }
|
78
|
-
def self.get_user_langs(username, github)
|
79
|
-
repos = github.repositories(username)
|
80
|
-
langs = {}
|
81
|
-
repos.each do |r|
|
82
|
-
next if r[:fork]
|
83
|
-
repo_langs = github.languages(r[:full_name])
|
84
|
-
repo_langs.each do |l, b|
|
85
|
-
if langs[l].nil?
|
86
|
-
langs[l] = b
|
87
|
-
else
|
88
|
-
existing = langs[l]
|
89
|
-
langs[l] = existing + b
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
langs
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.get_org_langs(username, github)
|
97
|
-
org_repos = get_org_repos(username, github)
|
98
|
-
langs = {}
|
99
|
-
org_repos.each do |r|
|
100
|
-
repo_langs = github.languages(r)
|
101
|
-
repo_langs.each do |l, b|
|
102
|
-
if langs[l].nil?
|
103
|
-
langs[l] = b
|
104
|
-
else
|
105
|
-
existing = langs[l]
|
106
|
-
langs[l] = existing + b
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
langs
|
111
|
-
end
|
112
|
-
|
113
|
-
# Gets the percentage for the given numbers.
|
114
|
-
# @param part [Fixnum] The partial value.
|
115
|
-
# @param whole [Fixnum] The whole value.
|
116
|
-
# @return [Fixnum] The percentage that part is of whole.
|
117
|
-
def self.calculate_percent(part, whole)
|
118
|
-
(part / whole) * 100
|
119
|
-
end
|
120
|
-
|
121
|
-
# Gets the defined color for the language.
|
122
|
-
# @param lang [String] The language name.
|
123
|
-
# @param colors [Hash] The hash of colors and languages.
|
124
|
-
# @return [String] The 6 digit hexidecimal color.
|
125
|
-
# @return [Nil] If there is no defined color for the language.
|
126
|
-
def self.get_color_for_language(lang, colors)
|
127
|
-
if colors[lang]['color'].nil?
|
128
|
-
return StringUtility.random_color_six
|
129
|
-
else
|
130
|
-
return colors[lang]['color']
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.get_language_percentages(langs)
|
135
|
-
total = 0
|
136
|
-
langs.each { |_, b| total += b }
|
137
|
-
lang_percents = {}
|
138
|
-
langs.each do |l, b|
|
139
|
-
percent = Utilities.calculate_percent(b, total.to_f)
|
140
|
-
lang_percents[l] = percent.round(2)
|
141
|
-
end
|
142
|
-
lang_percents
|
143
|
-
end
|
144
|
-
|
145
|
-
def self.analyze_orgs(username, github)
|
146
|
-
if user_exists?(username, github)
|
147
|
-
langs = get_org_langs(username, github)
|
148
|
-
return false if langs.empty?
|
149
|
-
get_language_percentages(langs)
|
150
|
-
else
|
151
|
-
false
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def self.analyze_user(username, github)
|
156
|
-
if user_exists?(username, github)
|
157
|
-
langs = get_user_langs(username, github)
|
158
|
-
return false if langs.empty?
|
159
|
-
get_language_percentages(langs)
|
160
|
-
else
|
161
|
-
false
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|