gitreport 0.0.7 → 0.0.8

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.7
1
+ 0.0.8
data/bin/gitreport CHANGED
@@ -5,7 +5,7 @@ require "rubygems"
5
5
  require 'trollop'
6
6
  require "gitreport"
7
7
 
8
- SUB_COMMANDS = %w(activate deactivate commit sync history)
8
+ SUB_COMMANDS = %w(activate deactivate commit sync import)
9
9
 
10
10
  def parse_options
11
11
 
@@ -15,7 +15,7 @@ gitreport is a commandline tool to synchronize your git repo's with gitreport.co
15
15
 
16
16
  Usage: gitreport <subcommand> [options]
17
17
 
18
- <subcommand> must be one of activate, deactivate, commit, sync, history
18
+ <subcommand> must be one of activate, deactivate, commit, sync, import
19
19
 
20
20
  Examples:
21
21
 
@@ -23,7 +23,7 @@ gitreport activate - register your project with gitreport.com
23
23
  gitreport deactivate - unregister your project from gitreport.com
24
24
  gitreport commit - manually transfer your last and stored (offline) commits to gitreport.com
25
25
  gitreport sync - manually transfer stored (offline) commits to gitreport.com
26
- gitreport history - import all the commits of a project to gitreport.com
26
+ gitreport import - import all the commits of a project to gitreport.com
27
27
 
28
28
  gitreport allows the folling [options]:
29
29
  EOS
@@ -48,7 +48,7 @@ gitreport allows the folling [options]:
48
48
  GitReport::Sender.send! :last_and_stored
49
49
  when "sync"
50
50
  GitReport::Sender.send! :stored
51
- when "history"
51
+ when "import"
52
52
  GitReport::BatchSender.send! :history
53
53
  else
54
54
  Trollop::die "unknown subcommand #{cmd.inspect}"
data/gitreport.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gitreport"
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jan Roesner"]
12
- s.date = "2011-10-27"
12
+ s.date = "2011-10-28"
13
13
  s.description = "gitreport keeps track of your projects. It collects info about commited and pushed data, submits it to our servers and provides a gorgous frontend to examine, discover and extract the data that you need to generate the payment recipes for your customers. No longer searching or `what did I commit when and where`..."
14
14
  s.email = "jan@roesner.it"
15
15
  s.executables = ["gitreport"]
@@ -31,6 +31,8 @@ Gem::Specification.new do |s|
31
31
  "lib/commit.rb",
32
32
  "lib/configuration.rb",
33
33
  "lib/current_branch.rb",
34
+ "lib/g_logger.rb",
35
+ "lib/generic_sender.rb",
34
36
  "lib/git.rb",
35
37
  "lib/git/author.rb",
36
38
  "lib/git/base.rb",
@@ -53,7 +55,6 @@ Gem::Specification.new do |s|
53
55
  "lib/history.rb",
54
56
  "lib/hook.rb",
55
57
  "lib/log.rb",
56
- "lib/logger.rb",
57
58
  "lib/project.rb",
58
59
  "lib/sender.rb",
59
60
  "lib/storage.rb",
data/lib/batch_sender.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module GitReport
2
2
 
3
- class BatchSender
3
+ class BatchSender < GenericSender
4
4
 
5
5
  # send the given commits chunked
6
6
  def self.send! option = nil
@@ -36,6 +36,7 @@ module GitReport
36
36
 
37
37
  # sends the commit batch data to the server
38
38
  def self.send_data! batch, options = nil
39
+ grlog(1, 'send_data started')
39
40
  begin
40
41
  response = Net::HTTP.Proxy(configuration.proxy_host, configuration.proxy_port).start(configuration.host, configuration.port) do |http|
41
42
  request = Net::HTTP::Post.new(request_path options)
@@ -45,40 +46,11 @@ module GitReport
45
46
  http.read_timeout = configuration.timeout
46
47
  http.request request unless GitReport.global_opts[:dry_run]
47
48
  end
49
+ grlog(1, response ? "send_data responded with #{response.code}" : "send_data had no response")
48
50
  raise GitReport::ServerError unless (response.code == "200" or response.code == "401") unless GitReport.global_opts[:dry_run]
49
51
  rescue Exception => e
50
- if e.is_a?(GitReport::ServerError)
51
- puts "A server error occured during data transfer."
52
- if GitReport.global_opts[:trace]
53
- puts "Exception: #{e}\n"
54
- puts "Message: #{JSON.parse(response.body)["message"]}\n"
55
- else
56
- puts "Run with --trace to get more info."
57
- end
58
- grlog(0 ,'send_data! - A server error occured during data transfer.')
59
- grlog(0, "send_data! - Exception: #{e}")
60
- grlog(0, "send_data! - Message: #{JSON.parse(response.body)["message"]}") if response
61
- exit
62
- else
63
- puts "A client error occured during data transfer."
64
- if GitReport.global_opts[:trace]
65
- puts "Exception: #{e}\n"
66
- e.backtrace.each do |line|
67
- puts "#{line}\n"
68
- end
69
- else
70
- puts "Run with --trace to get more info."
71
- end
72
- grlog(0, "send_data! - A client error occures during data transfer.")
73
- grlog(0, "send_data! - Exception: #{e}")
74
- grlog(0, "send_data! - Backtrace:")
75
- e.backtrace.each do |line|
76
- grlog(0, line)
77
- end
78
- exit
79
- end
80
-
81
- return false
52
+ communicate e, response
53
+ exit
82
54
  end
83
55
 
84
56
  true
@@ -93,24 +65,11 @@ module GitReport
93
65
  }.to_json
94
66
  end
95
67
 
96
- # returns configuration object
97
- def self.configuration
98
- @@configuration ||= GitReport.configuration
99
- end
100
-
101
68
  # returns the request path
102
69
  def self.request_path options
103
70
  @@path ||= "/v#{configuration.api_version}/projects"
104
71
  end
105
72
 
106
- # returns the default headers
107
- def self.headers request
108
- request['User-Agent'] = 'gitreport-client-ruby'
109
- request['Content-Type'] = 'application/json'
110
- request['Accept'] = 'application/json'
111
- request['X-gitreport-Auth-Token'] = configuration.auth_token
112
- end
113
-
114
73
  end
115
74
 
116
75
  end
data/lib/commit.rb CHANGED
@@ -45,7 +45,7 @@ module GitReport
45
45
 
46
46
  # returns commits stats in more detail
47
47
  def stats
48
- @commit.diff(@commit.parent).stats[:total]
48
+ @commit.parent.diff(@commit).stats[:total]
49
49
  rescue
50
50
  nil
51
51
  end
@@ -1,6 +1,6 @@
1
1
  module GitReport
2
2
 
3
- class Logger
3
+ class GLogger
4
4
 
5
5
  # logs the given message in case the given level is less or equal the configured log level
6
6
  def self.log level, message
@@ -13,7 +13,7 @@ module GitReport
13
13
  # provides method grlog in every class
14
14
  class << self.superclass
15
15
  def grlog level, message
16
- ::GitReport::Logger.log level, Time.now.to_s + " - " + self.to_s + " #" + message
16
+ ::GitReport::GLogger.log level, Time.now.to_s + " - " + self.to_s + " #" + message
17
17
  end
18
18
  end
19
19
 
@@ -0,0 +1,44 @@
1
+ class GenericSender
2
+
3
+ # logs and puts the error according to its conditions and configuration
4
+ # TODO refactor me!
5
+ def self.communicate exception, response
6
+ both, cmd, log = [], [], []
7
+ if exception.is_a?(GitReport::ServerError)
8
+ @error_type = "server error"
9
+ @details = JSON.parse(response.body)["message"] rescue response.body
10
+ else
11
+ @error_type = "client error"
12
+ @details = exception.backtrace
13
+ end
14
+ both << "A #{@error_type} occured during data transfer."
15
+ both << "Exception: #{exception}"
16
+ if GitReport.global_opts[:trace]
17
+ cmd << @details
18
+ else
19
+ cmd << "Run with --trace to get more info."
20
+ end
21
+ log << @details
22
+ puts (both + cmd).join("\n")
23
+ (both + log).each{ |line| grlog(0, "send_data! #{line}")}
24
+ end
25
+
26
+ # returns local storage
27
+ def self.storage
28
+ @@storage ||= GitReport::Storage.new(ENV['HOME'], '.gitreport_storage')
29
+ end
30
+
31
+ # returns configuration object
32
+ def self.configuration
33
+ @@configuration ||= GitReport.configuration
34
+ end
35
+
36
+ # returns the default headers
37
+ def self.headers request
38
+ request['User-Agent'] = 'gitreport-client-ruby'
39
+ request['Content-Type'] = 'application/json'
40
+ request['Accept'] = 'application/json'
41
+ request['X-gitreport-Auth-Token'] = configuration.auth_token
42
+ end
43
+
44
+ end
data/lib/gitreport.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'logger'
1
+ require 'g_logger'
2
2
  require 'git'
3
3
  require 'json'
4
4
  require 'net/http'
@@ -11,6 +11,7 @@ require 'commit'
11
11
  require 'history'
12
12
  require 'configuration'
13
13
  require 'git_configuration'
14
+ require 'generic_sender'
14
15
  require 'sender'
15
16
  require 'batch_sender'
16
17
  require 'storage'
@@ -19,6 +20,8 @@ require 'supplier'
19
20
 
20
21
  module GitReport
21
22
 
23
+ @@global_opts ||= nil
24
+
22
25
  class ServerError < StandardError;end
23
26
 
24
27
  # mattr_reader
data/lib/hook.rb CHANGED
@@ -54,7 +54,7 @@ module GitReport
54
54
 
55
55
  # returns true if the hook file already has a hook line in
56
56
  def self.line_exists?
57
- if file_content.match(/bundle\sexec\sgitreport\scommit\s&/)
57
+ if file_content.match(/nohup\sbundle\sexec\sgitreport\scommit\s>\s\/dev\/null\s2>\s\/dev\/null\s<\s\/dev\/null\s&/)
58
58
  return true
59
59
  end
60
60
 
@@ -76,7 +76,7 @@ module GitReport
76
76
  "#!/bin/sh\n" +
77
77
  "# This is a post-commit hook created by gitreport (http://gitreport.com)\n" +
78
78
  "#\n" +
79
- "# To remove it issue 'bundle exec unregister' in the projects main directory\n" +
79
+ "# To remove it issue 'bundle exec deactivate' in the projects main directory\n" +
80
80
  "# In case the gitreport gem is not installed anymore, simply remove this hook file\n" +
81
81
  "#\n" +
82
82
  "# Be aware of other post commit hooks that my be mentioned here!\n"
@@ -84,7 +84,7 @@ module GitReport
84
84
 
85
85
  # returns the line to activate gitreport via post commit hook
86
86
  def self.line
87
- "\nbundle exec gitreport commit &\n"
87
+ "\nnohup bundle exec gitreport commit > /dev/null 2> /dev/null < /dev/null &\n"
88
88
  end
89
89
 
90
90
  # removes the hook
@@ -105,7 +105,7 @@ module GitReport
105
105
 
106
106
  # returns true if the hook file is ours and was not changed
107
107
  def self.hook_file_unchanged?
108
- Digest::SHA1.hexdigest(file_content) == "9c69e61ce35b8ce21968343411e6abeb89b237dd"
108
+ Digest::SHA1.hexdigest(file_content) == "e4032a91bb8e07e09ea637c803d8763e26e165e7"
109
109
  end
110
110
 
111
111
  # removes our hook line from hook file
@@ -115,7 +115,7 @@ module GitReport
115
115
 
116
116
  # removes our hook line from given content
117
117
  def self.clean_up content
118
- content.gsub(/\nbundle\sexec\sgitreport\scommit\s&\n/,'')
118
+ content.gsub(/\nnohup\sbundle\sexec\sgitreport\scommit\s>\s\/dev\/null\s2>\s\/dev\/null\s<\s\/dev\/null\s&\n/,'')
119
119
  end
120
120
 
121
121
  end
data/lib/sender.rb CHANGED
@@ -1,27 +1,13 @@
1
1
  module GitReport
2
2
 
3
- class Sender
3
+ class Sender < GenericSender
4
4
 
5
5
  # sends or saves the commits
6
6
  def self.send! options = nil
7
7
  begin
8
8
  commits = GitReport::Supplier.commits(options)
9
9
  rescue Exception => e
10
- puts "A client error occured during data transfer."
11
- if GitReport.global_opts[:trace]
12
- puts "Exception: #{e}\n"
13
- e.backtrace.each do |line|
14
- puts "#{line}\n"
15
- end
16
- else
17
- puts "Run with --trace to get more info."
18
- end
19
- grlog(0, "send! - A client error occures during data transfer.")
20
- grlog(0, "send! - Exception: #{e}")
21
- grlog(0, "send! - Backtrace:")
22
- e.backtrace.each do |line|
23
- grlog(0, line)
24
- end
10
+ communicate e, nil
25
11
  exit
26
12
  end
27
13
 
@@ -37,6 +23,7 @@ module GitReport
37
23
 
38
24
  # sends the commit data to the server
39
25
  def self.send_data! commit, options = nil
26
+ grlog(1, 'send_data started')
40
27
  begin
41
28
  response = Net::HTTP.Proxy(configuration.proxy_host, configuration.proxy_port).start(configuration.host, configuration.port) do |http|
42
29
  request = Net::HTTP::Post.new(request_path options)
@@ -46,53 +33,21 @@ module GitReport
46
33
  http.read_timeout = configuration.timeout
47
34
  http.request request unless GitReport.global_opts[:dry_run]
48
35
  end
36
+ grlog(1, response ? "send_data responded with #{response.code}" : "send_data had no response")
49
37
  raise GitReport::ServerError unless (response.code == "201" or response.code == "401") unless GitReport.global_opts[:dry_run]
50
38
  rescue Exception => e
51
- if e.is_a?(GitReport::ServerError)
52
- puts "A server error occured during data transfer."
53
- if GitReport.global_opts[:trace]
54
- puts "Exception: #{e}\n"
55
- puts "Message: #{JSON.parse(response.body)["message"]}\n"
56
- else
57
- puts "Run with --trace to get more info."
58
- end
59
- else
60
- puts "A client error occured during data transfer."
61
- puts "Exception: #{e}\n"
62
- end
63
- grlog(0 ,'send_data! - A server error occured during data transfer.')
64
- grlog(0, "send_data! - Exception: #{e}")
65
- grlog(0, "send_data! - Message: #{JSON.parse(response.body)["message"]}") if response
66
-
39
+ communicate e, response
67
40
  return false
68
41
  end
69
42
 
70
43
  true
71
44
  end
72
45
 
73
- # returns local storage
74
- def self.storage
75
- @@storage ||= GitReport::Storage.new(ENV['HOME'], '.gitreport_storage')
76
- end
77
-
78
- # returns configuration object
79
- def self.configuration
80
- @@configuration ||= GitReport.configuration
81
- end
82
-
83
46
  # returns the request path
84
47
  def self.request_path options
85
48
  @@path ||= "/v#{configuration.api_version}/commits"
86
49
  end
87
50
 
88
- # returns the default headers
89
- def self.headers request
90
- request['User-Agent'] = 'gitreport-client-ruby'
91
- request['Content-Type'] = 'application/json'
92
- request['Accept'] = 'application/json'
93
- request['X-gitreport-Auth-Token'] = configuration.auth_token
94
- end
95
-
96
51
  end
97
52
 
98
53
  end
@@ -45,10 +45,10 @@ describe 'GitReport::Commit' do
45
45
  describe '#stats' do
46
46
  it 'should return the commit stats' do
47
47
  stats = GitReport::Commit.new(@project.log.commits.first, @project.identifier).stats
48
- stats[:deletions].should == 1
48
+ stats[:deletions].should == 0
49
49
  stats[:files].should == 1
50
50
  stats[:lines].should == 1
51
- stats[:insertions].should == 0
51
+ stats[:insertions].should == 1
52
52
  end
53
53
  end
54
54
 
@@ -18,7 +18,7 @@ describe 'GitReport::Hook' do
18
18
  (File.exists?(hook_file)).should be_true
19
19
  content = File.open(hook_file, 'r').read
20
20
 
21
- content.match(/\nbundle\sexec\sgitreport\scommit\s&\n/).should be_true
21
+ content.match(/\nnohup\sbundle\sexec\sgitreport\scommit\s>\s\/dev\/null\s2>\s\/dev\/null\s<\s\/dev\/null\s&\n/).should be_true
22
22
  end
23
23
 
24
24
  it 'should insert the gitreport hook into an existing post-commit hook file' do
@@ -30,7 +30,7 @@ describe 'GitReport::Hook' do
30
30
 
31
31
  GitReport::Hook.set!
32
32
  content = File.open(hook_file, 'r').read
33
- content.match(/\nbundle\sexec\sgitreport\scommit\s&\n/).should be_true
33
+ content.match(/\nnohup\sbundle\sexec\sgitreport\scommit\s>\s\/dev\/null\s2>\s\/dev\/null\s<\s\/dev\/null\s&\n/).should be_true
34
34
  end
35
35
  end
36
36
 
@@ -57,7 +57,7 @@ describe 'GitReport::Hook' do
57
57
  (File.exists?(hook_file)).should be_true
58
58
  content = File.open(hook_file, 'r').read
59
59
  content.should match(/\ssome\spreexisting\shook\sfile\n/)
60
- content.should_not match(/\nbundle\sexec\sgitreport\scommit\s&\n/)
60
+ content.should_not match(/\nnohup\sbundle\sexec\sgitreport\scommit\s>\s\/dev\/null\s2>\s\/dev\/null\s<\s\/dev\/null\s&\n/)
61
61
  end
62
62
  end
63
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitreport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-27 00:00:00.000000000Z
12
+ date: 2011-10-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70138129848900 !ruby/object:Gem::Requirement
16
+ requirement: &70284346535700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70138129848900
24
+ version_requirements: *70284346535700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: spork
27
- requirement: &70138129848420 !ruby/object:Gem::Requirement
27
+ requirement: &70284346531340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>'
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.9.0.rc
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70138129848420
35
+ version_requirements: *70284346531340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70138129847940 !ruby/object:Gem::Requirement
38
+ requirement: &70284346525880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70138129847940
46
+ version_requirements: *70284346525880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: webmock
49
- requirement: &70138129847460 !ruby/object:Gem::Requirement
49
+ requirement: &70284346521540 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70138129847460
57
+ version_requirements: *70284346521540
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: shoulda
60
- requirement: &70138129846980 !ruby/object:Gem::Requirement
60
+ requirement: &70284346518300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70138129846980
68
+ version_requirements: *70284346518300
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
- requirement: &70138129863620 !ruby/object:Gem::Requirement
71
+ requirement: &70284346514400 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70138129863620
79
+ version_requirements: *70284346514400
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &70138129863140 !ruby/object:Gem::Requirement
82
+ requirement: &70284346510280 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.6.4
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70138129863140
90
+ version_requirements: *70284346510280
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rcov
93
- requirement: &70138129862660 !ruby/object:Gem::Requirement
93
+ requirement: &70284346504540 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70138129862660
101
+ version_requirements: *70284346504540
102
102
  description: gitreport keeps track of your projects. It collects info about commited
103
103
  and pushed data, submits it to our servers and provides a gorgous frontend to examine,
104
104
  discover and extract the data that you need to generate the payment recipes for
@@ -124,6 +124,8 @@ files:
124
124
  - lib/commit.rb
125
125
  - lib/configuration.rb
126
126
  - lib/current_branch.rb
127
+ - lib/g_logger.rb
128
+ - lib/generic_sender.rb
127
129
  - lib/git.rb
128
130
  - lib/git/author.rb
129
131
  - lib/git/base.rb
@@ -146,7 +148,6 @@ files:
146
148
  - lib/history.rb
147
149
  - lib/hook.rb
148
150
  - lib/log.rb
149
- - lib/logger.rb
150
151
  - lib/project.rb
151
152
  - lib/sender.rb
152
153
  - lib/storage.rb
@@ -182,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
183
  version: '0'
183
184
  segments:
184
185
  - 0
185
- hash: -2322616335107185957
186
+ hash: 3923250588470254802
186
187
  required_rubygems_version: !ruby/object:Gem::Requirement
187
188
  none: false
188
189
  requirements: