tracker-client 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tracker +24 -0
- data/lib/command.rb +99 -0
- metadata +97 -0
data/bin/tracker
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rest-client'
|
5
|
+
require 'trollop'
|
6
|
+
|
7
|
+
$:.unshift File::expand_path(File.join(File.dirname(__FILE__), '..'))
|
8
|
+
|
9
|
+
require 'lib/command.rb'
|
10
|
+
|
11
|
+
opts = Trollop::options do
|
12
|
+
opt :dir, "GIT directory to use", :short => 'd', :default => '.'
|
13
|
+
opt :config, "Tracker config file location", :short => 'c', :default => "#{File.join(ENV['HOME'], '.trackerrc')}"
|
14
|
+
end
|
15
|
+
|
16
|
+
Tracker::Cmd.config(:set, :file => opts[:config])
|
17
|
+
|
18
|
+
puts case ARGV[0]
|
19
|
+
when 'record' then Tracker::Cmd.record(opts[:dir])
|
20
|
+
when 'ack' then Tracker::Cmd.ack(opts[:dir])
|
21
|
+
when 'nack' then Tracker::Cmd.nack(opts[:dir])
|
22
|
+
when 'push' then Tracker::Cmd.push(opts[:dir])
|
23
|
+
else 'Nothing to do here.'
|
24
|
+
end
|
data/lib/command.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
module Tracker
|
2
|
+
module Cmd
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
GIT_JSON_FORMAT = '{ "hashes":{ "commit":"%H", "tree":"%T", "parents":"%P" }, "author":{ "date": "%ai", "name": "%an", "email":"%ae" }, "committer":{ "date": "%ci", "name": "%cn", "email":"%ce" } },'
|
8
|
+
|
9
|
+
GIT_OPTS = "--format='#{GIT_JSON_FORMAT}'"
|
10
|
+
|
11
|
+
GIT_CMD = 'git --no-pager log origin/master..HEAD %s ' % GIT_OPTS
|
12
|
+
|
13
|
+
def self.default_configuration
|
14
|
+
{
|
15
|
+
:url => 'http://localhost:9292',
|
16
|
+
:user => 'mfojtik@redhat.com',
|
17
|
+
:password => 'test123'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.configuration(conf=nil); @configuration ||= conf; end
|
22
|
+
|
23
|
+
def self.config(action=:get, opts={})
|
24
|
+
if action == :set
|
25
|
+
if File.exists?(opts[:file])
|
26
|
+
configuration(YAML.load_file(opts[:file]))
|
27
|
+
else
|
28
|
+
end
|
29
|
+
end
|
30
|
+
configuration || configuration(default_configuration)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.patches_to_json(directory=nil)
|
34
|
+
patches_in_json = git_cmd(GIT_CMD, directory)
|
35
|
+
commit_messages_raw = git_cmd('git log --pretty=oneline origin/master..HEAD', directory)
|
36
|
+
commit_messages = {}
|
37
|
+
commit_messages_raw.each_line { |line|
|
38
|
+
hash, message = line.split(' ', 2)
|
39
|
+
commit_messages.merge!({ hash => message.strip })
|
40
|
+
}
|
41
|
+
"[#{patches_in_json}#{JSON::dump(commit_messages)}]"
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.record(directory)
|
45
|
+
RestClient.post(
|
46
|
+
config[:url] + '/patches',
|
47
|
+
patches_to_json(directory),
|
48
|
+
{
|
49
|
+
:content_type => 'application/json',
|
50
|
+
'Authorization' => "Basic #{basic_auth}"
|
51
|
+
}
|
52
|
+
)
|
53
|
+
"Patches recorded to server [#{config[:url]}]"
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.action(name, directory)
|
57
|
+
patches = JSON::parse(patches_to_json(directory))
|
58
|
+
messages = patches.pop
|
59
|
+
puts
|
60
|
+
patches.each do |p|
|
61
|
+
RestClient.post(
|
62
|
+
config[:url] + ('/patches/%s/%s' % [p['hashes']['commit'], name]), '',
|
63
|
+
{
|
64
|
+
:content_type => 'application/json',
|
65
|
+
'Authorization' => "Basic #{basic_auth}"
|
66
|
+
}
|
67
|
+
)
|
68
|
+
puts '[%s] %s' % [name.to_s.upcase, messages[p['hashes']['commit']]]
|
69
|
+
end
|
70
|
+
" |\n |--------> [%s]\n\n" % config[:url]
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.ack(directory); action(:ack, directory); end
|
74
|
+
def self.nack(directory); action(:nack, directory); end
|
75
|
+
def self.push(directory); action(:push, directory); end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def self.git_cmd(cmd, directory)
|
80
|
+
old_pwd = Dir.pwd
|
81
|
+
result = ''
|
82
|
+
begin
|
83
|
+
Dir.chdir(directory)
|
84
|
+
result = %x[#{cmd}]
|
85
|
+
rescue => e
|
86
|
+
puts "ERROR: #{e.message}"
|
87
|
+
exit(1)
|
88
|
+
ensure
|
89
|
+
Dir.chdir(old_pwd)
|
90
|
+
end
|
91
|
+
result
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.basic_auth
|
95
|
+
Base64.encode64("#{config[:user]}:#{config[:password]}")
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tracker-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michal Fojtik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: trollop
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: An interface to GIT patches tracker
|
63
|
+
email:
|
64
|
+
- mfojtik@redhat.com
|
65
|
+
executables:
|
66
|
+
- tracker
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- bin/tracker
|
71
|
+
- lib/command.rb
|
72
|
+
homepage: http://github.com/mifo/tracker
|
73
|
+
licenses:
|
74
|
+
- ASL
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.3.6
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.23
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: GIT patches tracker client
|
97
|
+
test_files: []
|