gh_contrib 0.0.1
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/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +1 -0
- data/Rakefile +2 -0
- data/bin/gh_contrib +39 -0
- data/gh_contrib.gemspec +28 -0
- data/lib/gh_contrib.rb +5 -0
- data/lib/gh_contrib/agent.rb +38 -0
- data/lib/gh_contrib/version.rb +3 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae090cc95a0b2f79c232e8f54e419dfa3ae0ae73
|
4
|
+
data.tar.gz: 35919919f0b58ab5b5a411fc1edc354779d360bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ebe8e4812c3f681c8ed5ec3dcba6bf052e9001c2a8f7d5fb4aea1821944ea4ba59da86a60d221627d9eee8c7089eb54448c1affeaa8bf3aad3bdfce3424f223
|
7
|
+
data.tar.gz: a5b0f293c6357a9377285baf886b79122fc6752cdc47f7ff98f59507b4bea6aba75435619f68871bc3cc79d2c1fe726362afaaf4fb9561cdeb01670a44fb0d91
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.env
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kohei Hasegawa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# gh_contrib
|
data/Rakefile
ADDED
data/bin/gh_contrib
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'dotenv'
|
4
|
+
Dotenv.load
|
5
|
+
|
6
|
+
require 'commander'
|
7
|
+
require 'gh_contrib'
|
8
|
+
|
9
|
+
Commander.configure do
|
10
|
+
program :version, GhContrib::VERSION
|
11
|
+
program :description, 'Show contributions of GitHub'
|
12
|
+
|
13
|
+
default_command :contributions
|
14
|
+
|
15
|
+
command :contributions do |c|
|
16
|
+
c.syntax = 'gh_contrib <username>'
|
17
|
+
c.description = 'Show contributions of a user'
|
18
|
+
|
19
|
+
c.option '-d <day|month>', String, 'Group by date'
|
20
|
+
|
21
|
+
c.action do |args, options|
|
22
|
+
options.default d: 'day'
|
23
|
+
|
24
|
+
username = args.shift || abort(c.syntax)
|
25
|
+
agent = GhContrib::Agent.new
|
26
|
+
if ENV['GITHUB_USERNAME'] && ENV['GITHUB_PASSWORD']
|
27
|
+
agent.login(ENV['GITHUB_USERNAME'], ENV['GITHUB_PASSWORD'])
|
28
|
+
end
|
29
|
+
|
30
|
+
if options.d == 'day'
|
31
|
+
puts agent.contributions(username).to_json
|
32
|
+
elsif options.d == 'month'
|
33
|
+
puts agent.contributions_by_month(username).to_json
|
34
|
+
else
|
35
|
+
raise(ArgumentError, "-d option should be passed as 'day' or 'month': #{options.d}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/gh_contrib.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gh_contrib/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gh_contrib"
|
8
|
+
spec.version = GhContrib::VERSION
|
9
|
+
spec.authors = ["Kohei Hasegawa"]
|
10
|
+
spec.email = ["ameutau@gmail.com"]
|
11
|
+
spec.summary = %q{Show contributions of GitHub.}
|
12
|
+
spec.description = %q{Show contributions of GitHub.}
|
13
|
+
spec.homepage = "https://github.com/banyan/gh_contrib"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "commander"
|
22
|
+
spec.add_runtime_dependency "nokogiri"
|
23
|
+
spec.add_runtime_dependency "mechanize"
|
24
|
+
spec.add_runtime_dependency "dotenv"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
end
|
data/lib/gh_contrib.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'mechanize'
|
3
|
+
|
4
|
+
module GhContrib
|
5
|
+
class Agent
|
6
|
+
GITHUB_URL = 'https://github.com'
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@agent = Mechanize.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def login(username, password)
|
13
|
+
page = @agent.get "#{GITHUB_URL}/login"
|
14
|
+
form = page.forms[1]
|
15
|
+
form.field_with(name: 'login').value = username
|
16
|
+
form.field_with(name: 'password').value = password
|
17
|
+
@agent.submit(form)
|
18
|
+
end
|
19
|
+
|
20
|
+
def contributions(username)
|
21
|
+
page = @agent.get "#{GITHUB_URL}/users/#{username}/contributions"
|
22
|
+
doc = Nokogiri::HTML(page.body)
|
23
|
+
doc.xpath('//rect').map {|element|
|
24
|
+
{ date: element["data-date"], count: element["data-count"].to_i }
|
25
|
+
}.reverse
|
26
|
+
end
|
27
|
+
|
28
|
+
def contributions_by_month(username)
|
29
|
+
contributions(username).each_with_object({}) {|row, h|
|
30
|
+
key = row[:date][0, 7] # "2014-10-01" => "2014-10"
|
31
|
+
h[key] ||= 0
|
32
|
+
h[key] += row[:count].to_i
|
33
|
+
}.map {|element|
|
34
|
+
{ date: element[0], count: element[1].to_i }
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gh_contrib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kohei Hasegawa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
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: nokogiri
|
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: mechanize
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
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: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Show contributions of GitHub.
|
98
|
+
email:
|
99
|
+
- ameutau@gmail.com
|
100
|
+
executables:
|
101
|
+
- gh_contrib
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/gh_contrib
|
111
|
+
- gh_contrib.gemspec
|
112
|
+
- lib/gh_contrib.rb
|
113
|
+
- lib/gh_contrib/agent.rb
|
114
|
+
- lib/gh_contrib/version.rb
|
115
|
+
homepage: https://github.com/banyan/gh_contrib
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.2.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Show contributions of GitHub.
|
139
|
+
test_files: []
|
140
|
+
has_rdoc:
|