rbgithook 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/Steepfile +6 -0
- data/exe/rbgithook +14 -6
- data/lib/rbgithook/version.rb +1 -1
- data/lib/rbgithook.rb +54 -16
- data/sig/rbgithook.rbs +16 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 126208371ad980b74efb9d3f90452e9ae9b05616d177a792e07c774e206f1f26
|
4
|
+
data.tar.gz: 98e3cff68de8a6946e00084e9d96fdeb1c7a329e6e8158c8b940ad3c6b6b8389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 101812bf06163703ea445fb781ccaf8457cb832ec36c37c98a7c978278232d28b12c9f4a5050d472f5d373bb10e3499865afbba7a28303dc87d93feec88752bf
|
7
|
+
data.tar.gz: cd6b654b1fba6548bc5453a885c60f8a24496cf09d35f308a6da5da0fa90c1cfff0d5233ddca7792a20e264e65b68835fff7b4a18708cbce8cd2f3b47823f952
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/Steepfile
ADDED
data/exe/rbgithook
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "rbgithook"
|
4
|
-
require "fileutils"
|
5
4
|
|
6
5
|
command = ARGV[0]
|
7
|
-
args = ARGV[1..]
|
8
6
|
|
9
|
-
if
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
if command.nil?
|
8
|
+
warn "Please specify a command to run\n\n"
|
9
|
+
Rbgithook.help
|
10
|
+
exit 1
|
13
11
|
end
|
12
|
+
|
13
|
+
cmds = {
|
14
|
+
"install" => ->(_) { Rbgithook.install },
|
15
|
+
"set" => ->(args) { Rbgithook.set(args) },
|
16
|
+
"add" => ->(args) { Rbgithook.add(args) },
|
17
|
+
"uninstall" => ->(_) { Rbgithook.uninstall },
|
18
|
+
"help" => ->(_) { Rbgithook.help }
|
19
|
+
}
|
20
|
+
|
21
|
+
cmds.key?(command) ? cmds[command].call(ARGV[1..]) : Rbgithook.help
|
data/lib/rbgithook/version.rb
CHANGED
data/lib/rbgithook.rb
CHANGED
@@ -1,39 +1,77 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "rbgithook/version"
|
4
|
+
require "fileutils"
|
4
5
|
|
5
6
|
module Rbgithook
|
7
|
+
DIRNAME = ".rbgithook"
|
8
|
+
|
6
9
|
def self.install
|
7
|
-
|
8
|
-
FileUtils.mkdir(dir) unless Dir.exist?(dir)
|
10
|
+
FileUtils.mkdir(DIRNAME) unless Dir.exist?(DIRNAME)
|
9
11
|
|
10
|
-
system("git", "config", "core.hooksPath",
|
12
|
+
system("git", "config", "core.hooksPath", DIRNAME)
|
11
13
|
end
|
12
14
|
|
13
15
|
def self.set(args)
|
14
|
-
file_name = args[0]
|
15
|
-
hook_command = args[1]
|
16
|
-
Dir.chdir(
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
file_name = get_file_name(args[0])
|
17
|
+
hook_command = get_hook_command(args[1])
|
18
|
+
Dir.chdir(DIRNAME)
|
19
|
+
File.open(file_name.to_s, "w") do |file|
|
20
|
+
file.write("#!/usr/bin/env sh\n#{hook_command}")
|
21
|
+
end
|
20
22
|
FileUtils.chmod(0o755, file_name)
|
21
23
|
end
|
22
24
|
|
23
25
|
def self.add(args)
|
24
|
-
file_name = args[0]
|
25
|
-
hook_command = args[1]
|
26
|
-
Dir.
|
26
|
+
file_name = get_file_name(args[0])
|
27
|
+
hook_command = get_hook_command(args[1])
|
28
|
+
unless Dir.exist?(DIRNAME)
|
29
|
+
warning_message("Directory", file_name, hook_command)
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
Dir.chdir(DIRNAME)
|
27
33
|
if File.exist?(file_name)
|
28
|
-
|
29
|
-
|
30
|
-
|
34
|
+
File.open(file_name.to_s, "a") do |file|
|
35
|
+
file.write("\n#{hook_command}")
|
36
|
+
end
|
31
37
|
else
|
32
|
-
|
38
|
+
warning_message("File", file_name, hook_command)
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
42
|
def self.uninstall
|
37
43
|
system("git", "config", "--unset", "core.hooksPath")
|
38
44
|
end
|
45
|
+
|
46
|
+
def self.help
|
47
|
+
puts <<~USAGE
|
48
|
+
rbgithook [command] {file} {command}
|
49
|
+
|
50
|
+
install - Install hook
|
51
|
+
set {file} {command} - Set a hook
|
52
|
+
add {file} {command} - Add a hook
|
53
|
+
uninstall - Uninstall hook
|
54
|
+
help - Show this usage
|
55
|
+
USAGE
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.warning_message(target, file_name, hook_command)
|
59
|
+
warn "#{target} not found, please run `rbgithook set #{file_name} '#{hook_command}'`"
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.get_file_name(file_name)
|
63
|
+
if file_name.nil?
|
64
|
+
warn "Please specify a file to hook"
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
file_name
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.get_hook_command(hook_command)
|
71
|
+
if hook_command.nil?
|
72
|
+
warn "Please specify a command to run"
|
73
|
+
exit 1
|
74
|
+
end
|
75
|
+
hook_command
|
76
|
+
end
|
39
77
|
end
|
data/sig/rbgithook.rbs
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# TypeProf 0.21.3
|
2
|
+
|
3
|
+
# Classes
|
4
|
+
module Rbgithook
|
5
|
+
VERSION: String
|
6
|
+
DIRNAME: String
|
7
|
+
|
8
|
+
def self.install: -> void
|
9
|
+
def self.set: (Array[String] args) -> void
|
10
|
+
def self.add: (Array[String] args) -> void
|
11
|
+
def self.uninstall: -> void
|
12
|
+
def self.help: -> void
|
13
|
+
def self.warning_message: (String target, String file_name, String hook_command) -> void
|
14
|
+
def self.get_file_name: (String file_name) -> String
|
15
|
+
def self.get_hook_command: (String hook_command) -> String
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbgithook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hyuraku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simple Git hook made by Ruby
|
14
14
|
email:
|
@@ -27,10 +27,12 @@ files:
|
|
27
27
|
- LICENSE.txt
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
|
+
- Steepfile
|
30
31
|
- exe/rbgithook
|
31
32
|
- lib/rbgithook.rb
|
32
33
|
- lib/rbgithook/version.rb
|
33
34
|
- rbgithook.gemspec
|
35
|
+
- sig/rbgithook.rbs
|
34
36
|
homepage: https://github.com/hyuraku/rbgithook
|
35
37
|
licenses:
|
36
38
|
- MIT
|