deka 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: ac4d091e219f45f44290ef7e48a6781a9c8dc868
4
+ data.tar.gz: bc5e5b5a3172901bf9d554b76ee1ec31c1caa561
5
+ SHA512:
6
+ metadata.gz: 03d1fe989ec67e09cfc746247fa6a723c78a840de8a7c9fb61dcb792260f0f10550f16690bae5974a5543b15e379efaf58062e0b04c1ba13d05d3b5ce0992ce9
7
+ data.tar.gz: 4155b9367d4445f27952eb52ac5a38dc9b861ff37b3640ce66bf3a35a23cac7d040f8d9426352aceac2651442f61012eb2b0f42a6064e550f36e378dd6f92eeb
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
data/.hound.yml ADDED
@@ -0,0 +1,5 @@
1
+ StringLiterals:
2
+ # Valid values (denoting the preferred quote delimiters) are:
3
+ # single_quotes, double_quotes
4
+ EnforcedStyle: single_quotes
5
+ Enabled: true
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in readme-tracker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 willnet
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,55 @@
1
+ # Deka
2
+
3
+ [![Build Status](https://travis-ci.org/willnet/deka.svg?branch=master)](https://travis-ci.org/willnet/deka)
4
+
5
+ Deka provides `deka` command which track files (ex: README.md) and write github issues if new commits detected. It is useful to translate documents on github and keep them fresh.
6
+
7
+ ### examples of use
8
+
9
+ - [willnet/capybara-readme-ja](https://github.com/willnet/capybara-readme-ja)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'deka'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install deka
24
+
25
+ ## Usage
26
+
27
+ * requirement: `git` command
28
+ * You should create a config file (ex: `./deka.yml`) and write settings.
29
+ * Use `deka` command to watch `watching_repo` and write issues to `issuing_repo`. If you don't want to watch all commits, write a commit hash to `.tracked_hash`, deka doesn't write issues prior to the commit hash.
30
+ * `.tracked_hash` if automatically updated by `deka` command
31
+
32
+ ```
33
+ Usage: deka [options]
34
+ --dry-run Dry run
35
+ -c, --config config path (default `./deka.yml`)
36
+ -s, --save path for saving tracked hash (default `./.tracked_hash`)
37
+ ```
38
+
39
+ ### config file example
40
+
41
+ ```
42
+ watching_files: 'README.md'
43
+ watching_repo: 'willnet/readme_tracker_watching_repo'
44
+ issuing_repo: 'willnet/readme_tracker_issuing_repo'
45
+ body: 'please respond'
46
+ access_token: YOUR_GITHUB_ACCESS_TOKEN
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/willnet/deka/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Bundler.setup
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new("spec")
7
+ task :default => :spec
data/bin/deka ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+ require 'bundler'
5
+ Bundler.require
6
+ require 'deka'
7
+ require 'slop'
8
+
9
+ opts = Slop.new(strict: true) do
10
+ banner 'Usage: deka [options]'
11
+ on 'dry-run', 'Dry run'
12
+ on 'c=', 'config', 'config path (default `./deka.yml`)'
13
+ on 's=', 'save', 'path for saving tracked hash (default `./.tracked_hash`)'
14
+ end
15
+
16
+ begin
17
+ opts.parse
18
+ Deka::Cli.run(opts.to_hash)
19
+ rescue Slop::Error => e
20
+ puts e.message
21
+ puts opts # print help
22
+ end
data/lib/deka.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'deka/version'
2
+ require 'deka/cli'
3
+
4
+ module Deka
5
+ end
data/lib/deka/cli.rb ADDED
@@ -0,0 +1,109 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+ require 'octokit'
4
+
5
+ class Deka::Cli
6
+ attr_accessor :config, :base_hash, :yaml, :save_file
7
+
8
+ def self.run(options = {})
9
+ new(options).run
10
+ end
11
+
12
+ def initialize(options = {})
13
+ @config = options[:config] || './deka.yml'
14
+ @save_file = options[:save] || './.tracked_hash'
15
+ @base_hash = File.read(save_file).chomp
16
+ @dry_run = options[:'dry-run']
17
+ end
18
+
19
+ def run
20
+ log = fetch_log
21
+
22
+ all_hashes = log.each_line.map { |line| line.strip[0..39] }
23
+ issue_hashes = all_hashes.take_while { |hash| hash != base_hash }.reverse
24
+
25
+ issue_hashes.each do |issue_hash|
26
+ create_issue(issuing_repo, issue_hash)
27
+ end
28
+
29
+ update_lastest_hash(issue_hashes.last)
30
+ ensure
31
+ delete_temp_repo
32
+ end
33
+
34
+ def client
35
+ @client ||= Octokit::Client.new(access_token: access_token)
36
+ end
37
+
38
+ private
39
+
40
+ def yaml
41
+ @yaml = YAML.load(File.read(config))
42
+ end
43
+
44
+ def watching_files
45
+ yaml['watching_files'] || 'README.md'
46
+ end
47
+
48
+ def watching_repo
49
+ yaml['watching_repo']
50
+ end
51
+
52
+ def issuing_repo
53
+ yaml['issuing_repo']
54
+ end
55
+
56
+ def access_token
57
+ yaml['access_token']
58
+ end
59
+
60
+ def directory_name
61
+ watching_repo.split('/')[1]
62
+ end
63
+
64
+ def issue_title(issue_hash)
65
+ "about #{issue_hash[0..6]}"
66
+ end
67
+
68
+ def issue_body(issue_hash)
69
+ commit_url = "https://github.com/#{watching_repo}/commit/#{issue_hash}"
70
+ if yaml['body']
71
+ yaml['body'] + "\n\n#{commit_url}"
72
+ else
73
+ "please respond \n\n#{commit_url}"
74
+ end
75
+ end
76
+
77
+ def fetch_log
78
+ system "git clone https://github.com/#{watching_repo}.git"
79
+ log = ''
80
+ FileUtils.cd directory_name do
81
+ log = `git log --pretty=oneline #{watching_files}`
82
+ end
83
+ log
84
+ end
85
+
86
+ def create_issue(repo, hash)
87
+ title = issue_title(hash)
88
+ body = issue_body(hash)
89
+ unless @dry_run
90
+ client.create_issue(repo, title, body)
91
+ end
92
+ puts "created issue of #{hash}"
93
+ end
94
+
95
+ def update_lastest_hash(latest_hash)
96
+ unless @dry_run
97
+ File.open(save_file, 'w') do |file|
98
+ file.write(latest_hash)
99
+ end
100
+ end
101
+ puts "updated #{save_file} with #{latest_hash}"
102
+ end
103
+
104
+ def delete_temp_repo
105
+ if File.exist?(directory_name)
106
+ FileUtils.rm_r directory_name
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,3 @@
1
+ module Deka
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'deka/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'deka'
8
+ spec.version = Deka::VERSION
9
+ spec.authors = ['willnet']
10
+ spec.email = ['netwillnet@gmail.com']
11
+ spec.summary = %q{tracking commit of README}
12
+ spec.description = %q{tracking commit of README}
13
+ spec.homepage = 'https://github.com/willnet/deka'
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_dependency 'octokit'
22
+ spec.add_dependency 'slop'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Deka::Cli do
4
+ describe '#run' do
5
+ context 'when pass config and save_file as argument' do
6
+ let(:config) { File.expand_path('../support/sample.yml', __FILE__) }
7
+ let(:save_file) { File.expand_path('../support/.tracked_hash', __FILE__) }
8
+ let!(:old_hash_txt) { File.read(save_file) }
9
+
10
+ after do
11
+ File.open(save_file, 'w') do |file|
12
+ file.write(old_hash_txt)
13
+ end
14
+ end
15
+
16
+ it 'should git clone its repository and write new hash to save_file' do
17
+ cli = Deka::Cli.new(config: config, save: save_file)
18
+ expect(cli).to receive(:system).
19
+ with('git clone https://github.com/willnet/readme_tracker_watching_repo.git').
20
+ and_call_original
21
+ expect(cli.client).to receive(:create_issue).
22
+ with('willnet/readme_tracker_issuing_repo', 'about 670f679', "please respond\n\nhttps://github.com/willnet/readme_tracker_watching_repo/commit/670f67987f9616a020f91e00f146090617b06e8a")
23
+ expect(cli.client).to receive(:create_issue).
24
+ with('willnet/readme_tracker_issuing_repo', 'about ccd8832', "please respond\n\nhttps://github.com/willnet/readme_tracker_watching_repo/commit/ccd88321b9cca4ceb24fdb09c3e338656c6300fa")
25
+ cli.run
26
+ new_hash_txt = File.read(save_file)
27
+ expect(new_hash_txt).to eq 'ccd88321b9cca4ceb24fdb09c3e338656c6300fa'
28
+ end
29
+
30
+ context 'and pass dry-run is true' do
31
+ it 'should dry run' do
32
+ cli = Deka::Cli.new(
33
+ config: config,
34
+ save: save_file,
35
+ :'dry-run' => true
36
+ )
37
+ expect(cli).to receive(:system).
38
+ with('git clone https://github.com/willnet/readme_tracker_watching_repo.git').
39
+ and_call_original
40
+ expect(cli.client).not_to receive(:create_issue)
41
+ cli.run
42
+ new_hash_txt = File.read(save_file).chomp
43
+ expect(new_hash_txt).to eq '6ed23d83705e2cf864cc2fa7d1307e0f8131b1b9'
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,80 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+
18
+ require 'deka'
19
+
20
+ RSpec.configure do |config|
21
+ # The settings below are suggested to provide a good initial experience
22
+ # with RSpec, but feel free to customize to your heart's content.
23
+
24
+ # These two settings work together to allow you to limit a spec run
25
+ # to individual examples or groups you care about by tagging them with
26
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
27
+ # get run.
28
+ config.filter_run :focus
29
+ config.run_all_when_everything_filtered = true
30
+
31
+ # Many RSpec users commonly either run the entire suite or an individual
32
+ # file, and it's useful to allow more verbose output when running an
33
+ # individual spec file.
34
+ if config.files_to_run.one?
35
+ # Use the documentation formatter for detailed output,
36
+ # unless a formatter has already been configured
37
+ # (e.g. via a command-line flag).
38
+ config.default_formatter = 'doc'
39
+ end
40
+
41
+ # Print the 10 slowest examples and example groups at the
42
+ # end of the spec run, to help surface which specs are running
43
+ # particularly slow.
44
+ config.profile_examples = 10
45
+
46
+ # Run specs in random order to surface order dependencies. If you find an
47
+ # order dependency and want to debug it, you can fix the order by providing
48
+ # the seed, which is printed after each run.
49
+ # --seed 1234
50
+ config.order = :random
51
+
52
+ # Seed global randomization in this process using the `--seed` CLI option.
53
+ # Setting this allows you to use `--seed` to deterministically reproduce
54
+ # test failures related to randomization by passing the same `--seed` value
55
+ # as the one that triggered the failure.
56
+ Kernel.srand config.seed
57
+
58
+ # rspec-expectations config goes here. You can use an alternate
59
+ # assertion/expectation library such as wrong or the stdlib/minitest
60
+ # assertions if you prefer.
61
+ config.expect_with :rspec do |expectations|
62
+ # Enable only the newer, non-monkey-patching expect syntax.
63
+ # For more details, see:
64
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
65
+ expectations.syntax = :expect
66
+ end
67
+
68
+ # rspec-mocks config goes here. You can use an alternate test double
69
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
70
+ config.mock_with :rspec do |mocks|
71
+ # Enable only the newer, non-monkey-patching expect syntax.
72
+ # For more details, see:
73
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
74
+ mocks.syntax = :expect
75
+
76
+ # Prevents you from mocking or stubbing a method that does not exist on
77
+ # a real object. This is generally recommended.
78
+ mocks.verify_partial_doubles = true
79
+ end
80
+ end
@@ -0,0 +1 @@
1
+ 6ed23d83705e2cf864cc2fa7d1307e0f8131b1b9
@@ -0,0 +1,5 @@
1
+ watching_files: 'README.md'
2
+ watching_repo: 'willnet/readme_tracker_watching_repo'
3
+ issuing_repo: 'willnet/readme_tracker_issuing_repo'
4
+ body: 'please respond'
5
+ access_token: ''
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deka
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - willnet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-25 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: '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: slop
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: tracking commit of README
84
+ email:
85
+ - netwillnet@gmail.com
86
+ executables:
87
+ - deka
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".hound.yml"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/deka
100
+ - lib/deka.rb
101
+ - lib/deka/cli.rb
102
+ - lib/deka/version.rb
103
+ - readme_tracker.gemspec
104
+ - spec/cli_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/support/.tracked_hash
107
+ - spec/support/sample.yml
108
+ homepage: https://github.com/willnet/deka
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: tracking commit of README
132
+ test_files:
133
+ - spec/cli_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/support/.tracked_hash
136
+ - spec/support/sample.yml