rusky 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df3aa342ba13d0944def81bba2cc1cba8d3e77ab
4
- data.tar.gz: ea7f33e03538cfc6ec192c784d376c518495bf17
3
+ metadata.gz: f3486401faaa9256285e4bb78ac2e568b02b44fb
4
+ data.tar.gz: 4331ad56642deef3eb5c780475fadc2938f81940
5
5
  SHA512:
6
- metadata.gz: d04613960f789fa70be3a76154bcdd57f6d96cbfa3c6b644da9f6251dd23f54068a0c0d5bcdb65aa6e340128addb21b504c40e2ba4a397fca66c19c31ca8ddf3
7
- data.tar.gz: 547e587628bfe538730ea08b14a2f3038acfdfb4e52d02a25a6d92ddbd28c5d7a35071483da9312628f83279948562bd38004a3f2acb627ecf971fb1edd88301
6
+ metadata.gz: 5df28b56ad76d8614455ba01072e9f440826ee5ddf663740cd76298b034318eb5c591ff8acd11c39e6941720431007003c2491338eb02118dc431e26f6cda026
7
+ data.tar.gz: b951a4b78910fdb7fcef0b173a2285abd7b72e97eca18287fe7c5baf0758c69af7d6ad317bc8c821ae363310bc460ca7e6df6014394045f3c25f5c6a4b15b34c
@@ -3,3 +3,5 @@ language: ruby
3
3
  rvm:
4
4
  - 2.4.1
5
5
  before_install: gem install bundler -v 1.15.4
6
+ script:
7
+ - bundle exec rspec
data/README.md CHANGED
@@ -1,43 +1,70 @@
1
1
  # Rusky
2
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/rusky`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Rusky helps you to manage Git hooks easily.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ If you don't know Git hooks well, [the official document](https://git-scm.com/docs/githooks) would help you.
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'rusky'
12
+ gem 'rusky', group: :development
13
13
  ```
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle
17
+ ```console
18
+ $ bundle
19
+ ```
18
20
 
19
21
  Or install it yourself as:
20
22
 
21
- $ gem install rusky
23
+ ```console
24
+ $ gem install rusky
25
+ ```
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ 1. Add the following line into your Rakefile. It defines rake tasks to be executed on Git hook. The task names are 'rusky:#{git_hook_name}'.
30
+
31
+ ```ruby
32
+ require "rusky/task"
33
+ ```
34
+
35
+ 2. Create `.rusky` file and define what you want on Git hooks as YAML. Keys should be Git hook name. Values should be an array of shell commands. Rusky executes those commands on Git hook.
36
+
37
+ ```yaml
38
+ # .rusky
39
+ pre-commit:
40
+ - rubocop
41
+ pre-push:
42
+ - bundle exec rspec
43
+ ```
44
+
45
+ ### Customizable callback rake task
46
+
47
+ You can write your own rake task as a callback of Git hook.
48
+
49
+ ```ruby
50
+ # Rakefile
51
+ namespace :rusky do
52
+ task :pre_commit do
53
+ # Your awesome task
54
+ end
55
+ end
56
+ ````
26
57
 
27
58
  ## Development
28
59
 
29
- 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.
60
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
61
 
31
62
  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
63
 
33
64
  ## Contributing
34
65
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rusky. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ohbarye/rusky. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
67
 
37
68
  ## License
38
69
 
39
70
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the Rusky project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rusky/blob/master/CODE_OF_CONDUCT.md).
@@ -1,12 +1,103 @@
1
- require "rusky/version"
2
- require "rusky/callback"
1
+ require 'rusky/version'
2
+ require 'yaml'
3
+ require 'fileutils'
3
4
 
4
5
  module Rusky
6
+ HOOKS = %w[
7
+ applypatch-msg
8
+ pre-applypatch
9
+ post-applypatch
10
+ pre-commit
11
+ prepare-commit-msg
12
+ commit-msg
13
+ post-commit
14
+ pre-rebase
15
+ post-checkout
16
+ post-merge
17
+ pre-push
18
+ pre-receive
19
+ update
20
+ post-receive
21
+ post-update
22
+ push-to-checkout
23
+ pre-auto-gc
24
+ post-rewrite
25
+ sendemail-validate
26
+ ].freeze
27
+
5
28
  def self.install
6
- Rusky::Callback.install
29
+ cwd = `lsof -p #{Process.ppid} | grep cwd`.split(" ").last
30
+
31
+ git_path = File.join(cwd, '.git')
32
+ if !File.exists? git_path
33
+ puts "can't find .git directory, skipping Git hooks installation"
34
+ return
35
+ end
36
+
37
+ hook_path = File.join(git_path, 'hooks')
38
+ if !File.exists? hook_path
39
+ FileUtils.mkdir_p hook_path
40
+ end
41
+
42
+ HOOKS.map do |hook_name|
43
+ create_hook(hook_name, hook_path, cwd)
44
+ end
45
+
46
+ # TODO create Rusky file
47
+ # TODO add `require` into Rakefile?
48
+ rescue => e
49
+ puts "unexpected error happened: #{e.inspect}"
50
+ end
51
+
52
+ def self.create_hook(hook_name, hook_path, cwd)
53
+ script = get_hook_script(hook_name, cwd)
54
+ filename = File.join(hook_path, hook_name)
55
+
56
+ # TODO check if it's okay to overwrite
57
+
58
+ write(filename, script)
7
59
  end
8
60
 
61
+ def self.write(filename, script)
62
+ File.write filename, script
63
+ FileUtils.chmod(0755, filename)
64
+ end
65
+
66
+ def self.get_hook_script(hook_name, cwd)
67
+ no_verify_message = if hook_name == 'prepare-commit-msg'
68
+ '(cannot be bypassed with --no-verify due to Git specs)'
69
+ else
70
+ '(add --no-verify to bypass)'
71
+ end
72
+
73
+ rake_task_name = "rusky:#{hook_name.gsub('-', '_')}"
74
+
75
+ <<~EOS
76
+ #!/bin/sh
77
+ #rusky #{Rusky::VERSION}
78
+ has_hook_script () {
79
+ [ -f .rusky ] && cat .rusky | grep -q "$1:"
80
+ }
81
+ cd "#{cwd}"
82
+ # Check if #{hook_name} script is defined, skip if not
83
+ has_hook_script #{hook_name} || exit 0
84
+
85
+ # Export Git hook params
86
+ export GIT_PARAMS="$*"
87
+ # Run command
88
+ echo "rusky > #{hook_name} Git hook is running"
89
+ echo "rusky > bundle exec rake #{rake_task_name}"
90
+ echo
91
+ bundle exec rake #{rake_task_name} || {
92
+ echo
93
+ echo "rusky > #{hook_name} Git hook failed #{no_verify_message}"
94
+ exit 1
95
+ }
96
+ EOS
97
+ end
98
+
99
+
9
100
  def self.uninstall
10
- Rusky::Callback.uninstall
101
+ # TODO uninstall
11
102
  end
12
103
  end
@@ -0,0 +1,42 @@
1
+ require 'rake'
2
+ require 'yaml'
3
+ require 'rusky'
4
+
5
+ module Rusky
6
+ class Task
7
+ include Rake::DSL if defined? Rake::DSL
8
+
9
+ class << self
10
+ def install_tasks(base=nil)
11
+ new(base).install
12
+ end
13
+ end
14
+
15
+ def initialize(base=nil)
16
+ @base = base || `lsof -p #{Process.ppid} | grep cwd`.split(" ").last
17
+ @yaml = YAML.load_file(File.join(@base, '.rusky'))
18
+ end
19
+
20
+ def install
21
+ Rusky::HOOKS.each do |hook_name|
22
+ rake_task_name = "rusky:#{hook_name.gsub('-', '_')}"
23
+
24
+ # prioritize existing user hook
25
+ if Rake::Task.task_defined? rake_task_name
26
+ next # Need to invoke?
27
+ end
28
+
29
+ task "#{rake_task_name}" do
30
+ commands = @yaml[hook_name]
31
+
32
+ commands.each do |command|
33
+ puts "rusky > #{command}"
34
+ system(command) || raise("#{command} failed")
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ Rusky::Task.install_tasks
@@ -1,3 +1,3 @@
1
1
  module Rusky
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -5,28 +5,22 @@ require "rusky/version"
5
5
 
6
6
  Gem.post_install do |installer|
7
7
  require "rusky"
8
-
9
8
  Rusky.install
10
- puts installer.inspect
11
- puts installer.instance_variable_get(:gem_dir)
12
9
  end
13
10
 
14
11
  Gem.pre_uninstall do |uninstaller|
15
12
  require "rusky"
16
-
17
13
  Rusky.uninstall
18
- puts uninstaller.inspect
19
- puts installer.instance_variable_get(:gem_dir)
20
14
  end
21
15
 
22
16
  Gem::Specification.new do |spec|
23
17
  spec.name = "rusky"
24
18
  spec.version = Rusky::VERSION
25
- spec.authors = ["ohbarye"]
19
+ spec.authors = ["Masato Ohba"]
26
20
  spec.email = ["over.rye@gmail.com"]
27
21
 
28
- spec.summary = "Add githooks easily"
29
- spec.description = "Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...)"
22
+ spec.summary = "Add Git hooks easily"
23
+ spec.description = "Rusky helps you to manage Git hooks easily."
30
24
  spec.homepage = "https://github.com/ohbarye/rusky"
31
25
  spec.license = "MIT"
32
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rusky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
- - ohbarye
7
+ - Masato Ohba
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-30 00:00:00.000000000 Z
11
+ date: 2017-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,8 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush,
56
- post-merge/postmerge and all that stuff...)
55
+ description: Rusky helps you to manage Git hooks easily.
57
56
  email:
58
57
  - over.rye@gmail.com
59
58
  executables: []
@@ -63,7 +62,6 @@ files:
63
62
  - ".gitignore"
64
63
  - ".rspec"
65
64
  - ".travis.yml"
66
- - CODE_OF_CONDUCT.md
67
65
  - Gemfile
68
66
  - LICENSE.txt
69
67
  - README.md
@@ -71,7 +69,7 @@ files:
71
69
  - bin/console
72
70
  - bin/setup
73
71
  - lib/rusky.rb
74
- - lib/rusky/callback.rb
72
+ - lib/rusky/task.rb
75
73
  - lib/rusky/version.rb
76
74
  - rusky.gemspec
77
75
  homepage: https://github.com/ohbarye/rusky
@@ -97,5 +95,5 @@ rubyforge_project:
97
95
  rubygems_version: 2.6.13
98
96
  signing_key:
99
97
  specification_version: 4
100
- summary: Add githooks easily
98
+ summary: Add Git hooks easily
101
99
  test_files: []
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at over.rye@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
@@ -1,15 +0,0 @@
1
- module Rusky
2
- module Callback
3
- def self.install
4
- puts 'installed'
5
- rusky_dir = File.expand_path(File.dirname($0))
6
- puts rusky_dir
7
- end
8
-
9
- def self.uninstall
10
- puts 'uninstalled'
11
- rusky_dir = File.expand_path(File.dirname($0))
12
- puts rusky_dir
13
- end
14
- end
15
- end