reading_log_extractor 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
+ SHA1:
3
+ metadata.gz: 0951f95c697e152a812366f3412115a21a102ead
4
+ data.tar.gz: 92129118573102811ce936d50d9b40b1941a60a1
5
+ SHA512:
6
+ metadata.gz: 39afa567a60da713656b93ec6904b9372c30054e7c7bab87c62fdb0848efcb916dac6d45cadccba11f0fbf67c5f4231d4001c59e35e244bfbdfca6f758270228
7
+ data.tar.gz: 5174ce44e3ce3eff151a4a8f4c7bf1cf113d1faae2280e970f42f8a41240c6071d9fe6ca0d09f798814d0e379b3e732f1bb4b861bcac3d098a99b2025e11c4d8
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
11
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.1.1
5
+ - 2.1.2
6
+ - 2.1.3
7
+ - 2.1.4
8
+ - 2.1.5
9
+ - 2.2.0
10
+ - 2.2.1
11
+ - 2.2.2
12
+ - 2.2.3
13
+ - ruby-head
14
+ - jruby-head
15
+ before_install: gem install bundler -v 1.10.6
16
+ addons:
17
+ code_climate:
18
+ repo_token: b274504de9305e19eef507c4cbe4d982764aee59339de36ef5896823fcc2392b
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in reading_log_extractor.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "codeclimate-test-reporter", require: nil
8
+ gem 'pry', require: nil
9
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tomas Valent
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.
@@ -0,0 +1,48 @@
1
+ [![Build Status](https://travis-ci.org/had-read/reading_log_extractor.svg)](https://travis-ci.org/had-read/reading_log_extractor)
2
+ [![Code Climate](https://codeclimate.com/github/had-read/reading_log_extractor/badges/gpa.svg)](https://codeclimate.com/github/had-read/reading_log_extractor)
3
+ [![Test Coverage](https://codeclimate.com/github/had-read/reading_log_extractor/badges/coverage.svg)](https://codeclimate.com/github/had-read/reading_log_extractor/coverage)
4
+
5
+ # ReadingLogExtractor
6
+
7
+ 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/reading_log_extractor`. To experiment with that code, run `bin/console` for an interactive prompt.
8
+
9
+ TODO: Delete this and the text above, and describe your gem
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'reading_log_extractor'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install reading_log_extractor
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/reading_log_extractor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
40
+
41
+ ## TODO
42
+
43
+ * ensure the reading-log is truly fork of had-read/reading-log
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
48
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "reading_log_extractor"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require 'github_api'
2
+ require 'uri'
3
+ require "reading_log_extractor/version"
4
+ require "reading_log_extractor/github_facade"
5
+ require "reading_log_extractor/processor"
6
+
7
+ module ReadingLogExtractor
8
+ class Config
9
+ attr_writer :reponame
10
+
11
+ def reponame
12
+ @reponame || 'reading-log'
13
+ end
14
+ end
15
+
16
+ def self.config
17
+ @config ||= Config.new
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module ReadingLogExtractor
2
+ class GithubFacade
3
+ attr_reader :gh_connection
4
+
5
+ def initialize(gh_connection:)
6
+ @gh_connection = gh_connection
7
+ end
8
+
9
+ def repo_list(username)
10
+ gh_connection.repos.list(user: username)
11
+ end
12
+
13
+ def commits(username, repo)
14
+ gh_connection
15
+ .repos
16
+ .commits
17
+ .list(username, repo)
18
+ end
19
+
20
+ def content_between(username, reponame, sha1, sha2)
21
+ gh_connection
22
+ .repos
23
+ .commits
24
+ .compare(username, reponame, sha1, sha2)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,97 @@
1
+ module ReadingLogExtractor
2
+ class Processor
3
+ class Commit
4
+ attr_reader :sha, :message, :author, :date, :avatar
5
+
6
+ def initialize(sha:, message:, author:, date:, avatar:)
7
+ @sha = sha
8
+ @message = message
9
+ @author = author
10
+ @date = date
11
+ @avatar = avatar
12
+ end
13
+ end
14
+
15
+ attr_reader :username, :reponame, :gh_facade
16
+
17
+ def initialize(username:, gh_facade:)
18
+ @gh_facade = gh_facade
19
+ @username = username
20
+ @reponame = ReadingLogExtractor.config.reponame
21
+ @mutex = Mutex.new
22
+ end
23
+
24
+ def repo_exist?
25
+ mutex.synchronize do
26
+ find_repo(gh_facade.repo_list(username))
27
+ end
28
+ end
29
+
30
+ def latest_commits(last_sha)
31
+ mutex.synchronize do
32
+ fetch_commits(gh_facade.commits(username, reponame), last_sha)
33
+ end
34
+ end
35
+
36
+ def content(sha1, sha2)
37
+ gh_facade
38
+ .content_between(username, reponame, sha1, sha2)
39
+ .files
40
+ .select {|f| f.filename == 'reading-log.md' }
41
+ .map(&:patch)
42
+ .first
43
+ end
44
+
45
+ private
46
+ attr_reader :mutex
47
+
48
+ def find_repo(list)
49
+ case list
50
+ when ->(ary) { ary.empty? }
51
+ false
52
+ when ->(ary) { list_has_reponame?(list) }
53
+ repo = list.lazy.select { |e| e.name == reponame }.first
54
+ repo.fork # true if it's a forked project
55
+ # in future gem will ensure weather the for is for
56
+ # of had-read/reading-log
57
+ else
58
+ find_repo(list.next_page)
59
+ end
60
+ end
61
+
62
+ def list_has_reponame?(list)
63
+ list.map(&:name).include?(reponame)
64
+ end
65
+
66
+ def fetch_commits(commits, sha, collection = [])
67
+ limit_reached = false
68
+
69
+ commits
70
+ .map { |g| init_commit(g) }
71
+ .each do |commit|
72
+ unless limit_reached
73
+ case commit.sha
74
+ when sha
75
+ limit_reached = true
76
+ else
77
+ collection << commit
78
+ end
79
+ end
80
+ end
81
+
82
+ if !limit_reached && !(next_page = commits.next_page).nil?
83
+ fetch_commits(next_page, sha, collection)
84
+ end
85
+
86
+ collection
87
+ end
88
+
89
+ def init_commit(gh_commit)
90
+ Commit.new(sha: gh_commit.sha,
91
+ message: gh_commit.commit.message,
92
+ author: gh_commit.author.login,
93
+ avatar: gh_commit.author.avatar_url,
94
+ date: gh_commit.commit.author.date )
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,3 @@
1
+ module ReadingLogExtractor
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reading_log_extractor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reading_log_extractor"
8
+ spec.version = ReadingLogExtractor::VERSION
9
+ spec.authors = ["Tomas Valent"]
10
+ spec.email = ["equivalent@eq8.eu"]
11
+
12
+ spec.summary = %q{Had Read reading-log extractor}
13
+ spec.description = %q{Had Read reading-log github api extractor}
14
+ spec.homepage = "https://github.com/had-read/reading_log_extractor"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "github_api", '~> 0.12'
31
+ spec.add_development_dependency "bundler", "~> 1.10"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", '~> 3.3'
34
+ spec.add_development_dependency "webmock", '~> 1.22'
35
+ spec.add_development_dependency "vcr", '~> 3.0'
36
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reading_log_extractor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Valent
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: github_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.22'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.22'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: Had Read reading-log github api extractor
98
+ email:
99
+ - equivalent@eq8.eu
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/reading_log_extractor.rb
115
+ - lib/reading_log_extractor/github_facade.rb
116
+ - lib/reading_log_extractor/processor.rb
117
+ - lib/reading_log_extractor/version.rb
118
+ - reading_log_extractor.gemspec
119
+ homepage: https://github.com/had-read/reading_log_extractor
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ allowed_push_host: https://rubygems.org
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.8
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Had Read reading-log extractor
144
+ test_files: []