ghuls 1.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 +7 -0
- data/bin/ghuls +10 -0
- data/cli/lib/ghuls/cli.rb +79 -0
- data/cli/lib/ghuls.rb +2 -0
- data/utils/utilities.rb +92 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5794b74db3ca3e7321804ed2dfffbfab6255513d
|
4
|
+
data.tar.gz: 7411ab229a1404c195d4383ba95d5c6d563c6ba2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c0ba1988d217fc7bd2b064336c50c54b60e35a2f9ba1f821190c670bf3bbf8e12d9e73da88913105ebd44cf09763c5683eb59069b3cd1865f4c8a1c0ddc6090c
|
7
|
+
data.tar.gz: ed658c22b769fcc212631e7c8c9cccf5fcadca2653c4874398a79b8ecd4633a65bbb06c137ecd0c256580b1ae702ab27632b1c1b6e0cbe9286e840c576ecba3d
|
data/bin/ghuls
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
require 'base64'
|
3
|
+
require 'rainbow'
|
4
|
+
require 'string-utility'
|
5
|
+
require_relative "#{Dir.pwd}/utils/utilities"
|
6
|
+
|
7
|
+
module GHULS
|
8
|
+
class CLI
|
9
|
+
# Parses the arguments (typically ARGV) into a usable hash.
|
10
|
+
# @param args [Array] The arguments to parse.
|
11
|
+
def parse_options(args)
|
12
|
+
args.each do |arg|
|
13
|
+
case arg
|
14
|
+
when '-h', '--help' then @opts[:help] = true
|
15
|
+
when '-un', '--user' then @opts[:user] = Utilities.get_next(arg, args)
|
16
|
+
when '-pw', '--pass' then @opts[:pass] = Utilities.get_next(arg, args)
|
17
|
+
when '-t', '--token' then @opts[:token] = Utilities.get_next(arg, args)
|
18
|
+
when '-g', '--get' then @opts[:get] = Utilities.get_next(arg, args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Creates a new instance of GHULS::CLI
|
24
|
+
# @param args [Array] The arguments for the CLI.
|
25
|
+
def initialize(args = ARGV)
|
26
|
+
@opts = {
|
27
|
+
help: false,
|
28
|
+
user: nil,
|
29
|
+
pass: nil,
|
30
|
+
token: nil,
|
31
|
+
get: nil
|
32
|
+
}
|
33
|
+
|
34
|
+
@usage = 'Usage: ghuls [-h] [-un] username [-pw] password [-t] token ' \
|
35
|
+
'[-g] username'
|
36
|
+
@help = "-h, --help Show helpful information.\n" \
|
37
|
+
"-un, --user The username to log in as.\n" \
|
38
|
+
"-pw, --pass The password for that username.\n" \
|
39
|
+
'-t, --token The token to log in as. This will be preferred ' \
|
40
|
+
"over username and password authentication.\n" \
|
41
|
+
'-g, --get The username/organization to analyze.'
|
42
|
+
|
43
|
+
parse_options(args)
|
44
|
+
config = Utilities.configure_stuff(@opts)
|
45
|
+
@gh = config[:git]
|
46
|
+
@colors = config[:colors]
|
47
|
+
end
|
48
|
+
|
49
|
+
# Whether or not the script should fail.
|
50
|
+
# @return [Boolean] False if it did not fail, true if it did.
|
51
|
+
def failed?
|
52
|
+
false if @opts[:help]
|
53
|
+
|
54
|
+
true if @opts[:get].nil?
|
55
|
+
true if @opts[:token].nil? && @opts[:user].nil?
|
56
|
+
true if @opts[:token].nil? && @opts[:pass].nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
# Simply runs the program.
|
60
|
+
def run
|
61
|
+
puts @usage if failed?
|
62
|
+
puts @help if @opts[:help]
|
63
|
+
exit if failed?
|
64
|
+
puts "Getting language data for #{@opts[:get]}..."
|
65
|
+
percents = Utilities.analyze(@opts[:get], @gh)
|
66
|
+
if percents
|
67
|
+
percents.each do |l, p|
|
68
|
+
color = Utilities.get_color_for_language(l.to_s, @colors)
|
69
|
+
color = StringUtility.random_color_six if color.nil?
|
70
|
+
puts Rainbow("#{l}: #{p}%").color(color)
|
71
|
+
end
|
72
|
+
else
|
73
|
+
puts "Sorry, we could not find anyone under the name #{@opts[:get]}. " \
|
74
|
+
'Please try again with a user that exists.'
|
75
|
+
exit
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/cli/lib/ghuls.rb
ADDED
data/utils/utilities.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
|
3
|
+
module Utilities
|
4
|
+
# Gets the Octokit and colors for the program.
|
5
|
+
# @param opts [Hash] The options to use. The ones that are used by this method
|
6
|
+
# are: :token, :pass, and :user.
|
7
|
+
# @return [Hash] A hash containing objects formatted as
|
8
|
+
# { git: Octokit::Client, colors: JSON }
|
9
|
+
def self.configure_stuff(opts = {})
|
10
|
+
token = opts[:token]
|
11
|
+
pass = opts[:pass]
|
12
|
+
user = opts[:user]
|
13
|
+
gh = Octokit::Client.new(login: user, password: pass) if token.nil?
|
14
|
+
gh = Octokit::Client.new(access_token: token) unless token.nil?
|
15
|
+
encoded = gh.contents('ozh/github-colors', path: 'colors.json')[:content]
|
16
|
+
colors = JSON.parse(Base64.decode64(encoded))
|
17
|
+
{ git: gh, colors: colors }
|
18
|
+
end
|
19
|
+
|
20
|
+
# Gets the next value in an array.
|
21
|
+
# @param single [Any] The current value.
|
22
|
+
# @param full [Array] The main array to parse.
|
23
|
+
# @return [Any] The next value in the array.
|
24
|
+
def self.get_next(single, full)
|
25
|
+
full.at(full.index(single) + 1)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.user_exists?(username, github)
|
29
|
+
begin
|
30
|
+
github.user(username).is_a?(Octokit::NotFound)
|
31
|
+
rescue Octokit::NotFound
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
# Gets the langauges and their bytes for the :user.
|
38
|
+
# @param username [String] The username to get info for.
|
39
|
+
# @param github [OctoKit::Client] The instance of Octokit::Client.
|
40
|
+
# @return [Hash] The languages and their bytes, as formatted as
|
41
|
+
# { :Ruby => 129890, :CoffeeScript => 5970 }
|
42
|
+
def self.get_langs(username, github)
|
43
|
+
repos = github.repositories(username)
|
44
|
+
langs = {}
|
45
|
+
repos.each do |r|
|
46
|
+
next if r[:fork]
|
47
|
+
repo_langs = github.languages(r[:full_name])
|
48
|
+
repo_langs.each do |l, b|
|
49
|
+
if langs[l].nil?
|
50
|
+
langs[l] = b
|
51
|
+
else
|
52
|
+
existing = langs[l]
|
53
|
+
langs[l] = existing + b
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
langs
|
58
|
+
end
|
59
|
+
|
60
|
+
# Gets the percentage for the given numbers.
|
61
|
+
# @param part [Fixnum] The partial value.
|
62
|
+
# @param whole [Fixnum] The whole value.
|
63
|
+
# @return [Fixnum] The percentage that part is of whole.
|
64
|
+
def self.calculate_percent(part, whole)
|
65
|
+
(part / whole) * 100
|
66
|
+
end
|
67
|
+
|
68
|
+
# Gets the defined color for the language.
|
69
|
+
# @param lang [String] The language name.
|
70
|
+
# @param colors [Hash] The hash of colors and languages.
|
71
|
+
# @return [String] The 6 digit hexidecimal color.
|
72
|
+
# @return [Nil] If there is no defined color for the language.
|
73
|
+
def self.get_color_for_language(lang, colors)
|
74
|
+
return colors[lang]['color'] unless colors[lang]['color'].nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.analyze(username, github)
|
78
|
+
if user_exists?(username, github)
|
79
|
+
languages = get_langs(username, github)
|
80
|
+
total = 0
|
81
|
+
languages.each { |_, b| total += b }
|
82
|
+
language_percentages = {}
|
83
|
+
languages.each do |l, b|
|
84
|
+
percent = Utilities.calculate_percent(b, total.to_f)
|
85
|
+
language_percentages[l] = percent.round(2)
|
86
|
+
end
|
87
|
+
language_percentages
|
88
|
+
else
|
89
|
+
false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghuls
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eli Foster
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: octokit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rainbow
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: string-utility
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Getting GitHub repository language data by user! It also has a web alternative
|
56
|
+
at http://ghuls.herokuapp.com
|
57
|
+
email: elifosterwy@gmail.com
|
58
|
+
executables:
|
59
|
+
- ghuls
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- bin/ghuls
|
64
|
+
- cli/lib/ghuls.rb
|
65
|
+
- cli/lib/ghuls/cli.rb
|
66
|
+
- utils/utilities.rb
|
67
|
+
homepage: http://ghuls.herokuapp.com
|
68
|
+
licenses: []
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2.0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.4.5.1
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: 'GHULS: GitHub User Language Statistics'
|
90
|
+
test_files: []
|