github_events_export 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0a8e220fc05a7b340169af0f9857d8f8326b4e9a14a77252997e5c14c94b9914
4
+ data.tar.gz: 1a264a0be1d8f5a19da87a7b9f3a9a91673e71b8c4f7452f0a1b5c3d7ed85b1e
5
+ SHA512:
6
+ metadata.gz: 3c749dd31f988405b75fa48dd24eeed93e874d8b57433792d5827f0bbafa4c92ae882741345597437788722951d5ad52d9ebce019b1b05b42ec860c16da30381
7
+ data.tar.gz: c8ff9cbce13bf93ec4ee96c097273203a17f79410013bee8af1ff187e4c1d31287bb457980bffefc9ee4d63886ef146c5de8d40a8737d3aaf17d59879737bd63
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in github_events_export.gemspec
4
+ gemspec
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ github_events_export (0.1.0)
5
+ octokit (~> 4.15.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ diff-lcs (1.3)
13
+ faraday (1.0.0)
14
+ multipart-post (>= 1.2, < 3)
15
+ multipart-post (2.1.1)
16
+ octokit (4.15.0)
17
+ faraday (>= 0.9)
18
+ sawyer (~> 0.8.0, >= 0.5.3)
19
+ public_suffix (4.0.2)
20
+ rake (10.5.0)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.1)
26
+ rspec-support (~> 3.9.1)
27
+ rspec-expectations (3.9.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.2)
34
+ sawyer (0.8.2)
35
+ addressable (>= 2.3.5)
36
+ faraday (> 0.8, < 2.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 2.0)
43
+ github_events_export!
44
+ rake (~> 10.0)
45
+ rspec (~> 3.0)
46
+
47
+ BUNDLED WITH
48
+ 2.1.2
@@ -0,0 +1,36 @@
1
+ # GithubEventsExport
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/github_events_export`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'github_events_export'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install github_events_export
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/garethrees/github_events_export.
36
+
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'github_events_export'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
5
+
6
+ require 'github_events_export'
7
+ exit GithubEventsExport::CLI.run(ARGV)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'github_events_export/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'github_events_export'
9
+ spec.version = GithubEventsExport::VERSION
10
+ spec.authors = ['Gareth Rees']
11
+ spec.email = ['gareth@garethrees.co.uk']
12
+ spec.license = 'MIT'
13
+
14
+ spec.summary = 'Export GitHub events to JSON files'
15
+ spec.homepage = 'https://github.com/garethrees/github_events_export'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = spec.homepage
19
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
20
+
21
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
25
+ # into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(spec)/})
29
+ end
30
+ end
31
+
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_runtime_dependency 'octokit', '~> 4.15.0'
37
+
38
+ spec.add_development_dependency 'bundler', '~> 2.0'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'octokit'
4
+
5
+ require 'github_events_export/cli'
6
+ require 'github_events_export/event'
7
+ require 'github_events_export/export'
8
+ require 'github_events_export/options'
9
+ require 'github_events_export/version'
10
+
11
+ # Export GitHub Events to individual JSON files
12
+ module GithubEventsExport
13
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GithubEventsExport
4
+ # Entrypoint for CLI usage
5
+ class CLI
6
+ STATUS_SUCCESS = 0
7
+ STATUS_FAILURE = 1
8
+
9
+ def self.run(argv)
10
+ new(Options.new(argv)).run
11
+ end
12
+
13
+ def initialize(options)
14
+ @options = options
15
+ end
16
+
17
+ def run
18
+ Export.new(client).run
19
+ STATUS_SUCCESS
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :options
25
+
26
+ def client
27
+ @client ||= ::Octokit::Client.new(
28
+ access_token: options[:token],
29
+ auto_paginate: true
30
+ )
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ module GithubEventsExport
6
+ # Wrapper around a GitHub Event
7
+ # https://developer.github.com/v3/activity/events
8
+ class Event
9
+ def self.all(client)
10
+ client.user_events(client.user.id).map { |e| new(e) }
11
+ end
12
+
13
+ def initialize(event_data)
14
+ @event_data = event_data
15
+ end
16
+
17
+ def save
18
+ save! if changed?
19
+ end
20
+
21
+ def save!
22
+ File.write(filename, to_json)
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :event_data
28
+
29
+ def changed?
30
+ return true unless persisted?
31
+
32
+ Digest::MD5.hexdigest(to_json) !=
33
+ Digest::MD5.hexdigest(File.read(filename))
34
+ end
35
+
36
+ def persisted?
37
+ File.exist?(filename)
38
+ end
39
+
40
+ def filename
41
+ "#{event_data.id}.json"
42
+ end
43
+
44
+ def to_json
45
+ event_data.to_h.to_json
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GithubEventsExport
4
+ # Save each Event to disk
5
+ class Export
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def run
11
+ Event.all(client).each(&:save)
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :client
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ module GithubEventsExport
6
+ # Parse CLI options
7
+ class Options
8
+ def initialize(args)
9
+ @args = args
10
+ end
11
+
12
+ def [](key)
13
+ parse[key]
14
+ end
15
+
16
+ def to_hash
17
+ parse
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :args
23
+
24
+ def parse
25
+ options = {}
26
+ option_parser.parse!(args, into: options)
27
+ options
28
+ end
29
+
30
+ def option_parser
31
+ OptionParser.new do |opts|
32
+ opts.banner = 'Usage: github-events-export [options]'
33
+ opts.on('--token=TOKEN', 'GitHub Access Token')
34
+ opts.on('-v', '--version', 'Print version')
35
+ opts.on('-h', '--help', 'Prints this help') do
36
+ puts opts
37
+ exit 1
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GithubEventsExport
4
+ VERSION = '0.1.0'.freeze
5
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_events_export
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gareth Rees
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.15.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.15.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - gareth@garethrees.co.uk
72
+ executables:
73
+ - github-events-export
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - exe/github-events-export
86
+ - github_events_export.gemspec
87
+ - lib/github_events_export.rb
88
+ - lib/github_events_export/cli.rb
89
+ - lib/github_events_export/event.rb
90
+ - lib/github_events_export/export.rb
91
+ - lib/github_events_export/options.rb
92
+ - lib/github_events_export/version.rb
93
+ homepage: https://github.com/garethrees/github_events_export
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ homepage_uri: https://github.com/garethrees/github_events_export
98
+ source_code_uri: https://github.com/garethrees/github_events_export
99
+ changelog_uri: https://github.com/garethrees/github_events_export/blob/master/CHANGELOG.md
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 2.3.0
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.0.6
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Export GitHub events to JSON files
119
+ test_files: []