gitreport 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +49 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/gitreport +56 -0
- data/gitreport.gemspec +102 -0
- data/lib/batch_sender.rb +86 -0
- data/lib/commit.rb +86 -0
- data/lib/configuration.rb +68 -0
- data/lib/current_branch.rb +24 -0
- data/lib/git_configuration.rb +14 -0
- data/lib/gitreport.rb +30 -0
- data/lib/history.rb +44 -0
- data/lib/hook.rb +122 -0
- data/lib/log.rb +26 -0
- data/lib/project.rb +70 -0
- data/lib/sender.rb +63 -0
- data/lib/storage.rb +27 -0
- data/lib/supplier.rb +53 -0
- data/lib/trollop.rb +783 -0
- data/spec/gitreport_spec.rb +1 -0
- data/spec/models/batch_sender_spec.rb +37 -0
- data/spec/models/commit_spec.rb +87 -0
- data/spec/models/configuration_spec.rb +69 -0
- data/spec/models/current_branch_spec.rb +22 -0
- data/spec/models/git_configuration_spec.rb +26 -0
- data/spec/models/history_spec.rb +50 -0
- data/spec/models/hook_spec.rb +64 -0
- data/spec/models/log_spec.rb +47 -0
- data/spec/models/project_spec.rb +93 -0
- data/spec/models/sender_spec.rb +75 -0
- data/spec/models/storage_spec.rb +53 -0
- data/spec/models/supplier_spec.rb +20 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/fake_repository.rb +83 -0
- metadata +234 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'json'
|
4
|
+
gem 'git', '~>1.2.5'
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem 'ruby-debug'
|
8
|
+
# gem 'ruby-debug19'
|
9
|
+
gem 'rspec'
|
10
|
+
gem 'webmock'
|
11
|
+
gem "shoulda", ">= 0"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.6.4"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.6)
|
5
|
+
columnize (0.3.4)
|
6
|
+
crack (0.3.1)
|
7
|
+
diff-lcs (1.1.3)
|
8
|
+
git (1.2.5)
|
9
|
+
jeweler (1.6.4)
|
10
|
+
bundler (~> 1.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
json (1.6.1)
|
14
|
+
linecache (0.46)
|
15
|
+
rbx-require-relative (> 0.0.4)
|
16
|
+
rake (0.9.2)
|
17
|
+
rbx-require-relative (0.0.5)
|
18
|
+
rcov (0.9.10)
|
19
|
+
rspec (2.6.0)
|
20
|
+
rspec-core (~> 2.6.0)
|
21
|
+
rspec-expectations (~> 2.6.0)
|
22
|
+
rspec-mocks (~> 2.6.0)
|
23
|
+
rspec-core (2.6.4)
|
24
|
+
rspec-expectations (2.6.0)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
rspec-mocks (2.6.0)
|
27
|
+
ruby-debug (0.10.4)
|
28
|
+
columnize (>= 0.1)
|
29
|
+
ruby-debug-base (~> 0.10.4.0)
|
30
|
+
ruby-debug-base (0.10.4)
|
31
|
+
linecache (>= 0.3)
|
32
|
+
shoulda (2.11.3)
|
33
|
+
webmock (1.7.6)
|
34
|
+
addressable (~> 2.2, > 2.2.5)
|
35
|
+
crack (>= 0.1.7)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bundler (~> 1.0.0)
|
42
|
+
git (~> 1.2.5)
|
43
|
+
jeweler (~> 1.6.4)
|
44
|
+
json
|
45
|
+
rcov
|
46
|
+
rspec
|
47
|
+
ruby-debug
|
48
|
+
shoulda
|
49
|
+
webmock
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jan Roesner
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= gitreport
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to gitreport
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Jan Roesner. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "gitreport"
|
18
|
+
gem.homepage = "http://github.com/janroesner/gitreport"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{gitreport tracks commit and push info of your git projects}
|
21
|
+
gem.description = %Q{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`...}
|
22
|
+
gem.email = "jan@roesner.it"
|
23
|
+
gem.authors = ["Jan Roesner"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "gitreport #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/gitreport
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
require "rubygems"
|
5
|
+
require 'trollop'
|
6
|
+
require "gitreport"
|
7
|
+
|
8
|
+
SUB_COMMANDS = %w(activate deactivate commit sync history)
|
9
|
+
|
10
|
+
def parse_options
|
11
|
+
|
12
|
+
global_opts = Trollop::options do
|
13
|
+
banner <<-EOS
|
14
|
+
gitreport is a commandline tool to synchronize your git repo's with gitreport.com
|
15
|
+
|
16
|
+
Usage: gitreport <subcommand> [options]
|
17
|
+
|
18
|
+
<subcommand> must be one of activate, deactivate, commit, sync, history
|
19
|
+
|
20
|
+
Examples:
|
21
|
+
|
22
|
+
gitreport activate - register your project with gitreport.com
|
23
|
+
gitreport deactivate - unregister your project from gitreport.com
|
24
|
+
gitreport commit - manually transfer your last and stored (offline) commits to gitreport.com
|
25
|
+
gitreport sync - manually transfer stored (offline) commits to gitreport.com
|
26
|
+
gitreport history - import all the commits of a project to gitreport.com
|
27
|
+
|
28
|
+
gitreport allows the folling [options]:
|
29
|
+
EOS
|
30
|
+
|
31
|
+
opt :dry_run, "Don't actually do anything", :short => "-n"
|
32
|
+
stop_on SUB_COMMANDS
|
33
|
+
end
|
34
|
+
|
35
|
+
cmd = ARGV.shift
|
36
|
+
Trollop::die "You must specify at least one command" unless cmd
|
37
|
+
|
38
|
+
cmd_opts =
|
39
|
+
case cmd
|
40
|
+
when "activate"
|
41
|
+
GitReport::Hook.set!
|
42
|
+
when "deactivate"
|
43
|
+
GitReport::Hook.remove!
|
44
|
+
when "commit"
|
45
|
+
GitReport::Sender.send! :last_and_stored
|
46
|
+
when "sync"
|
47
|
+
GitReport::Sender.send! :stored
|
48
|
+
when "history"
|
49
|
+
GitReport::BatchSender.send! :history
|
50
|
+
else
|
51
|
+
Trollop::die "unknown subcommand #{cmd.inspect}"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
parse_options
|
data/gitreport.gemspec
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "gitreport"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jan Roesner"]
|
12
|
+
s.date = "2011-10-02"
|
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
|
+
s.email = "jan@roesner.it"
|
15
|
+
s.executables = ["gitreport"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/gitreport",
|
29
|
+
"gitreport.gemspec",
|
30
|
+
"lib/batch_sender.rb",
|
31
|
+
"lib/commit.rb",
|
32
|
+
"lib/configuration.rb",
|
33
|
+
"lib/current_branch.rb",
|
34
|
+
"lib/git_configuration.rb",
|
35
|
+
"lib/gitreport.rb",
|
36
|
+
"lib/history.rb",
|
37
|
+
"lib/hook.rb",
|
38
|
+
"lib/log.rb",
|
39
|
+
"lib/project.rb",
|
40
|
+
"lib/sender.rb",
|
41
|
+
"lib/storage.rb",
|
42
|
+
"lib/supplier.rb",
|
43
|
+
"lib/trollop.rb",
|
44
|
+
"spec/gitreport_spec.rb",
|
45
|
+
"spec/models/batch_sender_spec.rb",
|
46
|
+
"spec/models/commit_spec.rb",
|
47
|
+
"spec/models/configuration_spec.rb",
|
48
|
+
"spec/models/current_branch_spec.rb",
|
49
|
+
"spec/models/git_configuration_spec.rb",
|
50
|
+
"spec/models/history_spec.rb",
|
51
|
+
"spec/models/hook_spec.rb",
|
52
|
+
"spec/models/log_spec.rb",
|
53
|
+
"spec/models/project_spec.rb",
|
54
|
+
"spec/models/sender_spec.rb",
|
55
|
+
"spec/models/storage_spec.rb",
|
56
|
+
"spec/models/supplier_spec.rb",
|
57
|
+
"spec/spec_helper.rb",
|
58
|
+
"spec/support/fake_repository.rb"
|
59
|
+
]
|
60
|
+
s.homepage = "http://github.com/janroesner/gitreport"
|
61
|
+
s.licenses = ["MIT"]
|
62
|
+
s.require_paths = ["lib"]
|
63
|
+
s.rubygems_version = "1.8.10"
|
64
|
+
s.summary = "gitreport tracks commit and push info of your git projects"
|
65
|
+
|
66
|
+
if s.respond_to? :specification_version then
|
67
|
+
s.specification_version = 3
|
68
|
+
|
69
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
70
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
71
|
+
s.add_runtime_dependency(%q<git>, ["~> 1.2.5"])
|
72
|
+
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
73
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
74
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
75
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
76
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
78
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
79
|
+
else
|
80
|
+
s.add_dependency(%q<json>, [">= 0"])
|
81
|
+
s.add_dependency(%q<git>, ["~> 1.2.5"])
|
82
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
83
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
84
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
85
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
86
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
87
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
88
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
89
|
+
end
|
90
|
+
else
|
91
|
+
s.add_dependency(%q<json>, [">= 0"])
|
92
|
+
s.add_dependency(%q<git>, ["~> 1.2.5"])
|
93
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
94
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
95
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
96
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
97
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
98
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
99
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
data/lib/batch_sender.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module GitReport
|
2
|
+
|
3
|
+
class BatchSender
|
4
|
+
|
5
|
+
# send the given commits chunked
|
6
|
+
def self.send! option = nil
|
7
|
+
puts "Collecting your projects commit data - this can take some time, please be patient!"
|
8
|
+
batches(option).each_with_index do |batch, index|
|
9
|
+
print "Sending batch #{index + 1} of #{@@num_batches} - #{index*100/@@num_batches}%\r"
|
10
|
+
STDOUT.flush
|
11
|
+
break unless send_data!(batch)
|
12
|
+
end
|
13
|
+
print "Sending batch #{@@num_batches} of #{@@num_batches} - 100%\r"
|
14
|
+
STDOUT.flush
|
15
|
+
print "\n"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# returns batches of commits with the batchsize taken from configuration
|
21
|
+
def self.batches option
|
22
|
+
raise "Nothing to create batches from" unless option
|
23
|
+
commits = GitReport::Supplier.commits(option)
|
24
|
+
batchsize = GitReport.configuration.batchsize
|
25
|
+
|
26
|
+
batches = []
|
27
|
+
divider = commits.size.divmod(batchsize).first
|
28
|
+
|
29
|
+
1.upto(divider+1) do |n|
|
30
|
+
batches << commits[(n-1)*batchsize..n*batchsize-1]
|
31
|
+
end
|
32
|
+
|
33
|
+
@@num_batches = batches.size
|
34
|
+
batches
|
35
|
+
end
|
36
|
+
|
37
|
+
# sends the commit batch data to the server
|
38
|
+
def self.send_data! batch, options = nil
|
39
|
+
begin
|
40
|
+
response = Net::HTTP.Proxy(configuration.proxy_host, configuration.proxy_port).start(configuration.host, configuration.port) do |http|
|
41
|
+
request = Net::HTTP::Post.new(request_path options)
|
42
|
+
headers request
|
43
|
+
request.body = body(batch)
|
44
|
+
http.open_timeout = configuration.timeout
|
45
|
+
http.read_timeout = configuration.timeout
|
46
|
+
http.request request
|
47
|
+
end
|
48
|
+
raise StandardError unless (response.code == "200" or response.code == "401")
|
49
|
+
rescue Exception => e
|
50
|
+
puts "Error during sending the commit batch: #{e}"
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
57
|
+
# returns the body as an aggregate of author, project and commit data
|
58
|
+
def self.body batch
|
59
|
+
{
|
60
|
+
:commits => batch.map(&:batch_data),
|
61
|
+
:author => GitReport::GitConfiguration.user_name,
|
62
|
+
:project => GitReport.project.data
|
63
|
+
}.to_json
|
64
|
+
end
|
65
|
+
|
66
|
+
# returns configuration object
|
67
|
+
def self.configuration
|
68
|
+
@@configuration ||= GitReport.configuration
|
69
|
+
end
|
70
|
+
|
71
|
+
# returns the request path
|
72
|
+
def self.request_path options
|
73
|
+
@@path ||= "/v#{configuration.api_version}/projects"
|
74
|
+
end
|
75
|
+
|
76
|
+
# returns the default headers
|
77
|
+
def self.headers request
|
78
|
+
request['User-Agent'] = 'gitreport-client-ruby'
|
79
|
+
request['Content-Type'] = 'application/json'
|
80
|
+
request['Accept'] = 'application/json'
|
81
|
+
request['X-gitreport-Auth-Token'] = configuration.auth_token
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
data/lib/commit.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module GitReport
|
2
|
+
|
3
|
+
class Commit
|
4
|
+
|
5
|
+
attr_accessor :commit, :project_identifier
|
6
|
+
|
7
|
+
def initialize commit = nil, project_identifier = nil
|
8
|
+
@project = GitReport.project
|
9
|
+
@commit = commit
|
10
|
+
@project_identifier = project_identifier
|
11
|
+
end
|
12
|
+
|
13
|
+
# returns the commit hash of self
|
14
|
+
def sha
|
15
|
+
self.commit.sha
|
16
|
+
end
|
17
|
+
|
18
|
+
# returns the short version of the commit hash of self
|
19
|
+
def short_sha
|
20
|
+
self.sha[0..6]
|
21
|
+
end
|
22
|
+
|
23
|
+
# returns the commit message of self
|
24
|
+
def message
|
25
|
+
self.commit.message
|
26
|
+
end
|
27
|
+
|
28
|
+
# returns the time when self was committed
|
29
|
+
def time
|
30
|
+
Time.parse(self.commit.author.date.to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
# returns a struct containing author information name and email of that commit
|
34
|
+
def author
|
35
|
+
author = OpenStruct.new
|
36
|
+
author.name = self.commit.author.name
|
37
|
+
author.email = self.commit.author.email
|
38
|
+
author
|
39
|
+
end
|
40
|
+
|
41
|
+
# returns commits stats in more detail
|
42
|
+
def stats
|
43
|
+
# TODO
|
44
|
+
end
|
45
|
+
|
46
|
+
# return the commits aggregated data in case a single commit is transferred
|
47
|
+
def data
|
48
|
+
@data ||= aggregate(:single)
|
49
|
+
end
|
50
|
+
|
51
|
+
def batch_data
|
52
|
+
@data ||= aggregate(:batch)
|
53
|
+
end
|
54
|
+
|
55
|
+
# return the commits aggregated data as JSON
|
56
|
+
def to_json
|
57
|
+
data.to_json
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# aggregates all the data that needs to be transfered to the server
|
63
|
+
def aggregate scope
|
64
|
+
# TODO fucking slow
|
65
|
+
data = {}
|
66
|
+
data[:sha] = self.sha
|
67
|
+
data[:short_sha] = self.short_sha
|
68
|
+
data[:author_name] = self.author.name
|
69
|
+
data[:author_email] = self.author.email
|
70
|
+
data[:time] = self.time.xmlschema
|
71
|
+
data[:message] = self.message
|
72
|
+
data[:project_name] = @project.name
|
73
|
+
if scope == :single
|
74
|
+
data[:project_identifier] = self.project_identifier
|
75
|
+
data[:project_path] = @project.path
|
76
|
+
data[:current_branch] = @project.branchname
|
77
|
+
data[:remotes] = @project.remotes.map(&:name)
|
78
|
+
data[:remote_urls] = @project.remotes.map(&:url)
|
79
|
+
data[:remote_branches] = @project.remote_branches
|
80
|
+
end
|
81
|
+
data
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module GitReport
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@project = GitReport.project
|
7
|
+
read_configuration or set_default_configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
# sets the given configuration
|
11
|
+
def set_configuration config_data
|
12
|
+
default_configuration.merge!(config_data).each_pair do |key, value|
|
13
|
+
self.class.send(:attr_accessor, key)
|
14
|
+
self.send(:"#{key}=", value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# reads project- or user configuration and sets it
|
21
|
+
def read_configuration
|
22
|
+
begin
|
23
|
+
if project_configuration_file_exists?
|
24
|
+
set_configuration YAML.load_file(project_configuration_file)
|
25
|
+
else
|
26
|
+
set_configuration YAML.load_file(user_configuration_file)
|
27
|
+
end
|
28
|
+
rescue
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# returns the default configuration
|
34
|
+
def default_configuration
|
35
|
+
{
|
36
|
+
"host" => "api.gitreport.com",
|
37
|
+
"port" => 80,
|
38
|
+
"proxy_host" => nil,
|
39
|
+
"proxy_port" => nil,
|
40
|
+
"auth_token" => "is_unset_check_your_config",
|
41
|
+
"api_version" => 1,
|
42
|
+
"timeout" => 5,
|
43
|
+
"batchsize" => 100
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# sets the default configuration
|
48
|
+
def set_default_configuration
|
49
|
+
set_configuration default_configuration
|
50
|
+
end
|
51
|
+
|
52
|
+
# returns true if a config file exists for the recent project
|
53
|
+
def project_configuration_file_exists?
|
54
|
+
File.exists? project_configuration_file
|
55
|
+
end
|
56
|
+
|
57
|
+
# returns the project configuration file in case there is any
|
58
|
+
def project_configuration_file
|
59
|
+
File.join(@project.path, '.gitreport')
|
60
|
+
end
|
61
|
+
|
62
|
+
# returns the users configuration file in case there is any
|
63
|
+
def user_configuration_file
|
64
|
+
File.join(ENV['HOME'], '.gitreport')
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module GitReport
|
2
|
+
class CurrentBranch
|
3
|
+
attr_accessor :project, :branch
|
4
|
+
|
5
|
+
def initialize project = nil
|
6
|
+
raise "No git repo found" unless project
|
7
|
+
@project = project
|
8
|
+
@branch = project.branch
|
9
|
+
end
|
10
|
+
|
11
|
+
# returns the name of the currently checked out branch
|
12
|
+
def name
|
13
|
+
@project.branches.select{|b| b.current}.first.full rescue alt_name
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# alternative method to return the current branches name
|
19
|
+
def alt_name
|
20
|
+
name = `git branch`.split("\n").select{|b| b.match(/^\*/)}.first.match(/^\*(.*)$/)
|
21
|
+
return $1.strip
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GitReport
|
2
|
+
class GitConfiguration
|
3
|
+
|
4
|
+
# returns the current users name from git config
|
5
|
+
def self.user_name
|
6
|
+
@@username ||= GitReport.project.project.config('user.name')
|
7
|
+
end
|
8
|
+
|
9
|
+
# returns the current users email from git config
|
10
|
+
def self.user_email
|
11
|
+
@@useremail ||= GitReport.project.project.config('user.email')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/gitreport.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'git'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
require 'time'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'project'
|
7
|
+
require 'current_branch'
|
8
|
+
require 'log'
|
9
|
+
require 'commit'
|
10
|
+
require 'history'
|
11
|
+
require 'configuration'
|
12
|
+
require 'git_configuration'
|
13
|
+
require 'sender'
|
14
|
+
require 'batch_sender'
|
15
|
+
require 'storage'
|
16
|
+
require 'hook'
|
17
|
+
require 'supplier'
|
18
|
+
|
19
|
+
module GitReport
|
20
|
+
|
21
|
+
# mattr_reader
|
22
|
+
def self.project
|
23
|
+
@@project ||= GitReport::Project.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configuration
|
27
|
+
@@config ||= GitReport::Configuration.new
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/history.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module GitReport
|
2
|
+
|
3
|
+
class History
|
4
|
+
|
5
|
+
# returns the histories commits depending on the scope :user or :all
|
6
|
+
def self.commits scope = :user
|
7
|
+
case scope
|
8
|
+
when :user
|
9
|
+
self.user_commits
|
10
|
+
else
|
11
|
+
self.all_commits
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# returns all commits of this project
|
18
|
+
def self.all_commits_raw
|
19
|
+
GitReport.project.revlist.inject([]){ |commits, rev| commits.push(GitReport.project.project.gcommit(rev)); commits }
|
20
|
+
end
|
21
|
+
|
22
|
+
# returns only the users commits of this project
|
23
|
+
# TODO: horrable performance
|
24
|
+
def self.user_commits_raw
|
25
|
+
all_commits_raw.delete_if{ |co| co.author.name != user_name }
|
26
|
+
end
|
27
|
+
|
28
|
+
# returns all commits of this project wrapped into Commit objects
|
29
|
+
def self.all_commits
|
30
|
+
all_commits_raw.map{ |co| GitReport::Commit.new(co, GitReport.project.identifier) }
|
31
|
+
end
|
32
|
+
|
33
|
+
# returns only the users commits of this project wrapped into Commit objects
|
34
|
+
def self.user_commits
|
35
|
+
user_commits_raw.map{ |co| GitReport::Commit.new(co, GitReport.project.identifier) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.user_name
|
39
|
+
@@username ||= GitReport::GitConfiguration.user_name
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|