right_scraper 1.0.12 → 1.0.13
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/lib/right_scraper/scrapers/git_scraper.rb +46 -39
- data/right_scraper.gemspec +1 -1
- metadata +2 -2
@@ -48,24 +48,27 @@ module RightScale
|
|
48
48
|
msg += "git repository '#{@repo.display_name}'"
|
49
49
|
@callback.call(msg, is_step=true) if @callback
|
50
50
|
ssh_cmd = ssh_command
|
51
|
-
is_tag = nil
|
52
|
-
|
51
|
+
is_tag = is_branch = on_branch = nil
|
52
|
+
has_tag = !@repo.tag.nil? && !@repo.tag.empty?
|
53
53
|
|
54
54
|
if @incremental
|
55
55
|
Dir.chdir(@current_repo_dir) do
|
56
56
|
analysis = git_fetch_and_analyze(ssh_cmd, update=true)
|
57
|
-
if succeeded? && @incremental
|
57
|
+
if succeeded? && @incremental && has_tag
|
58
58
|
is_tag = analysis[:tag]
|
59
59
|
is_branch = analysis[:branch]
|
60
|
+
on_branch = analysis[:on_branch]
|
60
61
|
if !is_tag && !is_branch
|
61
|
-
|
62
|
-
|
62
|
+
current_sha = `git rev-parse HEAD`.chomp
|
63
|
+
if current_sha == @repo.tag
|
64
|
+
@callback.call("Nothing to update: already using #{repo.tag}", is_step=false) if @callback
|
65
|
+
return true
|
66
|
+
end
|
63
67
|
end
|
64
68
|
if is_tag && is_branch
|
65
69
|
@errors << 'Repository tag ambiguous: could be git tag or git branch'
|
66
|
-
|
67
|
-
|
68
|
-
res = `git checkout #{tag} 2>&1`
|
70
|
+
elsif !on_branch
|
71
|
+
res = `git checkout #{@repo.tag} 2>&1`
|
69
72
|
if $? != 0
|
70
73
|
@callback.call("Failed to checkout #{tag}: #{res}, falling back to cloning", is_step=false) if @callback
|
71
74
|
FileUtils.rm_rf(@current_repo_dir)
|
@@ -79,24 +82,27 @@ module RightScale
|
|
79
82
|
git_cmd = "#{ssh_cmd} git clone --quiet --depth 1 \"#{@repo.url}\" \"#{@current_repo_dir}\" 2>&1"
|
80
83
|
res = @watcher.launch_and_watch(git_cmd, @current_repo_dir)
|
81
84
|
handle_watcher_result(res, 'git clone', update=false)
|
82
|
-
if
|
85
|
+
if has_tag && succeeded?
|
83
86
|
Dir.chdir(@current_repo_dir) do
|
84
87
|
if is_tag.nil?
|
85
|
-
analysis
|
86
|
-
is_tag
|
88
|
+
analysis = git_fetch_and_analyze(ssh_cmd, update=false)
|
89
|
+
is_tag = analysis[:tag]
|
87
90
|
is_branch = analysis[:branch]
|
91
|
+
on_branch = analysis[:on_branch]
|
88
92
|
end
|
89
93
|
if succeeded?
|
90
94
|
if is_tag && is_branch
|
91
95
|
@errors << 'Repository tag ambiguous: could be git tag or git branch'
|
92
|
-
elsif is_branch
|
93
|
-
|
94
|
-
|
96
|
+
elsif is_branch
|
97
|
+
if !on_branch
|
98
|
+
output = `git branch #{@repo.tag} origin/#{@repo.tag} 2>&1`
|
99
|
+
@errors << output if $? != 0
|
100
|
+
end
|
95
101
|
elsif !is_tag # Not a branch nor a tag, SHA ref? fetch everything so we have all SHAs
|
96
|
-
output = `#{ssh_cmd} git fetch
|
102
|
+
output = `#{ssh_cmd} git fetch --depth #{2**31 - 1} 2>&1`
|
97
103
|
@errors << output if $? != 0
|
98
104
|
end
|
99
|
-
if succeeded?
|
105
|
+
if succeeded? && !on_branch
|
100
106
|
output = `git checkout #{@repo.tag} 2>&1`
|
101
107
|
@errors << output if $? != 0
|
102
108
|
end
|
@@ -163,27 +169,27 @@ module RightScale
|
|
163
169
|
# === Raise
|
164
170
|
# Exception:: If the USERPROFILE environment variable is not set
|
165
171
|
def win32_ssh_command
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
172
|
+
key_content = @repo.first_credential
|
173
|
+
unless key_content.nil?
|
174
|
+
# resolve key file path.
|
175
|
+
raise 'Environment variable USERPROFILE is missing' unless ENV['USERPROFILE']
|
176
|
+
user_profile_dir_path = ENV['USERPROFILE']
|
177
|
+
ssh_keys_dir = File.join(user_profile_dir_path, '.ssh')
|
178
|
+
FileUtils.mkdir_p(ssh_keys_dir) unless File.directory?(ssh_keys_dir)
|
179
|
+
ssh_key_file_path = File.join(ssh_keys_dir, 'id_rsa')
|
180
|
+
|
181
|
+
# (re)create key file. must overwrite any existing credentials in case
|
182
|
+
# we are switching repositories and have different credentials for each.
|
183
|
+
File.open(ssh_key_file_path, 'w') { |f| f.puts(key_content) }
|
184
|
+
|
185
|
+
# we need to create the "known_hosts" file or else the process will
|
186
|
+
# halt in windows waiting for a yes/no response to the unknown
|
187
|
+
# git host. this is normally handled by specifying
|
188
|
+
# "-o StrictHostKeyChecking=no" in the GIT_SSH executable, but it is
|
189
|
+
# still a mystery why this doesn't work properly in windows.
|
190
|
+
# so make a ssh call which creates the proper "known_hosts" file.
|
191
|
+
system("ssh -o StrictHostKeyChecking=no #{repo.url.split(':').first} exit 2>&1")
|
192
|
+
end
|
187
193
|
return ''
|
188
194
|
end
|
189
195
|
|
@@ -205,12 +211,13 @@ module RightScale
|
|
205
211
|
git_cmd = "#{ssh_cmd} git fetch --tags --depth 1 2>&1"
|
206
212
|
res = @watcher.launch_and_watch(git_cmd, @current_repo_dir)
|
207
213
|
handle_watcher_result(res, 'git fetch', update, ok_codes=[0, 1]) # git fetch returns 1 when there is nothing to fetch
|
208
|
-
is_tag = is_branch = false
|
214
|
+
is_tag = is_branch = on_branch = false
|
209
215
|
if succeeded? && (!update || @incremental)
|
210
216
|
is_tag = `git tag`.split("\n").include?(@repo.tag)
|
211
217
|
is_branch = `git branch -r`.split("\n").map { |t| t.strip }.include?("origin/#{@repo.tag}")
|
218
|
+
on_branch = is_branch && !!(`git branch`.split("\n").include?("* #{@repo.tag}")
|
212
219
|
end
|
213
|
-
{ :tag => is_tag, :branch => is_branch }
|
220
|
+
{ :tag => is_tag, :branch => is_branch, :on_branch => on_branch }
|
214
221
|
end
|
215
222
|
|
216
223
|
end
|
data/right_scraper.gemspec
CHANGED
@@ -23,7 +23,7 @@ require 'rubygems'
|
|
23
23
|
|
24
24
|
spec = Gem::Specification.new do |spec|
|
25
25
|
spec.name = 'right_scraper'
|
26
|
-
spec.version = '1.0.
|
26
|
+
spec.version = '1.0.13'
|
27
27
|
spec.authors = ['Raphael Simon']
|
28
28
|
spec.email = 'raphael@rightscale.com'
|
29
29
|
spec.homepage = 'https://github.com/rightscale/right_scraper'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raphael Simon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-04-18 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|