github-info 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/github-info-0.1.0.gem +0 -0
- data/github-info.gemspec +0 -2
- data/lib/github-info.rb +2 -0
- data/lib/github-info/cli.rb +71 -12
- data/lib/github-info/github.rb +20 -55
- data/lib/github-info/scraper.rb +17 -17
- data/lib/github-info/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce99877910d4f4d08043e5771b3757008aa98a79593abcf132d946525af3274a
|
4
|
+
data.tar.gz: 40fa21b09cde2b1dce9f4d1aed061b044cb3ed4c561c48f977e2eb9850944b4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00633cef3405c83a122229cb8993cec6fcf0a4949b130d2915ded76a183a5ab67532e85dbf9065bc8616fb91a481b4e5d84d45a12d2eaf21e3a897b710f994e1
|
7
|
+
data.tar.gz: 5bef8a2901191d8ae24fbdf53f20e536401b4156a14b777e0a00e7ef0350c559a52dc1cf9ad210bf084c9fcd68f0f81f99bf80b24b439a2d480e0085685a14bb
|
Binary file
|
data/github-info.gemspec
CHANGED
@@ -12,8 +12,6 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = "https://github.com/BrandonMWeaver/github-info"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
|
-
# Specify which files should be added to the gem when it is released.
|
16
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
15
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
16
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
17
|
end
|
data/lib/github-info.rb
CHANGED
data/lib/github-info/cli.rb
CHANGED
@@ -5,9 +5,68 @@ class GithubInfo::CLI
|
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
|
+
def print_help
|
9
|
+
print "\tgit: [profile] -> "
|
10
|
+
puts "Retrieves information from a github profile."
|
11
|
+
print "\tname -> "
|
12
|
+
puts "Outputs the name of the user if one is provided."
|
13
|
+
print "\tcontributions -> "
|
14
|
+
puts "Outputs the contributions commited by the user within the last year."
|
15
|
+
print "\trepos -> "
|
16
|
+
puts "Outputs an indexed list of the user's repositories."
|
17
|
+
print "\thistory: [repository_index] -> "
|
18
|
+
puts "Outputs a list of a repository's commit history."
|
19
|
+
print "\texit -> "
|
20
|
+
puts "Exit the program."
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_name
|
24
|
+
if @github_profile.name != ""
|
25
|
+
puts @github_profile.name
|
26
|
+
else
|
27
|
+
puts "name unavailable"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def print_contributions
|
32
|
+
puts "#{@github_profile.contributions} contributions in the last year"
|
33
|
+
end
|
34
|
+
|
35
|
+
def print_repositories
|
36
|
+
if @github_profile.repositories.size != 0
|
37
|
+
puts "repositories:"
|
38
|
+
i = 0
|
39
|
+
@github_profile.repositories.each do |repository|
|
40
|
+
print "\t"
|
41
|
+
print '0' if i < 9
|
42
|
+
puts "#{i += 1}. #{repository[:name]}"
|
43
|
+
end
|
44
|
+
else
|
45
|
+
puts "no repositories"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def print_commit_history(index)
|
50
|
+
puts "commit history:"
|
51
|
+
@github_profile.commit_history(index).each { |commit|
|
52
|
+
print "\t"
|
53
|
+
print "#{format_date(commit[:date])}: "
|
54
|
+
puts commit[:description]
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def format_date(date)
|
59
|
+
if date.split(' ')[1].split(',')[0].to_i < 10
|
60
|
+
date_pieces = date.split(' ')
|
61
|
+
date = "#{date_pieces[0]} 0#{date_pieces[1]} #{date_pieces[2]}"
|
62
|
+
end
|
63
|
+
return date
|
64
|
+
end
|
65
|
+
|
8
66
|
def menu
|
9
67
|
commands = ["name", "contributions", "repos", "history"]
|
10
|
-
|
68
|
+
|
69
|
+
puts "enter 'help' for a list of commands"
|
11
70
|
|
12
71
|
loop do
|
13
72
|
puts "command:"
|
@@ -15,8 +74,8 @@ class GithubInfo::CLI
|
|
15
74
|
|
16
75
|
if input.split(':')[0].downcase == "git"
|
17
76
|
begin
|
18
|
-
|
19
|
-
@
|
77
|
+
profile_name = input.split(':')[1].split(' ')[0]
|
78
|
+
@github_profile = GithubInfo::Github.find_or_create_by_user_name(profile_name)
|
20
79
|
puts "github acquired"
|
21
80
|
rescue OpenURI::HTTPError
|
22
81
|
puts "github not found"
|
@@ -25,21 +84,21 @@ class GithubInfo::CLI
|
|
25
84
|
end
|
26
85
|
|
27
86
|
elsif input.downcase == "help"
|
28
|
-
|
87
|
+
print_help
|
29
88
|
|
30
|
-
elsif input.downcase == "name" && @
|
31
|
-
|
89
|
+
elsif input.downcase == "name" && @github_profile
|
90
|
+
print_name
|
32
91
|
|
33
|
-
elsif input.downcase == "contributions" && @
|
34
|
-
|
92
|
+
elsif input.downcase == "contributions" && @github_profile
|
93
|
+
print_contributions
|
35
94
|
|
36
|
-
elsif input.downcase == "repos" && @
|
37
|
-
|
95
|
+
elsif input.downcase == "repos" && @github_profile
|
96
|
+
print_repositories
|
38
97
|
|
39
|
-
elsif input.split(':')[0].downcase == "history" && @
|
98
|
+
elsif input.split(':')[0].downcase == "history" && @github_profile
|
40
99
|
begin
|
41
100
|
index = input.split(':')[1].split(' ')[0].to_i - 1
|
42
|
-
|
101
|
+
print_commit_history(index)
|
43
102
|
rescue OpenURI::HTTPError
|
44
103
|
puts "repository not found"
|
45
104
|
rescue NoMethodError
|
data/lib/github-info/github.rb
CHANGED
@@ -1,68 +1,33 @@
|
|
1
1
|
class GithubInfo::Github
|
2
|
-
def initialize(github_name)
|
3
|
-
scraper = GithubInfo::Scraper.new(github_name)
|
4
|
-
@name = scraper.github_info[:user_info][:name]
|
5
|
-
@contributions = scraper.github_info[:user_info][:contributions]
|
6
|
-
@repositories = scraper.github_info[:repositories]
|
7
|
-
end
|
8
2
|
|
9
|
-
|
10
|
-
puts "\tgit: [profile]"
|
11
|
-
puts "\t Retrieves information from a github profile.\n\n"
|
12
|
-
puts "\tname"
|
13
|
-
puts "\t Outputs the name of the user if one is provided.\n\n"
|
14
|
-
puts "\tcontributions"
|
15
|
-
puts "\t Outputs the contributions commited by the user within the last year.\n\n"
|
16
|
-
puts "\trepos"
|
17
|
-
puts "\t Outputs an indexed list of the user's repositories.\n\n"
|
18
|
-
puts "\thistory: [repository_index]"
|
19
|
-
puts "\t Outputs a list of a repository's commit history.\n\n"
|
20
|
-
end
|
3
|
+
attr_reader :user_name, :name, :contributions, :repositories
|
21
4
|
|
22
|
-
|
23
|
-
if @name != ""
|
24
|
-
puts @name
|
25
|
-
else
|
26
|
-
puts "name unavailable"
|
27
|
-
end
|
28
|
-
end
|
5
|
+
@@all = []
|
29
6
|
|
30
|
-
def
|
31
|
-
|
7
|
+
def initialize(user_name)
|
8
|
+
@user_name = user_name
|
9
|
+
github_info = GithubInfo::Scraper.scrape(@user_name)
|
10
|
+
@name = github_info[:user_info][:name]
|
11
|
+
@contributions = github_info[:user_info][:contributions]
|
12
|
+
@repositories = github_info[:repositories]
|
13
|
+
@@all << self
|
32
14
|
end
|
33
15
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
print "\t"
|
40
|
-
print '0' if i < 9
|
41
|
-
puts "#{i += 1}. #{repository[:name]}"
|
42
|
-
}
|
43
|
-
else
|
44
|
-
puts "no repositories"
|
16
|
+
def self.find_or_create_by_user_name(user_name)
|
17
|
+
@@all.each do |profile|
|
18
|
+
if user_name == profile.user_name
|
19
|
+
return profile
|
20
|
+
end
|
45
21
|
end
|
22
|
+
return self.new(user_name)
|
46
23
|
end
|
47
24
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
puts "commit history:"
|
52
|
-
commit_history.each { |commit|
|
53
|
-
print "\t"
|
54
|
-
print "#{format_date(commit[:date])}: "
|
55
|
-
puts commit[:description]
|
56
|
-
}
|
25
|
+
def self.all
|
26
|
+
return @@all
|
57
27
|
end
|
58
28
|
|
59
|
-
|
60
|
-
|
61
|
-
def format_date(date)
|
62
|
-
if date.split(' ')[1].split(',')[0].to_i < 10
|
63
|
-
date_pieces = date.split(' ')
|
64
|
-
date = "#{date_pieces[0]} 0#{date_pieces[1]} #{date_pieces[2]}"
|
65
|
-
end
|
66
|
-
return date
|
29
|
+
def commit_history(index)
|
30
|
+
return GithubInfo::Scraper.get_commit_history(@repositories[index][:href])
|
67
31
|
end
|
32
|
+
|
68
33
|
end
|
data/lib/github-info/scraper.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
require "nokogiri"
|
2
|
-
require "open-uri"
|
3
|
-
|
4
1
|
class GithubInfo::Scraper
|
5
|
-
attr_reader :github_info
|
6
2
|
|
7
|
-
def
|
8
|
-
@github_name = github_name
|
3
|
+
def self.scrape(profile_name)
|
9
4
|
@github_info = {
|
10
|
-
user_info: get_user_info,
|
11
|
-
repositories: get_repositories
|
5
|
+
user_info: get_user_info(profile_name),
|
6
|
+
repositories: get_repositories(profile_name)
|
12
7
|
}
|
8
|
+
return @github_info
|
13
9
|
end
|
14
10
|
|
15
11
|
def self.get_commit_history(relative_path)
|
@@ -29,21 +25,25 @@ class GithubInfo::Scraper
|
|
29
25
|
|
30
26
|
private
|
31
27
|
|
32
|
-
def get_user_info
|
28
|
+
def self.get_user_info(profile_name)
|
33
29
|
user_info = {}
|
34
|
-
document = Nokogiri::HTML(open("https://github.com/#{
|
30
|
+
document = Nokogiri::HTML(open("https://github.com/#{profile_name}"))
|
35
31
|
user_info[:name] = document.css("span.p-name.vcard-fullname.d-block.overflow-hidden").text
|
36
32
|
user_info[:contributions] = document.css("h2.f4.text-normal.mb-2")[1].text.split(' ')[0]
|
37
33
|
return user_info
|
38
34
|
end
|
39
35
|
|
40
|
-
def get_repositories
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
def self.get_repositories(profile_name)
|
37
|
+
repositories = []
|
38
|
+
document = Nokogiri::HTML(open("https://github.com/#{profile_name}?tab=repositories"))
|
39
|
+
document.css("div.d-inline-block.mb-1 h3 a").each do |repository|
|
40
|
+
repository_hash = {
|
41
|
+
name: repository.text.split(' ')[0],
|
42
|
+
href: repository.attr("href")
|
43
|
+
}
|
44
|
+
repositories << repository_hash
|
45
|
+
end
|
47
46
|
return repositories
|
48
47
|
end
|
48
|
+
|
49
49
|
end
|
data/lib/github-info/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "'Brandon Weaver'"
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- bin/console
|
55
55
|
- bin/github-info
|
56
56
|
- bin/setup
|
57
|
+
- github-info-0.1.0.gem
|
57
58
|
- github-info.gemspec
|
58
59
|
- lib/github-info.rb
|
59
60
|
- lib/github-info/cli.rb
|