rusky 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +14 -3
- data/lib/rusky/task.rb +19 -12
- data/lib/rusky/version.rb +1 -1
- data/lib/rusky.rb +37 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b70c085e2caab3d7284902bfd34eecb999001b5d
|
4
|
+
data.tar.gz: 07ce62ef2eb50ce35162758dba22c449e4909e92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d0ceeef2bb8b9f4efc214bca2f93c992ce874d084a17e27337512fc30bad0b81bc30d69080f1725665391c84dc2695e403327b8f0afa0a0b7445653a42bc6e3
|
7
|
+
data.tar.gz: 95777dfb0ae9f2422354545dea9820f715cc96377d1a838c1dc55d4adcf0d0d819f3c91ac7623749311792137cd17f973a0326167ead1bec3738c58c0e1c5ef2
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Rusky
|
2
2
|
|
3
|
-
Rusky helps you to manage Git hooks easily.
|
3
|
+
Rusky is a lightweight library which helps you to manage Git hooks easily. Once you set up Rusky, it would be beneficial for all your team.
|
4
|
+
|
5
|
+
This library is inspired an awesome npm library, [husky](https://github.com/typicode/husky). So Rusky = Ruby + husky.
|
4
6
|
|
5
7
|
If you don't know Git hooks well, [the official document](https://git-scm.com/docs/githooks) would help you.
|
6
8
|
|
@@ -24,12 +26,15 @@ Or install it yourself as:
|
|
24
26
|
$ gem install rusky
|
25
27
|
```
|
26
28
|
|
29
|
+
After installation, Rusky automatically creates git hook scripts in `.git/hooks` directory. It does not remove existing files.
|
30
|
+
|
27
31
|
## Usage
|
28
32
|
|
29
|
-
1. Add the following
|
33
|
+
1. Add the following lines into your Rakefile. It defines rake tasks to be executed on Git hook. The task names are `"rusky:#{git_hook_name}"`.
|
30
34
|
|
31
35
|
```ruby
|
32
36
|
require "rusky/task"
|
37
|
+
Rusky::Task.install
|
33
38
|
```
|
34
39
|
|
35
40
|
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.
|
@@ -48,12 +53,18 @@ You can write your own rake task as a callback of Git hook.
|
|
48
53
|
|
49
54
|
```ruby
|
50
55
|
# Rakefile
|
56
|
+
require "rusky/task"
|
57
|
+
|
51
58
|
namespace :rusky do
|
52
59
|
task :pre_commit do
|
53
60
|
# Your awesome task
|
54
61
|
end
|
55
62
|
end
|
56
|
-
|
63
|
+
|
64
|
+
Rusky::Task.install
|
65
|
+
```
|
66
|
+
|
67
|
+
NOTE: You have to call `Rusky::Task.install` after your task definition. Otherwise, the task is defined twice. According to the current Rake spec, such a duplicated task does not overwrite a former one, both run when calling the task.
|
57
68
|
|
58
69
|
## Development
|
59
70
|
|
data/lib/rusky/task.rb
CHANGED
@@ -7,14 +7,15 @@ module Rusky
|
|
7
7
|
include Rake::DSL if defined? Rake::DSL
|
8
8
|
|
9
9
|
class << self
|
10
|
-
def
|
10
|
+
def install(base=nil)
|
11
11
|
new(base).install
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def initialize(base=nil)
|
16
16
|
@base = base || `lsof -p #{Process.ppid} | grep cwd`.split(" ").last
|
17
|
-
|
17
|
+
rusky_setting_file_path = File.join(@base, '.rusky')
|
18
|
+
@yaml = File.exists?(rusky_setting_file_path) ? YAML.load_file(File.join(@base, '.rusky')) : Hash.new([])
|
18
19
|
end
|
19
20
|
|
20
21
|
def install
|
@@ -22,21 +23,27 @@ module Rusky
|
|
22
23
|
rake_task_name = "rusky:#{hook_name.gsub('-', '_')}"
|
23
24
|
|
24
25
|
# prioritize existing user hook
|
25
|
-
if Rake::Task.task_defined? rake_task_name
|
26
|
-
|
27
|
-
|
26
|
+
next if Rake::Task.task_defined? rake_task_name
|
27
|
+
|
28
|
+
define_task hook_name, rake_task_name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def define_task(hook_name, rake_task_name)
|
33
|
+
task "#{rake_task_name}" do
|
34
|
+
commands = @yaml[hook_name]
|
28
35
|
|
29
|
-
|
30
|
-
|
36
|
+
if commands.empty?
|
37
|
+
puts "rusky > No command for #{hook_name} is defined in .rusky file"
|
38
|
+
next
|
39
|
+
end
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
41
|
+
commands.each do |command|
|
42
|
+
puts "rusky > #{command}"
|
43
|
+
system(command) || raise("rusky > #{command} failed")
|
36
44
|
end
|
37
45
|
end
|
38
46
|
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
|
-
Rusky::Task.install_tasks
|
data/lib/rusky/version.rb
CHANGED
data/lib/rusky.rb
CHANGED
@@ -39,12 +39,14 @@ module Rusky
|
|
39
39
|
FileUtils.mkdir_p hook_path
|
40
40
|
end
|
41
41
|
|
42
|
-
HOOKS.
|
42
|
+
HOOKS.each do |hook_name|
|
43
43
|
create_hook(hook_name, hook_path, cwd)
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
rusky_setting_file_path = File.join(cwd, '.rusky')
|
47
|
+
if !File.exists? rusky_setting_file_path
|
48
|
+
File.write(rusky_setting_file_path, '')
|
49
|
+
end
|
48
50
|
rescue => e
|
49
51
|
puts "unexpected error happened: #{e.inspect}"
|
50
52
|
end
|
@@ -53,9 +55,16 @@ module Rusky
|
|
53
55
|
script = get_hook_script(hook_name, cwd)
|
54
56
|
filename = File.join(hook_path, hook_name)
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
if File.exists? filename
|
59
|
+
if File.read(filename).include? 'rusky'
|
60
|
+
# Overwrite
|
61
|
+
write(filename, script)
|
62
|
+
else
|
63
|
+
# Keep user original Git hook
|
64
|
+
end
|
65
|
+
else
|
66
|
+
write(filename, script)
|
67
|
+
end
|
59
68
|
end
|
60
69
|
|
61
70
|
def self.write(filename, script)
|
@@ -98,6 +107,27 @@ module Rusky
|
|
98
107
|
|
99
108
|
|
100
109
|
def self.uninstall
|
101
|
-
#
|
110
|
+
cwd = `lsof -p #{Process.ppid} | grep cwd`.split(" ").last
|
111
|
+
|
112
|
+
HOOKS.each do |hook_name|
|
113
|
+
remove_hook(cwd, hook_name)
|
114
|
+
end
|
115
|
+
|
116
|
+
rusky_setting_file_path = File.join(cwd, '.rusky')
|
117
|
+
if File.exists? rusky_setting_file_path
|
118
|
+
File.delete(rusky_setting_file_path)
|
119
|
+
puts "rusky > removing .rusky file..."
|
120
|
+
end
|
121
|
+
|
122
|
+
puts "rusky > uninstall is done. please remove rake tasks for rusky if you have them"
|
123
|
+
puts "rusky > Thank you for using rusky!"
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.remove_hook(cwd, hook_name)
|
127
|
+
filename = File.join(cwd, '.git', 'hooks', hook_name)
|
128
|
+
if File.exists?(filename) && File.read(filename).include?('rusky')
|
129
|
+
puts "rusky > removing #{hook_name} hook script..."
|
130
|
+
File.delete(filename)
|
131
|
+
end
|
102
132
|
end
|
103
133
|
end
|
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masato Ohba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|