hubba 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +2 -0
- data/lib/hubba.rb +2 -0
- data/lib/hubba/github.rb +10 -0
- data/lib/hubba/stats.rb +113 -0
- data/lib/hubba/version.rb +2 -2
- data/test/test_stats.rb +40 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 483d4813ac93c23eaf300404342fb8883712449a
|
4
|
+
data.tar.gz: 897633ce5908ead11844d5421dd495e087440747
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e33ee3954c0a131e05cd3ca92c0359be2b27cafa59541ad2e76a6338ef64b35e618b74c5b335177f77ffddf85604f6be4fc72d314ab39293e66e901eedd8ab81
|
7
|
+
data.tar.gz: d4a32cd4fd90fb3d7da117f7a25b04cfb13dc5a0049134255edcbc53753604af4a5916ba7223ef86454c1b8331a03f7b2b4f753907ea3ea6ddcd41379c796d93
|
data/Manifest.txt
CHANGED
@@ -6,9 +6,11 @@ lib/hubba.rb
|
|
6
6
|
lib/hubba/cache.rb
|
7
7
|
lib/hubba/client.rb
|
8
8
|
lib/hubba/github.rb
|
9
|
+
lib/hubba/stats.rb
|
9
10
|
lib/hubba/version.rb
|
10
11
|
test/cache/users~geraldb~orgs.json
|
11
12
|
test/cache/users~geraldb~repos.json
|
12
13
|
test/helper.rb
|
13
14
|
test/test_cache.rb
|
14
15
|
test/test_config.rb
|
16
|
+
test/test_stats.rb
|
data/lib/hubba.rb
CHANGED
@@ -7,6 +7,7 @@ require 'uri'
|
|
7
7
|
require 'pp'
|
8
8
|
require 'json'
|
9
9
|
require 'yaml'
|
10
|
+
require 'time'
|
10
11
|
|
11
12
|
|
12
13
|
# 3rd party gems/libs
|
@@ -17,6 +18,7 @@ require 'hubba/version' # note: let version always go first
|
|
17
18
|
require 'hubba/cache'
|
18
19
|
require 'hubba/client'
|
19
20
|
require 'hubba/github'
|
21
|
+
require 'hubba/stats'
|
20
22
|
|
21
23
|
|
22
24
|
# say hello
|
data/lib/hubba/github.rb
CHANGED
@@ -104,6 +104,16 @@ def org_repos( name )
|
|
104
104
|
end
|
105
105
|
|
106
106
|
|
107
|
+
|
108
|
+
def repo( full_name ) ## full_name (handle) e.g. henrythemes/jekyll-starter-theme
|
109
|
+
Resource.new( get "/repos/#{full_name}" )
|
110
|
+
end
|
111
|
+
|
112
|
+
def repo_commits( full_name )
|
113
|
+
Resource.new( get "/repos/#{full_name}/commits" )
|
114
|
+
end
|
115
|
+
|
116
|
+
|
107
117
|
private
|
108
118
|
def get( request_uri )
|
109
119
|
if offline?
|
data/lib/hubba/stats.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Hubba
|
4
|
+
|
5
|
+
####
|
6
|
+
# keep track of repo stats over time (with history hash)
|
7
|
+
|
8
|
+
class Stats ## todo/check: rename to GithubRepoStats or RepoStats - why? why not?
|
9
|
+
|
10
|
+
attr_reader :data
|
11
|
+
|
12
|
+
def initialize( full_name )
|
13
|
+
@data = {}
|
14
|
+
@data['full_name'] = full_name # e.g. poole/hyde etc.
|
15
|
+
end
|
16
|
+
|
17
|
+
def full_name() @data['full_name']; end
|
18
|
+
|
19
|
+
|
20
|
+
def size
|
21
|
+
# size of repo in kb (as reported by github api)
|
22
|
+
@data['size'] || 0 ## return 0 if not found - why? why not? (return nil - why? why not??)
|
23
|
+
end
|
24
|
+
|
25
|
+
def stars
|
26
|
+
## return last stargazers_count entry (as number; 0 if not found)
|
27
|
+
t1 = 0
|
28
|
+
|
29
|
+
history = @data['history']
|
30
|
+
if history
|
31
|
+
history_keys = @data['history'].keys.sort.reverse
|
32
|
+
## todo/fix: for now assumes one entry per week
|
33
|
+
## simple case [0] and [1] for a week later
|
34
|
+
## check actual date - why? why not?
|
35
|
+
stats_t1 = history_keys[0] ? history[ history_keys[0] ] : nil
|
36
|
+
if stats_t1
|
37
|
+
t1 = stats_t1['stargazers_count'] || 0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
t1
|
41
|
+
end # method stars
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
###############################
|
46
|
+
## fetch / read / write methods
|
47
|
+
|
48
|
+
def fetch( gh ) ## update stats / fetch data from github via api
|
49
|
+
puts "fetching #{full_name}..."
|
50
|
+
repo = gh.repo( full_name )
|
51
|
+
|
52
|
+
## e.g. 2015-05-11T20:21:43Z
|
53
|
+
## puts Time.iso8601( repo.data['created_at'] )
|
54
|
+
@data['created_at'] = repo.data['created_at']
|
55
|
+
@data['size'] = repo.data['size'] # size in kb (kilobyte)
|
56
|
+
|
57
|
+
rec = {}
|
58
|
+
|
59
|
+
puts "stargazers_count"
|
60
|
+
puts repo.data['stargazers_count']
|
61
|
+
rec['stargazers_count'] = repo.data['stargazers_count']
|
62
|
+
|
63
|
+
today = Date.today.strftime( '%Y-%m-%d' ) ## e.g. 2016-09-27
|
64
|
+
puts "add record #{today} to history..."
|
65
|
+
pp rec # check if stargazers_count is a number (NOT a string)
|
66
|
+
|
67
|
+
@data[ 'history' ] ||= {}
|
68
|
+
@data[ 'history' ][ today ] = rec
|
69
|
+
|
70
|
+
##########################
|
71
|
+
## also check / keep track of (latest) commit
|
72
|
+
commits = gh.repo_commits( full_name )
|
73
|
+
puts "last commit/update:"
|
74
|
+
## pp commits
|
75
|
+
commit = {
|
76
|
+
'committer' => {
|
77
|
+
'date' => commits.data[0]['commit']['committer']['date'],
|
78
|
+
'name' => commits.data[0]['commit']['committer']['name']
|
79
|
+
},
|
80
|
+
'message' => commits.data[0]['commit']['message']
|
81
|
+
}
|
82
|
+
|
83
|
+
## for now store only the latest commit (e.g. a single commit in an array)
|
84
|
+
@data[ 'commits'] = [commit]
|
85
|
+
|
86
|
+
pp @data
|
87
|
+
end
|
88
|
+
|
89
|
+
def write( data_dir: './data' )
|
90
|
+
basename = full_name.gsub( '/', '~' ) ## e.g. poole/hyde become poole~hyde
|
91
|
+
puts "writing (saving) to #{basename}..."
|
92
|
+
File.open( "#{data_dir}/#{basename}.json", 'w:utf-8' ) do |f|
|
93
|
+
f.write JSON.pretty_generate( data )
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def read( data_dir: './data' ) ## note: use read instead of load (load is kind of keyword for loading code)
|
98
|
+
## note: skip reading if file not present
|
99
|
+
basename = full_name.gsub( '/', '~' ) ## e.g. poole/hyde become poole~hyde
|
100
|
+
filename = "#{data_dir}/#{basename}.json"
|
101
|
+
if File.exist?( filename )
|
102
|
+
puts "reading (loading) from #{basename}..."
|
103
|
+
json = File.open( filename, 'r:utf-8' ) { |file| file.read } ## todo/fix: use read_utf8
|
104
|
+
@data = JSON.parse( json )
|
105
|
+
else
|
106
|
+
puts "skipping reading (loading) from #{basename} -- file not found"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end # class Stats
|
111
|
+
|
112
|
+
|
113
|
+
end # module Hubba
|
data/lib/hubba/version.rb
CHANGED
data/test/test_stats.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_stats.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
|
11
|
+
class TestStats < MiniTest::Test
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@gh = Hubba::Github.new( cache_dir: "#{Hubba.root}/test/cache" )
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_stats
|
18
|
+
repos = [
|
19
|
+
'henrythemes/jekyll-starter-theme',
|
20
|
+
'poole/hyde',
|
21
|
+
'jekyll/minima'
|
22
|
+
]
|
23
|
+
|
24
|
+
repos.each do |repo|
|
25
|
+
stats = Hubba::Stats.new( repo )
|
26
|
+
stats.read( data_dir: './tmp' )
|
27
|
+
|
28
|
+
puts "stars before fetch: #{stats.stars}"
|
29
|
+
puts "size before fetch: #{stats.size} kb"
|
30
|
+
stats.fetch( @gh )
|
31
|
+
puts "stars after fetch: #{stats.stars}"
|
32
|
+
puts "size after fetch: #{stats.size} kb"
|
33
|
+
|
34
|
+
stats.write( data_dir: './tmp' )
|
35
|
+
end
|
36
|
+
|
37
|
+
assert true # for now everything ok if we get here
|
38
|
+
end
|
39
|
+
|
40
|
+
end # class TestStats
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logutils
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.15'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.15'
|
55
55
|
description: hubba - (yet) another (lite) GitHub HTTP API client / library
|
56
56
|
email: ruby-talk@ruby-lang.org
|
57
57
|
executables: []
|
@@ -69,12 +69,14 @@ files:
|
|
69
69
|
- lib/hubba/cache.rb
|
70
70
|
- lib/hubba/client.rb
|
71
71
|
- lib/hubba/github.rb
|
72
|
+
- lib/hubba/stats.rb
|
72
73
|
- lib/hubba/version.rb
|
73
74
|
- test/cache/users~geraldb~orgs.json
|
74
75
|
- test/cache/users~geraldb~repos.json
|
75
76
|
- test/helper.rb
|
76
77
|
- test/test_cache.rb
|
77
78
|
- test/test_config.rb
|
79
|
+
- test/test_stats.rb
|
78
80
|
homepage: https://github.com/rubylibs/hubba
|
79
81
|
licenses:
|
80
82
|
- Public Domain
|
@@ -97,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
99
|
version: '0'
|
98
100
|
requirements: []
|
99
101
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.6.7
|
101
103
|
signing_key:
|
102
104
|
specification_version: 4
|
103
105
|
summary: hubba - (yet) another (lite) GitHub HTTP API client / library
|