githop 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e2ea41a67fe6d9af45021fb92585965cfcc7eee
4
+ data.tar.gz: 31faa04a8eae5333ba04ce07e4810e450873df2f
5
+ SHA512:
6
+ metadata.gz: 31fa3bc92f1f8d475ad975b5e6f1362b49da3684626021e4531a2375afbbd281a5585bc51c30e98b223d46837789486e738bb4bac4593046232b28d9433480e8
7
+ data.tar.gz: f811e55ea711952ec068f9a3bd3bc0786303338235f897b7c78575c968f4f4c60276165d7ce6f7485fa8f4f43da1353526b6bcbd7c5599dfcfaae6956c756af5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ bigquery-sample.marshal
17
+ privatekey.p12
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ Metrics/AbcSize:
2
+ Max: 35
3
+
4
+ Metrics/LineLength:
5
+ Max: 105
6
+
7
+ Metrics/MethodLength:
8
+ Max: 15
9
+
10
+ Style/Documentation:
11
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Boris Bügling
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # githop
2
+
3
+ 🐙⏰
4
+
5
+ Uses [BigQuery][3] and [GitHub Archive][2] to create something like [TimeHop][4] for GitHub. It will
6
+ show you the things you did exactly one year ago.
7
+
8
+ ## Usage
9
+
10
+ If you are orta and it is 24th of May, 2015, you might see something like this:
11
+
12
+ ```bash
13
+ $ githop
14
+ At 2014-05-24 11:54:54, you forked the repo cocodelabs/NSAttributedString-CCLFormat
15
+ At 2014-05-24 11:56:49, you created a PR on cocodelabs/NSAttributedString-CCLFormat
16
+ At 2014-05-24 22:03:42, you created a PR on CocoaPods/cocoadocs.org
17
+ At 2014-05-24 22:32:20, you created the tag 2.7.2 on orta/ARAnalytics
18
+ ```
19
+
20
+ or specify a username to see another person's history:
21
+
22
+ ```bash
23
+ $ githop jpsim
24
+ At 2014-05-24 10:15:34, jpsim watched the repo shahruz/Sketch-Toolbox
25
+ At 2014-05-24 10:18:35, jpsim watched the repo heardrwt/RHObjectiveBeagle
26
+ ```
27
+
28
+ ## Installation
29
+
30
+ Use
31
+
32
+ ```bash
33
+ gem install githop
34
+ ```
35
+
36
+ to install the it and configure some settings in `~/.githop.yml`:
37
+
38
+ ```yaml
39
+ ---
40
+ github_user: your GitHub username
41
+
42
+ bigquery: {
43
+ client_id: BigQuery OAuth Client-ID,
44
+ service_email: BigQuery Service E-Mail,
45
+ keyfile: Location of your BigQuery key (a .p12 file),
46
+ project_id: ID of your BigQuery project
47
+ }
48
+ ```
49
+
50
+ Please follow [these steps][5] to set up a [BigQuery][3] OAuth application and take a look at
51
+ [this][6] for manually verifying your Google Cloud account works. [BigQuery][3] is free for 3TB
52
+ of queries and you don't have to set up any payments to use GitHop.
53
+
54
+ ## Thanks
55
+
56
+ Felix Krause for the [idea][1].
57
+
58
+ [1]: https://twitter.com/KrauseFx/status/602506804547977216
59
+ [2]: https://www.githubarchive.org/
60
+ [3]: https://cloud.google.com/bigquery/what-is-bigquery
61
+ [4]: http://timehop.com
62
+ [5]: https://github.com/abronte/BigQuery#keys
63
+ [6]: https://www.githubarchive.org/#bigquery
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/githop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if $PROGRAM_NAME == __FILE__
4
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
5
+ require 'rubygems'
6
+ require 'bundler/setup'
7
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
8
+ end
9
+
10
+ require 'githop'
11
+
12
+ config = YAML.load(File.read("#{ENV['HOME']}/.githop.yml"))
13
+ other_user = ARGV.first
14
+
15
+ result = GitHop.hop(config, other_user)
16
+
17
+ if result['rows'].nil?
18
+ $stderr.puts "GitHub Archive query for #{other_user || config['github_user']} had no results."
19
+ $stderr.puts result.inspect
20
+ exit(1)
21
+ end
22
+
23
+ result = GitHop.pretty_print(result, other_user)
24
+
25
+ if result.count == 0
26
+ puts "No events found, but #{other_user || 'you'} surely had an awesome day nevertheless :)"
27
+ else
28
+ puts result
29
+ end
data/githop.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'githop/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'githop'
8
+ spec.version = GitHop::VERSION
9
+ spec.authors = ['Boris Bügling']
10
+ spec.email = ['boris@buegling.com']
11
+ spec.summary = 'Uses BigQuery and GitHub Archive to create something like TimeHop for GitHub.'
12
+ spec.homepage = 'https://github.com/neonichu/githop'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+
23
+ spec.add_dependency 'activesupport'
24
+ spec.add_dependency 'bigquery'
25
+ end
data/lib/githop.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'githop/version'
2
+
3
+ require 'active_support/time'
4
+ require 'big_query'
5
+ require 'json'
6
+ require 'yaml'
7
+
8
+ module GitHop
9
+ private
10
+
11
+ def self.build_query_2014(gh_user)
12
+ end_date = 1.year.ago
13
+ month = end_date.strftime('%Y%m')
14
+ end_date = end_date.strftime('%Y-%m-%d')
15
+
16
+ query = <<END
17
+ SELECT type, repository_owner, repository_name, created_at, payload_url, payload_desc, payload_ref,
18
+ payload_ref_type
19
+ FROM ([githubarchive:month.#{month}])
20
+ WHERE actor = '#{gh_user}' AND
21
+ (created_at LIKE '#{end_date}%')
22
+ ORDER BY created_at;
23
+ END
24
+ query
25
+ end
26
+
27
+ def self.build_query_2015(gh_user)
28
+ end_date = 1.year.ago
29
+ start_date = (end_date - 1.day).strftime('%Y-%m-%d')
30
+ end_date = end_date.strftime('%Y-%m-%d')
31
+
32
+ query = <<END
33
+ SELECT type, repo.name, created_at,
34
+ JSON_EXTRACT(payload, '$.action') as event,
35
+ FROM (TABLE_DATE_RANGE([githubarchive:day.events_],
36
+ TIMESTAMP('#{start_date}'),
37
+ TIMESTAMP('#{end_date}')
38
+ ))
39
+ WHERE actor.login = '#{gh_user}' ORDER BY created_at;
40
+ END
41
+ query
42
+ end
43
+
44
+ def self.client_options(config)
45
+ opts = {}
46
+ opts['client_id'] = config['bigquery']['client_id']
47
+ opts['service_email'] = config['bigquery']['service_email']
48
+ opts['key'] = config['bigquery']['keyfile']
49
+ opts['project_id'] = config['bigquery']['project_id']
50
+ opts
51
+ end
52
+
53
+ def self.hop(config, user = nil)
54
+ bq = BigQuery::Client.new(client_options(config))
55
+ query = build_query_2014(user || config['github_user'])
56
+ result = bq.query(query)
57
+
58
+ # File.open('bigquery-sample.marshal', 'w') { |to_file| Marshal.dump(result, to_file) }
59
+ # exit(0)
60
+ # result = File.open('bigquery-sample.marshal', 'r') { |from_file| Marshal.load(from_file) }
61
+
62
+ result
63
+ end
64
+
65
+ def self.labels
66
+ {
67
+ 'CreateEvent' => 'created the',
68
+ 'ForkEvent' => 'forked the repo',
69
+ 'IssueCommentEvent' => 'commented an issue on',
70
+ 'IssuesEvent' => 'created an issue on',
71
+ 'PullRequestEvent' => 'created a PR on',
72
+ 'PushEvent' => 'pushed commits to',
73
+ 'WatchEvent' => 'watched the repo'
74
+ }
75
+ end
76
+
77
+ def self.pretty_print(result, user = nil)
78
+ result['rows'].map { |row| row['f'] }.map do |event|
79
+ type, owner, repo, created_at = event[0]['v'], event[1]['v'], event[2]['v'], event[3]['v']
80
+ _, _, ref, ref_type = event[4]['v'], event[5]['v'], event[6]['v'], event[7]['v']
81
+
82
+ # Filter some not so interesting events
83
+ next if %w(IssueCommentEvent IssuesEvent PushEvent).include?(type)
84
+
85
+ action = labels[type]
86
+ fail "Unsupported event type #{type}" if action.nil?
87
+
88
+ if type == 'CreateEvent'
89
+ action += " #{ref_type}"
90
+ action += " #{ref} on" if ref_type != 'repository'
91
+ end
92
+
93
+ "At #{created_at}, #{user || 'you'} #{action} #{owner}/#{repo}"
94
+ end.compact
95
+ end
96
+ end
@@ -0,0 +1,3 @@
1
+ module GitHop
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: githop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Boris Bügling
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-24 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: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
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: bigquery
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
+ description:
70
+ email:
71
+ - boris@buegling.com
72
+ executables:
73
+ - githop
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rubocop.yml
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - bin/githop
85
+ - githop.gemspec
86
+ - lib/githop.rb
87
+ - lib/githop/version.rb
88
+ homepage: https://github.com/neonichu/githop
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.14
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Uses BigQuery and GitHub Archive to create something like TimeHop for GitHub.
112
+ test_files: []
113
+ has_rdoc: