happy-commit 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.1.0
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__)+"/../lib"
4
+
5
+ require 'happy-commit'
6
+
7
+ HappyCommit.on_commit
data/happy-commit.gemspec CHANGED
@@ -5,15 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{happy-commit}
8
- s.version = "0.0.4"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David A. Cuadrado"]
12
- s.date = %q{2010-09-05}
13
- s.default_executable = %q{happy-commit}
12
+ s.date = %q{2010-09-28}
14
13
  s.description = %q{happy commits!}
15
14
  s.email = %q{krawek@gmail.com}
16
- s.executables = ["happy-commit"]
15
+ s.executables = ["happy-commit-stats", "happy-commit"]
17
16
  s.extra_rdoc_files = [
18
17
  "LICENSE",
19
18
  "README.rdoc"
@@ -26,8 +25,11 @@ Gem::Specification.new do |s|
26
25
  "Rakefile",
27
26
  "VERSION",
28
27
  "bin/happy-commit",
28
+ "bin/happy-commit-stats",
29
29
  "happy-commit.gemspec",
30
30
  "lib/happy-commit.rb",
31
+ "lib/happy-commit/hook.rb",
32
+ "lib/happy-commit/on_commit.rb",
31
33
  "sounds/070-who2.wav",
32
34
  "sounds/Engineer_cheers01.wav",
33
35
  "sounds/Engineer_cheers02.wav",
data/lib/happy-commit.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'fileutils'
2
+ require 'happy-commit/on_commit'
2
3
 
3
4
  module HappyCommit
5
+ include HappyCommit::OnCommit
6
+
4
7
  def self.sounds
5
8
  @sounds ||= Dir.glob(File.dirname(__FILE__)+"/../sounds/*.wav")
6
9
  end
@@ -13,11 +16,7 @@ module HappyCommit
13
16
  end
14
17
 
15
18
  File.open(self.post_commit_path, "w") do |f|
16
- f << %@#!/usr/bin/env ruby
17
- sounds = Dir.glob(".git/sounds/*.wav")
18
- command = %w[aplay afplay play].find { |w| `#\{w} --version 2>/dev/null`; $?.success? }
19
- system("#\{command} #\{sounds.at(rand(sounds.size))} 2>/dev/null &")
20
- @
19
+ f << File.read(File.expand_path("../happy-commit/hook.rb", __FILE__))
21
20
  end
22
21
  FileUtils.chmod(0755, self.post_commit_path)
23
22
  end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ git_dir = File.expand_path("../../", __FILE__)
4
+
5
+ sounds = Dir.glob("#{git_dir}/sounds/*.wav")
6
+ command = %w[aplay afplay play].find { |w| `#\{w} --version 2>/dev/null`; $?.success? }
7
+ sound = sounds.at(rand(sounds.size))
8
+ system("#{command} #{sound} 2>/dev/null &")
9
+
10
+ system("happy-commit-stats")
@@ -0,0 +1,73 @@
1
+ module HappyCommit
2
+ module OnCommit
3
+ def self.included(base)
4
+ base.class_eval do
5
+ base.extend ClassMethods
6
+ end
7
+ end
8
+
9
+ module ClassMethods
10
+ def on_commit
11
+ order, commits = self.commits
12
+ pos = order.index(current_name)+1
13
+
14
+ if pos == 1
15
+ puts ">> Congrats!! you are the most committer of all time with #{commits[current_name]} commits!"
16
+ elsif pos == 2
17
+ puts ">> You need #{commits[order.first] - commits[current_name]} commits to reach #{order.first}(the champion)"
18
+ end
19
+
20
+ order, commits = self.commits_today
21
+ pos = order.index(current_name)+1
22
+ if pos == 1
23
+ puts ">> Congrats!! you are the most committer today with #{commits[current_name]} commits!"
24
+ elsif pos == 2
25
+ puts ">> You need #{commits[order.first] - commits[current_name]} commits to reach #{order.first}(the champion)"
26
+ elsif pos
27
+ puts ">> You have committed #{commits[current_name]} times today, congrats!"
28
+ end
29
+ end
30
+
31
+ def current_name
32
+ @current_name||=`git config user.name`.strip
33
+ end
34
+
35
+ def commits
36
+ commits = {}
37
+ order = []
38
+ count = 0
39
+ `git shortlog -s -n -m HEAD`.each_line do |line|
40
+ if line =~ /\s+(\d+)\s+(.+)$/
41
+ name = $2.strip
42
+ commits[name] = $1.to_i
43
+ order << name
44
+ count += 1
45
+
46
+ break if count >= 5
47
+ end
48
+ end
49
+
50
+ [order, commits]
51
+ end
52
+
53
+ def commits_today
54
+ hours = Time.now.strftime("%k").to_i-5
55
+ order = []
56
+ count = 0
57
+ commits = {}
58
+ `git shortlog -s -n -m --since="#{hours} hours ago" HEAD`.each_line do |line|
59
+ if line =~ /\s+(\d+)\s+(.+)$/
60
+ name = $2.strip
61
+ commits[name] = $1.to_i
62
+ order << name
63
+ count += 1
64
+
65
+ break if count >= 5
66
+ end
67
+ end
68
+
69
+ [order, commits]
70
+ end
71
+ end
72
+ end
73
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happy-commit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 4
10
- version: 0.0.4
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David A. Cuadrado
@@ -15,8 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-05 00:00:00 -05:00
19
- default_executable: happy-commit
18
+ date: 2010-09-28 00:00:00 -05:00
19
+ default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: thoughtbot-shoulda
@@ -35,6 +35,7 @@ dependencies:
35
35
  description: happy commits!
36
36
  email: krawek@gmail.com
37
37
  executables:
38
+ - happy-commit-stats
38
39
  - happy-commit
39
40
  extensions: []
40
41
 
@@ -49,8 +50,11 @@ files:
49
50
  - Rakefile
50
51
  - VERSION
51
52
  - bin/happy-commit
53
+ - bin/happy-commit-stats
52
54
  - happy-commit.gemspec
53
55
  - lib/happy-commit.rb
56
+ - lib/happy-commit/hook.rb
57
+ - lib/happy-commit/on_commit.rb
54
58
  - sounds/070-who2.wav
55
59
  - sounds/Engineer_cheers01.wav
56
60
  - sounds/Engineer_cheers02.wav