tracker-client 0.6 → 0.7
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/bin/tracker +5 -0
- data/lib/command.rb +88 -7
- metadata +2 -2
data/bin/tracker
CHANGED
@@ -14,6 +14,7 @@ opts = Trollop::options do
|
|
14
14
|
opt :config, "Tracker config file location", :short => 'c', :default => "#{File.join(ENV['HOME'], '.trackerrc')}"
|
15
15
|
opt :obsolete, "Used when recording new revision of patchset", :short => 'o', :type => :int
|
16
16
|
opt :message, "Add short message to actions", :short => 'm', :type => :string
|
17
|
+
opt :id, "Patchset ID used by download action", :short => 'i', :type => :int
|
17
18
|
end
|
18
19
|
|
19
20
|
Tracker::Cmd.config(:set, :file => opts[:config])
|
@@ -26,6 +27,8 @@ def print_usage
|
|
26
27
|
puts 'tracker nack - NACK all patches in current branch'
|
27
28
|
puts 'tracker push - Mark all patches in current branch as PUSHED'
|
28
29
|
puts 'tracker status - Display review status for current branch'
|
30
|
+
puts 'tracker upload - Upload current patches (diffs) to tracker'
|
31
|
+
puts 'tracker download - Download whole patchset from tracker'
|
29
32
|
puts
|
30
33
|
system("#{__FILE__} --help")
|
31
34
|
puts
|
@@ -40,6 +43,8 @@ puts case ARGV[0]
|
|
40
43
|
when 'ack' then Tracker::Cmd.ack(opts[:dir], :message => opts[:message])
|
41
44
|
when 'nack' then Tracker::Cmd.nack(opts[:dir], :message => opts[:message])
|
42
45
|
when 'push' then Tracker::Cmd.push(opts[:dir], :message => opts[:message])
|
46
|
+
when 'upload' then Tracker::Cmd.upload(opts[:dir])
|
47
|
+
when 'download' then Tracker::Cmd.download(opts[:dir], opts[:id])
|
43
48
|
when 'status' then Tracker::Cmd.status(opts[:dir])
|
44
49
|
else print_usage
|
45
50
|
end
|
data/lib/command.rb
CHANGED
@@ -5,7 +5,10 @@ module Tracker
|
|
5
5
|
require 'json'
|
6
6
|
require 'base64'
|
7
7
|
|
8
|
-
GIT_JSON_FORMAT = '{ "hashes":
|
8
|
+
GIT_JSON_FORMAT = '{ "hashes":'+
|
9
|
+
'{ "commit":"%H", "tree":"%T",'+' "parents":"%P" },'+
|
10
|
+
'"author":{ "date": "%ai", "name": "%an", "email":"%ae" },'+
|
11
|
+
'"committer":{ "date": "%ci", "name": "%cn", "email":"%ce" } },'
|
9
12
|
|
10
13
|
GIT_OPTS = "--format='#{GIT_JSON_FORMAT}'"
|
11
14
|
|
@@ -64,7 +67,7 @@ module Tracker
|
|
64
67
|
number_of_commits = JSON::parse(patches_to_json(directory)).pop.size
|
65
68
|
begin
|
66
69
|
response = RestClient.post(
|
67
|
-
config[:url] + '/
|
70
|
+
config[:url] + '/set',
|
68
71
|
patches_to_json(directory),
|
69
72
|
{
|
70
73
|
:content_type => 'application/json',
|
@@ -73,12 +76,85 @@ module Tracker
|
|
73
76
|
}
|
74
77
|
)
|
75
78
|
response = JSON::parse(response)
|
76
|
-
"#{number_of_commits} patches were recorded to the tracker server
|
79
|
+
"#{number_of_commits} patches were recorded to the tracker server"+
|
80
|
+
" [#{config[:url]}][##{response['id']}][rev#{response['revision']}]"
|
77
81
|
rescue => e
|
78
82
|
e.message
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
86
|
+
def self.upload(directory)
|
87
|
+
diffs = git_cmd('git format-patch --stdout master', directory)
|
88
|
+
patches = {}
|
89
|
+
current_patch_commit = ''
|
90
|
+
diffs.each_line do |line|
|
91
|
+
if line =~ %r[^From (\w{40}) ]
|
92
|
+
current_patch_commit = $1
|
93
|
+
patches[current_patch_commit] = line
|
94
|
+
else
|
95
|
+
patches[current_patch_commit] += line
|
96
|
+
end
|
97
|
+
end
|
98
|
+
begin
|
99
|
+
patches.each do |commit, body|
|
100
|
+
puts '[^] %s' % commit
|
101
|
+
upload_patch_body(commit, body)
|
102
|
+
end
|
103
|
+
'%i patches were uploaded to tracker [%s]' % [patches.size, config[:url]]
|
104
|
+
rescue => e
|
105
|
+
e.message
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.upload_patch_body(commit_id, body)
|
110
|
+
RestClient.put(
|
111
|
+
config[:url] + ('/patch/%s/body' % commit_id),
|
112
|
+
body,
|
113
|
+
{
|
114
|
+
:content_type => 'application/json',
|
115
|
+
'Authorization' => "Basic #{basic_auth}"
|
116
|
+
}
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.download_patch_body(commit_id)
|
121
|
+
RestClient.get(
|
122
|
+
config[:url] + ('/patch/%s/download' % commit_id),
|
123
|
+
{
|
124
|
+
:content_type => 'application/json',
|
125
|
+
'Authorization' => "Basic #{basic_auth}"
|
126
|
+
}
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.download(directory, patchset_id)
|
131
|
+
patches = []
|
132
|
+
begin
|
133
|
+
response = RestClient.get(
|
134
|
+
config[:url] + ('/set/%s' % patchset_id),
|
135
|
+
{
|
136
|
+
'Accept' => 'application/json',
|
137
|
+
'Authorization' => "Basic #{basic_auth}"
|
138
|
+
}
|
139
|
+
)
|
140
|
+
patches = JSON::parse(response)['patches'].map { |p| p['commit'] }
|
141
|
+
rescue => e
|
142
|
+
puts "ERR: #{e.message}"
|
143
|
+
exit
|
144
|
+
end
|
145
|
+
counter = 0
|
146
|
+
puts
|
147
|
+
patches.each do |commit|
|
148
|
+
File.open(File.join(directory, "#{counter}-#{commit}.patch"), 'w') { |f|
|
149
|
+
f.puts download_patch_body(commit)
|
150
|
+
}
|
151
|
+
puts '[v] %s-%s.patch' % [counter, commit]
|
152
|
+
counter += 1
|
153
|
+
end
|
154
|
+
puts "\n -> #{counter} patches downloaded."
|
155
|
+
''
|
156
|
+
end
|
157
|
+
|
82
158
|
def self.obsolete_patchset(patchset_id)
|
83
159
|
RestClient.post(
|
84
160
|
config[:url] + ('/patchset/%s/obsolete' % patchset_id), '',
|
@@ -104,7 +180,7 @@ module Tracker
|
|
104
180
|
patches.each do |p|
|
105
181
|
begin
|
106
182
|
RestClient.post(
|
107
|
-
config[:url] + ('/
|
183
|
+
config[:url] + ('/patch/%s/%s' % [p['hashes']['commit'], name]),
|
108
184
|
{
|
109
185
|
:message => options[:message]
|
110
186
|
},
|
@@ -134,14 +210,19 @@ module Tracker
|
|
134
210
|
patches.each do |p|
|
135
211
|
begin
|
136
212
|
response = RestClient.get(
|
137
|
-
config[:url] + ('/
|
213
|
+
config[:url] + ('/patch/%s' % p['hashes']['commit']),
|
138
214
|
{
|
139
|
-
|
215
|
+
'Accept' => 'application/json',
|
140
216
|
'Authorization' => "Basic #{basic_auth}"
|
141
217
|
}
|
142
218
|
)
|
143
219
|
response = JSON::parse(response)
|
144
|
-
puts '[%s][%s][rev%s] %s' % [
|
220
|
+
puts '[%s][%s][rev%s] %s' % [
|
221
|
+
response['commit'][-8, 8],
|
222
|
+
response['status'].upcase,
|
223
|
+
response['revision'],
|
224
|
+
response['message']
|
225
|
+
]
|
145
226
|
counter+=1
|
146
227
|
rescue => e
|
147
228
|
next if response == 'null'
|
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.7'
|
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-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|