git-sleep 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/bin/git-sleep +33 -32
- data/hooks/post-commit +42 -0
- data/hooks/pre-commit +13 -6
- data/lib/git-sleep.rb +2 -2
- metadata +3 -2
data/README.md
CHANGED
data/bin/git-sleep
CHANGED
@@ -11,24 +11,22 @@ help_text = "Available commands:
|
|
11
11
|
git sleep init"
|
12
12
|
|
13
13
|
CURRENT_PATH = File.expand_path(".")
|
14
|
-
|
15
|
-
NON_SAMPLE_FILE_NAME = "#{CURRENT_PATH}/.git/hooks/pre-commit"
|
14
|
+
PATH_TO_THIS_REPOS_HOOKS = "#{CURRENT_PATH}/.git/hooks"
|
16
15
|
|
17
|
-
def install_hook
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
def install_hook(event)
|
17
|
+
hook_code = File.read(File.expand_path("../../hooks/#{event}", __FILE__))
|
18
|
+
path_to_new_hook = File.expand_path("#{PATH_TO_THIS_REPOS_HOOKS}/#{event}")
|
19
|
+
if File.exists? path_to_new_hook
|
20
|
+
puts "You already have a #{event} hook and we don't want to overwrite it..."
|
21
|
+
print "Is it okay? [y/n] "
|
22
|
+
ok = $stdin.gets.chomp
|
23
|
+
return unless ok == "y"
|
24
24
|
end
|
25
|
-
|
26
|
-
|
27
|
-
puts "Successfully installed hook. Enjoy your new sense of balance."
|
28
|
-
else
|
29
|
-
puts "Sorry, the hook failed to install..." # will this ever happen?
|
25
|
+
File.open(path_to_new_hook, "w") do |f|
|
26
|
+
f.write hook_code
|
30
27
|
end
|
31
|
-
|
28
|
+
`chmod a+x #{path_to_new_hook}`
|
29
|
+
puts "Hook installed and made executable"
|
32
30
|
end
|
33
31
|
|
34
32
|
|
@@ -38,32 +36,35 @@ when 0
|
|
38
36
|
when 1
|
39
37
|
case ARGV.first.downcase.to_sym
|
40
38
|
when :init
|
41
|
-
|
42
|
-
if Dir.entries(CURRENT_PATH).include?
|
43
|
-
puts "This is a git repo
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
puts "You already have a pre-commit hook and we don't want to overwrite it..."
|
49
|
-
print "Is it okay? [y/n] "
|
50
|
-
ok = $stdin.gets.chomp
|
51
|
-
install_hook() if ok == "y"
|
39
|
+
|
40
|
+
if !Dir.entries(CURRENT_PATH).include? ".git"
|
41
|
+
puts "This is not a git repo. Would you like to initialize one?"
|
42
|
+
print "[y/n] "
|
43
|
+
ok = $stdin.gets.chomp
|
44
|
+
if ok == "y"
|
45
|
+
`git init`
|
52
46
|
else
|
53
|
-
|
54
|
-
# this probably won't work because it won't be executable...?
|
55
|
-
install_hook()
|
47
|
+
exit 0
|
56
48
|
end
|
57
|
-
else
|
58
|
-
puts "This is not a git repo!"
|
59
49
|
end
|
50
|
+
|
51
|
+
puts "Install the pre-commit hook that prevents commits when you haven't sleep enough?"
|
52
|
+
print "Is it okay? [y/n] "
|
53
|
+
ok = $stdin.gets.chomp
|
54
|
+
install_hook("pre-commit") if ok == "y"
|
55
|
+
|
56
|
+
puts "Install the post-commit hook that adds git notes about your sleep data?"
|
57
|
+
print "Is it okay? [y/n] "
|
58
|
+
ok = $stdin.gets.chomp
|
59
|
+
install_hook("post-commit") if ok =="y"
|
60
|
+
|
60
61
|
when :authorize
|
61
62
|
puts "Visit #{GitSleep::OUR_SITE} to get the necessary information"
|
62
63
|
puts "what is your xid?"
|
63
64
|
print "> "
|
64
65
|
xid = $stdin.gets.chomp
|
65
66
|
netrc.new_item_prefix = "\n# jawbone xid\n"
|
66
|
-
netrc["gitsleep.com"] = xid, "
|
67
|
+
netrc["gitsleep.com"] = xid, "no_password"
|
67
68
|
netrc.save
|
68
69
|
when :"-v"
|
69
70
|
puts "Git Sleep v#{GitSleep::VERSION}"
|
data/hooks/post-commit
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'netrc'
|
5
|
+
require 'git-sleep'
|
6
|
+
require 'httparty'
|
7
|
+
|
8
|
+
netrc = Netrc.read(GitSleep::NETRC_PATH)
|
9
|
+
xid = netrc["gitsleep.com"].first
|
10
|
+
|
11
|
+
raise "Need to `git sleep authorize`" if xid.nil?
|
12
|
+
|
13
|
+
|
14
|
+
begin
|
15
|
+
response = HTTParty.get(
|
16
|
+
"http://www.gitsleep.com/api/need_sleep",
|
17
|
+
:body => {
|
18
|
+
:xid => xid
|
19
|
+
}
|
20
|
+
)
|
21
|
+
rescue Exception => e
|
22
|
+
puts "Can't connect to gitsleep.com"
|
23
|
+
exit 0
|
24
|
+
end
|
25
|
+
|
26
|
+
if response.response.code.to_i == 200
|
27
|
+
data = response.parsed_response
|
28
|
+
|
29
|
+
`git notes --ref=gitsleep add -m "On #{data['sleep24']} hours sleep"`
|
30
|
+
remotes = `git remote`.split("\n")
|
31
|
+
remotes.each do |remote|
|
32
|
+
`git push #{remote} refs/notes/* 2> /dev/null`
|
33
|
+
end
|
34
|
+
|
35
|
+
elsif response.response.code.to_i == 401
|
36
|
+
puts "Must first authorize at #{GitSleep::OUR_SITE}"
|
37
|
+
puts "Then run `git sleep authorize`"
|
38
|
+
else
|
39
|
+
# could not communicate with our server
|
40
|
+
# uh oh!
|
41
|
+
end
|
42
|
+
|
data/hooks/pre-commit
CHANGED
@@ -10,12 +10,19 @@ xid = netrc["gitsleep.com"].first
|
|
10
10
|
|
11
11
|
raise "Need to `git sleep authorize`" if xid.nil?
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
:
|
17
|
-
|
18
|
-
|
13
|
+
begin
|
14
|
+
response = HTTParty.get(
|
15
|
+
"http://www.gitsleep.com/api/need_sleep",
|
16
|
+
:body => {
|
17
|
+
:xid => xid
|
18
|
+
}
|
19
|
+
)
|
20
|
+
rescue Exception => e
|
21
|
+
puts "Can't connect to gitsleep.com"
|
22
|
+
exit 0
|
23
|
+
end
|
24
|
+
|
25
|
+
|
19
26
|
|
20
27
|
if response.response.code.to_i == 200
|
21
28
|
data = response.parsed_response
|
data/lib/git-sleep.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-sleep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-08-
|
14
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- ./README.md
|
59
59
|
- ./git-sleep.gemspec
|
60
60
|
- ./.gitignore
|
61
|
+
- ./hooks/post-commit
|
61
62
|
- ./hooks/pre-commit
|
62
63
|
- ./bin/git-sleep
|
63
64
|
- ./lib/git-sleep.rb
|