gitme_time 0.0.7 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -13,8 +13,11 @@ If you specify a number between square brackets in your commit message, it will
13
13
 
14
14
  # Installation
15
15
 
16
- ```
17
- gem install gitme_time
16
+ Require it inside your project Gemfile:
17
+ ```ruby
18
+ group :development do
19
+ gem 'gitme_time', '~> 0.1.0'
20
+ end
18
21
  ```
19
22
 
20
23
  # Configuration
@@ -33,16 +36,14 @@ Then, inside your project, launch gitme_time init to configure your project:
33
36
  gitme_time init
34
37
  ```
35
38
 
36
- As a final step, add a hook to your git repository:
39
+ This will create the project config file if not exist and will add a git post-commit hook.
40
+ Upon each commit, the hook will send your data to the configured basecamp domain.
37
41
 
38
- ```
39
- cd /path/to/git/project
40
- ln -sf `which gitme_time` ./.git/hooks/post-commit
41
- ```
42
+ Note: remember to add the project config file (.gitme_time.yml) to the git repo, so all your teammates will log the entries inside the same domain/project
42
43
 
43
44
  # TODO
44
45
 
45
- - Specs!
46
+ - Specs! I had no time to write them.
46
47
 
47
48
  # Get ready to contribute!
48
49
 
data/bin/gitme_time CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'rubygems'
2
3
  require 'gitme_time'
3
4
  require 'gitme_time/cli'
4
5
 
@@ -1,66 +1,135 @@
1
1
  module GitmeTime
2
2
  module CLI
3
3
  module InitTutorial
4
- def self.create_project_config_file
5
- if GitmeTime::Config.project_data?
6
- puts "Project config file already exists (#{GitmeTime::Config.project_config_file}). Skipping ..."
7
- else
8
- puts "Generating Project config file ..."
9
- File.open Config.project_config_file, 'w' do |f|
10
- f.write({ 'domain' => get_domain, 'project_id' => get_project }.to_yaml)
4
+ class << self
5
+ def create_project_config_file
6
+ generate_project_config_file
7
+ generate_git_hook
8
+ end
9
+
10
+ def generate_git_hook
11
+ if File.file? Config.project_hook_file
12
+ hook_content = File.open(Config.project_hook_file).read
13
+ if hook_content =~ /GitmeTime/
14
+ version = hook_content.match(/GitmeTime (.+)\.$/)[1]
15
+ if version == GitmeTime::VERSION
16
+ puts 'Git post-commit hook already exists and is updated. Skipping ...'
17
+ else
18
+ File.delete Config.project_hook_file
19
+ write_hook_file
20
+ puts 'Generated an updated Git post-commit hook'
21
+ end
22
+ else
23
+ puts 'Git post-commit hook already exists but it has not been generated by GitmeTime. What I have to do ?'
24
+ option = nil
25
+ while option.nil?
26
+ print '[O]verwrite/[S]kip/Show [C]ontent ? '
27
+ option = STDIN.gets.chomp.downcase
28
+ if option == 'i'
29
+ puts 'Skipping Git post-commit hook generation...'
30
+ break
31
+ elsif option == 'o'
32
+ File.delete Config.project_hook_file
33
+ write_hook_file
34
+ elsif option == 'c'
35
+ puts
36
+ puts hook_content
37
+ puts
38
+ option = nil
39
+ else
40
+ option = nil
41
+ puts 'Invalid Option. Allowed choices are:'
42
+ end
43
+ end
44
+ end
45
+ else
46
+ write_hook_file
47
+ puts 'Generated the Git post-commit hook'
11
48
  end
12
- puts "Project config file generated!"
49
+ puts 'Init Completed!'
13
50
  end
14
- puts "Remember to add the git hook like in the following way:"
15
- puts "\tln -s `which gitme_time` ./.git/hooks/post-commit"
16
- end
17
51
 
18
- private
52
+ def write_hook_file
53
+ File.open Config.project_hook_file, 'w' do |f|
54
+ f.write <<-FILE
55
+ #!/usr/bin/env ruby
56
+ #
57
+ # This file was generated by GitmeTime #{GitmeTime::VERSION}.
58
+ # For more informations, see https://github.com/mikamai/gitme_time
19
59
 
20
- def self.get_project
21
- projects = Basecamp::Project.all
22
- puts "\tChoose a project from one of the following:"
23
- projects.each_with_index do |project, index|
24
- puts "\t\t#{index + 1} - #{project.name}"
25
- end
60
+ require 'pathname'
61
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../Gemfile",
62
+ Pathname.new(__FILE__).realpath)
63
+
64
+ require 'rubygems'
65
+ require 'bundler/setup'
26
66
 
27
- project_id = nil
28
- while project_id.nil?
29
- puts
30
- print "\tProject (e.g. 1): "
31
- project_index = STDIN.gets.chomp
32
- if project_index.empty?
33
- puts "\t\tProject is required!"
34
- project_index = nil
35
- elsif project_index.to_i < 1 || project_index.to_i > projects.length
36
- puts "\t\tA project index between 1 and #{projects.count} is required!"
37
- project_index = nil
67
+ load Gem.bin_path('gitme_time', 'gitme_time')
68
+ FILE
38
69
  end
39
- project_id = projects[project_index.to_i - 1].id if project_index.present?
70
+ File.chmod 0755, Config.project_hook_file
71
+ puts "Git post-commit hook successfully created in #{Config.project_hook_file}"
40
72
  end
41
- project_id.to_i
42
- end
43
73
 
44
- def self.get_domain
45
- domain = nil
46
- while domain.nil?
47
- puts
48
- print "\tBasecamp Domain (e.g. company.basecamphq.com): "
49
- domain = STDIN.gets.chomp
50
- if domain.empty?
51
- puts "\t\tBasecamp Domain is required!"
52
- domain = nil
74
+ def generate_project_config_file
75
+ if GitmeTime::Config.project_data?
76
+ puts "Project config file already exists (#{GitmeTime::Config.project_config_file}). Skipping ..."
53
77
  else
54
- begin
55
- GitmeTime.connect! :domain => domain
56
- Basecamp::Person.me # connection test
57
- rescue SocketError
58
- puts "\t\tCannot connect to https://#{domain} !"
78
+ puts "Generating Project config file ..."
79
+ File.open Config.project_config_file, 'w' do |f|
80
+ f.write({ 'domain' => get_domain, 'project_id' => get_project }.to_yaml)
81
+ end
82
+ puts "Project config file generated!"
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ def get_project
89
+ projects = Basecamp::Project.all
90
+ puts "\tChoose a project from one of the following:"
91
+ projects.each_with_index do |project, index|
92
+ puts "\t\t#{index + 1} - #{project.name}"
93
+ end
94
+
95
+ project_id = nil
96
+ while project_id.nil?
97
+ puts
98
+ print "\tProject (e.g. 1): "
99
+ project_index = STDIN.gets.chomp
100
+ if project_index.empty?
101
+ puts "\t\tProject is required!"
102
+ project_index = nil
103
+ elsif project_index.to_i < 1 || project_index.to_i > projects.length
104
+ puts "\t\tA project index between 1 and #{projects.count} is required!"
105
+ project_index = nil
106
+ end
107
+ project_id = projects[project_index.to_i - 1].id if project_index.present?
108
+ end
109
+ project_id.to_i
110
+ end
111
+
112
+ def get_domain
113
+ domain = nil
114
+ while domain.nil?
115
+ puts
116
+ print "\tBasecamp Domain (e.g. company.basecamphq.com): "
117
+ domain = STDIN.gets.chomp
118
+ if domain.empty?
119
+ puts "\t\tBasecamp Domain is required!"
59
120
  domain = nil
121
+ else
122
+ begin
123
+ GitmeTime.connect! :domain => domain
124
+ Basecamp::Person.me # connection test
125
+ rescue SocketError
126
+ puts "\t\tCannot connect to https://#{domain} !"
127
+ domain = nil
128
+ end
60
129
  end
61
130
  end
131
+ domain
62
132
  end
63
- domain
64
133
  end
65
134
  end
66
135
  end
@@ -35,6 +35,10 @@ module GitmeTime
35
35
  File.join project_directory, '.gitme_time.yml'
36
36
  end
37
37
 
38
+ def project_hook_file
39
+ File.expand_path '../.git/hooks/post-commit', Config.project_config_file
40
+ end
41
+
38
42
  private
39
43
 
40
44
  def project_data
@@ -1,3 +1,3 @@
1
1
  module GitmeTime
2
- VERSION = '0.0.7'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/gitme_time.rb CHANGED
@@ -15,7 +15,7 @@ module GitmeTime
15
15
  message = commit.message
16
16
  hours = 0
17
17
  end
18
- message << " (#{current_branch} : #{commit.sha[0,6]})"
18
+ message << " [#{current_branch} #{commit.sha[0,6]}]"
19
19
  create_entry message, :hours => hours
20
20
  end
21
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitme_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -161,18 +161,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
161
  - - ! '>='
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
- segments:
165
- - 0
166
- hash: -1756184393276805927
167
164
  required_rubygems_version: !ruby/object:Gem::Requirement
168
165
  none: false
169
166
  requirements:
170
167
  - - ! '>='
171
168
  - !ruby/object:Gem::Version
172
169
  version: '0'
173
- segments:
174
- - 0
175
- hash: -1756184393276805927
176
170
  requirements: []
177
171
  rubyforge_project:
178
172
  rubygems_version: 1.8.24