tracker-client 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tracker +22 -2
- data/lib/command.rb +97 -22
- metadata +2 -2
data/bin/tracker
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'rest-client'
|
5
5
|
require 'trollop'
|
6
|
+
require 'pp'
|
6
7
|
|
7
8
|
$:.unshift File::expand_path(File.join(File.dirname(__FILE__), '..'))
|
8
9
|
|
@@ -11,14 +12,33 @@ require 'lib/command.rb'
|
|
11
12
|
opts = Trollop::options do
|
12
13
|
opt :dir, "GIT directory to use", :short => 'd', :default => '.'
|
13
14
|
opt :config, "Tracker config file location", :short => 'c', :default => "#{File.join(ENV['HOME'], '.trackerrc')}"
|
15
|
+
opt :obsolete, "Used when recording new revision of patchset", :short => 'o', :type => :int
|
14
16
|
end
|
15
17
|
|
16
18
|
Tracker::Cmd.config(:set, :file => opts[:config])
|
17
19
|
|
20
|
+
def print_usage
|
21
|
+
puts 'Usage:'
|
22
|
+
puts
|
23
|
+
puts 'tracker record - Record current patchset to tracker'
|
24
|
+
puts 'tracker ack - ACK all patches in current branch'
|
25
|
+
puts 'tracker nack - NACK all patches in current branch'
|
26
|
+
puts 'tracker push - Mark all patches in current branch as PUSHED'
|
27
|
+
puts 'tracker status - Display review status for current branch'
|
28
|
+
puts
|
29
|
+
system("#{__FILE__} --help")
|
30
|
+
puts
|
31
|
+
puts 'Examples:'
|
32
|
+
puts
|
33
|
+
puts '$ tracker record -o 45 # Record current branch and obsolete patchset 45 (bump revision)'
|
34
|
+
''
|
35
|
+
end
|
36
|
+
|
18
37
|
puts case ARGV[0]
|
19
|
-
when 'record' then Tracker::Cmd.record(opts[:dir])
|
38
|
+
when 'record' then Tracker::Cmd.record(opts[:dir], opts[:obsolete])
|
20
39
|
when 'ack' then Tracker::Cmd.ack(opts[:dir])
|
21
40
|
when 'nack' then Tracker::Cmd.nack(opts[:dir])
|
22
41
|
when 'push' then Tracker::Cmd.push(opts[:dir])
|
23
|
-
|
42
|
+
when 'status' then Tracker::Cmd.status(opts[:dir])
|
43
|
+
else print_usage
|
24
44
|
end
|
data/lib/command.rb
CHANGED
@@ -18,54 +18,101 @@ module Tracker
|
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
|
+
# Set/Get configuration for the command-line client
|
22
|
+
#
|
23
|
+
# * +conf+ - Set configuration:
|
24
|
+
#
|
25
|
+
# * +:url+ - Tracker server URL (default: http://localhost:9292)
|
26
|
+
# * +:user+ - Tracker username
|
27
|
+
# * +:password+* - Tracker password
|
28
|
+
#
|
21
29
|
def self.configuration(conf=nil); @configuration ||= conf; end
|
22
30
|
|
31
|
+
# Retrieve/Set the configuration from YAML file, if YAML file does not
|
32
|
+
# exists, use the +default_configuration+ instead
|
33
|
+
#
|
34
|
+
# * +action+ - If action :set then overide the default_configuration (default: :get)
|
35
|
+
# * +:opts+ - Read YAML file from opts[:file]
|
36
|
+
#
|
23
37
|
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
|
38
|
+
configuration(YAML.load_file(opts[:file])) if (action == :set) && File.exists?(opts[:file])
|
30
39
|
configuration || configuration(default_configuration)
|
31
40
|
end
|
32
41
|
|
42
|
+
# Read commits between origin/master..HEAD and convert them to JSON string
|
43
|
+
#
|
44
|
+
# * +directory+ - If given, cmd app will 'chdir' into that directory (default: nil)
|
45
|
+
#
|
33
46
|
def self.patches_to_json(directory=nil)
|
34
47
|
patches_in_json = git_cmd(GIT_CMD, directory)
|
35
48
|
commit_messages_raw = git_cmd('git log --pretty=oneline origin/master..HEAD', directory)
|
36
|
-
commit_messages = {}
|
37
|
-
commit_messages_raw.each_line { |line|
|
49
|
+
commit_messages = commit_messages_raw.each_line.map.inject({}) do |result, line|
|
38
50
|
hash, message = line.split(' ', 2)
|
39
|
-
|
40
|
-
|
51
|
+
result[hash] = message.strip
|
52
|
+
result
|
53
|
+
end
|
41
54
|
"[#{patches_in_json}#{JSON::dump(commit_messages)}]"
|
42
55
|
end
|
43
56
|
|
44
|
-
|
57
|
+
# Method will call +patches_to_json+ and POST the JSON array to Tracker
|
58
|
+
# server. Authentication stored in +config+ is used.
|
59
|
+
#
|
60
|
+
# * +directory+ - If given, cmd app will 'chdir' into that directory (default: nil)
|
61
|
+
#
|
62
|
+
def self.record(directory, obsolete=nil)
|
63
|
+
number_of_commits = JSON::parse(patches_to_json(directory)).pop.size
|
64
|
+
begin
|
65
|
+
response = RestClient.post(
|
66
|
+
config[:url] + '/patches',
|
67
|
+
patches_to_json(directory),
|
68
|
+
{
|
69
|
+
:content_type => 'application/json',
|
70
|
+
'Authorization' => "Basic #{basic_auth}",
|
71
|
+
'X-Obsoletes' => obsolete || 'no'
|
72
|
+
}
|
73
|
+
)
|
74
|
+
response = JSON::parse(response)
|
75
|
+
"#{number_of_commits} patches were recorded to the tracker server [#{config[:url]}][##{response['id']}][rev#{response['revision']}]"
|
76
|
+
rescue => e
|
77
|
+
e.message
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.obsolete_patchset(patchset_id)
|
45
82
|
RestClient.post(
|
46
|
-
config[:url] + '/
|
47
|
-
patches_to_json(directory),
|
83
|
+
config[:url] + ('/patchset/%s/obsolete' % patchset_id), '',
|
48
84
|
{
|
49
85
|
:content_type => 'application/json',
|
50
86
|
'Authorization' => "Basic #{basic_auth}"
|
51
87
|
}
|
52
88
|
)
|
53
|
-
|
89
|
+
puts 'This record marked patchset [#%s] as obsoleted.'
|
54
90
|
end
|
55
91
|
|
92
|
+
# Method perform given action on GIT branch with recorded commits.
|
93
|
+
# The patches **need** to be recorded on Tracker server to perfom any
|
94
|
+
# action.
|
95
|
+
#
|
96
|
+
# * +name+ - Action name (:ack, :nack, :push)
|
97
|
+
# * +directory+ - If given, cmd app will 'chdir' into that directory (default: nil)
|
98
|
+
#
|
56
99
|
def self.action(name, directory)
|
57
100
|
patches = JSON::parse(patches_to_json(directory))
|
58
101
|
messages = patches.pop
|
59
102
|
puts
|
60
103
|
patches.each do |p|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
104
|
+
begin
|
105
|
+
RestClient.post(
|
106
|
+
config[:url] + ('/patches/%s/%s' % [p['hashes']['commit'], name]), '',
|
107
|
+
{
|
108
|
+
:content_type => 'application/json',
|
109
|
+
'Authorization' => "Basic #{basic_auth}"
|
110
|
+
}
|
111
|
+
)
|
112
|
+
puts '[%s][%s] %s' % [name.to_s.upcase, p['hashes']['commit'][-8, 8], messages[p['hashes']['commit']]]
|
113
|
+
rescue => e
|
114
|
+
puts '[ERR] %s' % e.message
|
115
|
+
end
|
69
116
|
end
|
70
117
|
" |\n |--------> [%s]\n\n" % config[:url]
|
71
118
|
end
|
@@ -74,8 +121,36 @@ module Tracker
|
|
74
121
|
def self.nack(directory); action(:nack, directory); end
|
75
122
|
def self.push(directory); action(:push, directory); end
|
76
123
|
|
124
|
+
def self.status(directory)
|
125
|
+
patches = JSON::parse(patches_to_json(directory))
|
126
|
+
# Remove messages from Array
|
127
|
+
patches.pop
|
128
|
+
puts
|
129
|
+
patches.each do |p|
|
130
|
+
begin
|
131
|
+
response = RestClient.get(
|
132
|
+
config[:url] + ('/patches/%s' % p['hashes']['commit']),
|
133
|
+
{
|
134
|
+
:content_type => 'application/json',
|
135
|
+
'Authorization' => "Basic #{basic_auth}"
|
136
|
+
}
|
137
|
+
)
|
138
|
+
response = JSON::parse(response)
|
139
|
+
puts '[%s][%s][rev%s] %s' % [response['commit'][-8, 8], response['status'].upcase, response['revision'], response['message']]
|
140
|
+
rescue => e
|
141
|
+
puts '[ERR][%s] %s' % [p['hashes']['commit'][-8, 8], e.message]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
" |\n |--------> [%s]\n\n" % config[:url]
|
145
|
+
end
|
146
|
+
|
77
147
|
private
|
78
148
|
|
149
|
+
# Execute GIT command ('git') in the specified directory. Method will then
|
150
|
+
# revert pwd to its original value and return command output in string.
|
151
|
+
#
|
152
|
+
# * +cmd+ - GIT command to perform (eg. 'git log')
|
153
|
+
#
|
79
154
|
def self.git_cmd(cmd, directory)
|
80
155
|
old_pwd = Dir.pwd
|
81
156
|
result = ''
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tracker-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|