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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 124fffa9bc672725f7995619fb8580aeb1b80b7889c841d98ae4f18130c967dd
4
- data.tar.gz: e78bd7ac08a59812a0213a03c5df361dc14f82a9dbd6578d6a581140ca4d6713
3
+ metadata.gz: ce99877910d4f4d08043e5771b3757008aa98a79593abcf132d946525af3274a
4
+ data.tar.gz: 40fa21b09cde2b1dce9f4d1aed061b044cb3ed4c561c48f977e2eb9850944b4e
5
5
  SHA512:
6
- metadata.gz: af3dff3b1e9d3d94a1298a04ed2359eb1881c0d83d52d24d848b14823b5a5119c16d5d7257ae10cd9956a37b64096c117208abdd619957339a9e892e4116757d
7
- data.tar.gz: 0dac35484b556983d2996dd9d12cd3b668d3475834d442dfc2a5177b374c6f14ac476faf966382c64679ed264dbe0e7a0a670334adf571035f84ca3cf5b0ce05
6
+ metadata.gz: 00633cef3405c83a122229cb8993cec6fcf0a4949b130d2915ded76a183a5ab67532e85dbf9065bc8616fb91a481b4e5d84d45a12d2eaf21e3a897b710f994e1
7
+ data.tar.gz: 5bef8a2901191d8ae24fbdf53f20e536401b4156a14b777e0a00e7ef0350c559a52dc1cf9ad210bf084c9fcd68f0f81f99bf80b24b439a2d480e0085685a14bb
Binary file
@@ -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
@@ -1,3 +1,5 @@
1
+ require "nokogiri"
2
+ require "open-uri"
1
3
  require_relative "github-info/version"
2
4
  require_relative "github-info/cli"
3
5
  require_relative "github-info/github"
@@ -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
- github_name = ""
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
- github_name = input.split(':')[1].split(' ')[0]
19
- @github = GithubInfo::Github.new(github_name)
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
- GithubInfo::Github.print_help
87
+ print_help
29
88
 
30
- elsif input.downcase == "name" && @github
31
- @github.print_name
89
+ elsif input.downcase == "name" && @github_profile
90
+ print_name
32
91
 
33
- elsif input.downcase == "contributions" && @github
34
- @github.print_contributions
92
+ elsif input.downcase == "contributions" && @github_profile
93
+ print_contributions
35
94
 
36
- elsif input.downcase == "repos" && @github
37
- @github.print_repos
95
+ elsif input.downcase == "repos" && @github_profile
96
+ print_repositories
38
97
 
39
- elsif input.split(':')[0].downcase == "history" && @github
98
+ elsif input.split(':')[0].downcase == "history" && @github_profile
40
99
  begin
41
100
  index = input.split(':')[1].split(' ')[0].to_i - 1
42
- @github.print_commit_history(index)
101
+ print_commit_history(index)
43
102
  rescue OpenURI::HTTPError
44
103
  puts "repository not found"
45
104
  rescue NoMethodError
@@ -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
- def self.print_help
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
- def print_name
23
- if @name != ""
24
- puts @name
25
- else
26
- puts "name unavailable"
27
- end
28
- end
5
+ @@all = []
29
6
 
30
- def print_contributions
31
- puts "#{@contributions} contributions in the last year"
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 print_repos
35
- if @repositories.size != 0
36
- i = 0
37
- puts "repositories:"
38
- @repositories.each { |repository|
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 print_commit_history(index)
49
- commit_history = GithubInfo::Scraper.get_commit_history(@repositories[index][:href])
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
- private
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
@@ -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 initialize(github_name)
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/#{@github_name}"))
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
- document = Nokogiri::HTML(open("https://github.com/#{@github_name}?tab=repositories"))
42
- repositories = document.css("div.d-inline-block.mb-1 h3 a")
43
- repositories.each { |repository|
44
- repository[:name] = repository.text.split(' ')[0]
45
- repository[:href] = repository.attr("href")
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
@@ -1,3 +1,3 @@
1
1
  module GithubInfo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-06 00:00:00.000000000 Z
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