github-info 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 124fffa9bc672725f7995619fb8580aeb1b80b7889c841d98ae4f18130c967dd
4
+ data.tar.gz: e78bd7ac08a59812a0213a03c5df361dc14f82a9dbd6578d6a581140ca4d6713
5
+ SHA512:
6
+ metadata.gz: af3dff3b1e9d3d94a1298a04ed2359eb1881c0d83d52d24d848b14823b5a5119c16d5d7257ae10cd9956a37b64096c117208abdd619957339a9e892e4116757d
7
+ data.tar.gz: 0dac35484b556983d2996dd9d12cd3b668d3475834d442dfc2a5177b374c6f14ac476faf966382c64679ed264dbe0e7a0a670334adf571035f84ca3cf5b0ce05
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ source "https://rubygems.org"
data/Gemfile.lock ADDED
@@ -0,0 +1,11 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+
5
+ PLATFORMS
6
+ ruby
7
+
8
+ DEPENDENCIES
9
+
10
+ BUNDLED WITH
11
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 'Brandon Weaver'
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Github::Info
2
+
3
+ This gem provides commands which are used to retrieve and output information from a github profile.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'github-info'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install github-info
20
+
21
+ ## Usage
22
+
23
+ This CLI gem provides the following commands:
24
+ help
25
+ git: [profile]
26
+ name
27
+ contributions
28
+ repos
29
+ history: [repository_index]
30
+
31
+ A [profile] is the username of a github profile.
32
+ e.g. BrandonMWeaver
33
+
34
+ A [repository_index] is identified by the number to the left-hand side of a repository as listed by the output of repos.
35
+ e.g. 1
36
+
37
+ help -> Provides a list of available commands and their usage.
38
+ git: [profile] -> Retrieves information from a github profile.
39
+ name -> Outputs the name of the user if one is provided.
40
+ contributions -> Outputs the contributions commited by the user within the last year.
41
+ repos -> Outputs an indexed list of the user's repositories.
42
+ history: [repository_index] -> Outputs a list of a repository's commit history
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/BrandonMWeaver/github-info.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "github-info"
5
+
6
+ require "irb"
7
+ IRB.start(__FILE__)
data/bin/github-info ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/github-info"
4
+
5
+ GithubInfo::CLI.new.call
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "github-info/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "github-info"
7
+ spec.version = GithubInfo::VERSION
8
+ spec.authors = ["'Brandon Weaver'"]
9
+ spec.email = ["'a7xncob@gmail.com'"]
10
+
11
+ spec.summary = "This gem provides commands which are used to retrieve and output information from a github profile."
12
+ spec.homepage = "https://github.com/BrandonMWeaver/github-info"
13
+ spec.license = "MIT"
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
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 2.0"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,4 @@
1
+ require_relative "github-info/version"
2
+ require_relative "github-info/cli"
3
+ require_relative "github-info/github"
4
+ require_relative "github-info/scraper"
@@ -0,0 +1,60 @@
1
+ class GithubInfo::CLI
2
+ def call
3
+ menu
4
+ end
5
+
6
+ private
7
+
8
+ def menu
9
+ commands = ["name", "contributions", "repos", "history"]
10
+ github_name = ""
11
+
12
+ loop do
13
+ puts "command:"
14
+ input = gets.strip
15
+
16
+ if input.split(':')[0].downcase == "git"
17
+ begin
18
+ github_name = input.split(':')[1].split(' ')[0]
19
+ @github = GithubInfo::Github.new(github_name)
20
+ puts "github acquired"
21
+ rescue OpenURI::HTTPError
22
+ puts "github not found"
23
+ rescue NoMethodError
24
+ puts "github not provided"
25
+ end
26
+
27
+ elsif input.downcase == "help"
28
+ GithubInfo::Github.print_help
29
+
30
+ elsif input.downcase == "name" && @github
31
+ @github.print_name
32
+
33
+ elsif input.downcase == "contributions" && @github
34
+ @github.print_contributions
35
+
36
+ elsif input.downcase == "repos" && @github
37
+ @github.print_repos
38
+
39
+ elsif input.split(':')[0].downcase == "history" && @github
40
+ begin
41
+ index = input.split(':')[1].split(' ')[0].to_i - 1
42
+ @github.print_commit_history(index)
43
+ rescue OpenURI::HTTPError
44
+ puts "repository not found"
45
+ rescue NoMethodError
46
+ puts "repository not found"
47
+ end
48
+
49
+ elsif input.downcase == "exit"
50
+ break
51
+
52
+ elsif commands.include?(input.split(':')[0].downcase)
53
+ puts "command currently unavailable"
54
+
55
+ else
56
+ puts "unknown command"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,68 @@
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
+
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
21
+
22
+ def print_name
23
+ if @name != ""
24
+ puts @name
25
+ else
26
+ puts "name unavailable"
27
+ end
28
+ end
29
+
30
+ def print_contributions
31
+ puts "#{@contributions} contributions in the last year"
32
+ end
33
+
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"
45
+ end
46
+ end
47
+
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
+ }
57
+ end
58
+
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
67
+ end
68
+ end
@@ -0,0 +1,49 @@
1
+ require "nokogiri"
2
+ require "open-uri"
3
+
4
+ class GithubInfo::Scraper
5
+ attr_reader :github_info
6
+
7
+ def initialize(github_name)
8
+ @github_name = github_name
9
+ @github_info = {
10
+ user_info: get_user_info,
11
+ repositories: get_repositories
12
+ }
13
+ end
14
+
15
+ def self.get_commit_history(relative_path)
16
+ commit_history = []
17
+ document = Nokogiri::HTML(open("https://github.com#{relative_path}/commits/master"))
18
+ document.css("div.table-list-cell").each { |commit|
19
+ if commit.css("p a.message.js-navigation-open").text != ""
20
+ commit_hash = {
21
+ description: commit.css("p a.message.js-navigation-open").text,
22
+ date: commit.css("relative-time.no-wrap").text
23
+ }
24
+ commit_history << commit_hash
25
+ end
26
+ }
27
+ return commit_history
28
+ end
29
+
30
+ private
31
+
32
+ def get_user_info
33
+ user_info = {}
34
+ document = Nokogiri::HTML(open("https://github.com/#{@github_name}"))
35
+ user_info[:name] = document.css("span.p-name.vcard-fullname.d-block.overflow-hidden").text
36
+ user_info[:contributions] = document.css("h2.f4.text-normal.mb-2")[1].text.split(' ')[0]
37
+ return user_info
38
+ end
39
+
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
+ }
47
+ return repositories
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module GithubInfo
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-info
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Brandon Weaver'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - "'a7xncob@gmail.com'"
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/github-info
56
+ - bin/setup
57
+ - github-info.gemspec
58
+ - lib/github-info.rb
59
+ - lib/github-info/cli.rb
60
+ - lib/github-info/github.rb
61
+ - lib/github-info/scraper.rb
62
+ - lib/github-info/version.rb
63
+ homepage: https://github.com/BrandonMWeaver/github-info
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.0.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: This gem provides commands which are used to retrieve and output information
86
+ from a github profile.
87
+ test_files: []