tracker-client 0.7 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/tracker +3 -1
  2. data/lib/command.rb +23 -7
  3. metadata +1 -1
data/bin/tracker CHANGED
@@ -28,7 +28,8 @@ def print_usage
28
28
  puts 'tracker push - Mark all patches in current branch as PUSHED'
29
29
  puts 'tracker status - Display review status for current branch'
30
30
  puts 'tracker upload - Upload current patches (diffs) to tracker'
31
- puts 'tracker download - Download whole patchset from tracker'
31
+ puts 'tracker download - Download whole patchset from tracker (-i PATCHSET_ID)'
32
+ puts 'tracker apply - Apply patch with specified commit (-i COMMIT_ID)'
32
33
  puts
33
34
  system("#{__FILE__} --help")
34
35
  puts
@@ -46,5 +47,6 @@ puts case ARGV[0]
46
47
  when 'upload' then Tracker::Cmd.upload(opts[:dir])
47
48
  when 'download' then Tracker::Cmd.download(opts[:dir], opts[:id])
48
49
  when 'status' then Tracker::Cmd.status(opts[:dir])
50
+ when 'apply' then Tracker::Cmd.apply(opts[:dir], ARGV[1])
49
51
  else print_usage
50
52
  end
data/lib/command.rb CHANGED
@@ -83,6 +83,18 @@ module Tracker
83
83
  end
84
84
  end
85
85
 
86
+ def self.apply(directory, commit_id)
87
+ unless commit_id =~ /(\w{40})/
88
+ puts 'You must provide GIT commit hash (40 characters).'
89
+ exit 1
90
+ end
91
+ patch_body = download_patch_body(commit_id)
92
+ File.open(File.join(directory, "#{commit_id}.patch"), 'w') { |f| f.puts patch_body }
93
+ print 'Are you sure you want to apply patch to current branch? [Y/n]'
94
+ exit if (STDIN.gets.chomp) == 'n'
95
+ git_cmd("git am #{commit_id}.patch", directory)
96
+ end
97
+
86
98
  def self.upload(directory)
87
99
  diffs = git_cmd('git format-patch --stdout master', directory)
88
100
  patches = {}
@@ -118,13 +130,17 @@ module Tracker
118
130
  end
119
131
 
120
132
  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
- )
133
+ begin
134
+ RestClient.get(
135
+ config[:url] + ('/patch/%s/download' % commit_id),
136
+ {
137
+ :content_type => 'text/plain',
138
+ 'Authorization' => "Basic #{basic_auth}"
139
+ }
140
+ )
141
+ rescue => e
142
+ puts "[ERR] #{e.message}"
143
+ end
128
144
  end
129
145
 
130
146
  def self.download(directory, patchset_id)
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.7'
4
+ version: '0.8'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: