right_scraper 1.0.2 → 1.0.3
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 +64 -41
- data/right_scraper.gemspec +1 -1
- metadata +2 -2
@@ -47,52 +47,71 @@ module RightScale
|
|
47
47
|
msg = @incremental ? 'Pulling ' : 'Cloning '
|
48
48
|
msg += "git repository '#{@repo.display_name}'"
|
49
49
|
@callback.call(msg, is_step=true) if @callback
|
50
|
-
ssh_cmd
|
51
|
-
res
|
52
|
-
is_tag
|
50
|
+
ssh_cmd = ssh_command
|
51
|
+
res = ''
|
52
|
+
is_tag = nil
|
53
53
|
is_branch = nil
|
54
|
+
update_failed = false
|
54
55
|
|
55
56
|
if @incremental
|
56
57
|
Dir.chdir(@current_repo_dir) do
|
57
|
-
|
58
|
-
if
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
@
|
69
|
-
|
70
|
-
|
58
|
+
analysis = git_fetch_and_analyze(ssh_cmd)
|
59
|
+
if analysis[:success]
|
60
|
+
is_tag = analysis[:tag]
|
61
|
+
is_branch = analysis[:branch]
|
62
|
+
if !is_tag && !is_branch
|
63
|
+
@callback.call('Nothing to update: repo tag refers to neither a branch nor a tag', is_step=false)
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
if is_tag && is_branch
|
67
|
+
@errors << 'Repository tag ambiguous: could be git tag or git branch'
|
68
|
+
else
|
69
|
+
tag = @repo.tag.nil? || @repo.tag.empty? ? 'master' : @repo.tag
|
70
|
+
res = `git checkout #{tag} 2>&1`
|
71
|
+
if $? != 0
|
72
|
+
@callback.call("Failed to checkout #{tag}: #{res}, falling back to cloning", is_step=false) if @callback
|
73
|
+
update_failed = true
|
74
|
+
end
|
71
75
|
end
|
76
|
+
else
|
77
|
+
@callback.call("Failed to update repo: #{analysis[:output]}, falling back to cloning", is_step=false) if @callback
|
78
|
+
update_failed = true
|
72
79
|
end
|
73
80
|
end
|
74
81
|
end
|
82
|
+
if update_failed
|
83
|
+
FileUtils.rm_rf(@current_repo_dir)
|
84
|
+
@incremental = false
|
85
|
+
end
|
75
86
|
if !@incremental && succeeded?
|
76
87
|
res += `#{ssh_cmd} git clone --quiet --depth 1 "#{@repo.url}" "#{@current_repo_dir}" 2>&1`
|
77
|
-
@errors << res if $? != 0
|
88
|
+
@errors << "Failed to clone repo: #{res}" if $? != 0
|
78
89
|
if !@repo.tag.nil? && !@repo.tag.empty? && @repo.tag != 'master' && succeeded?
|
79
90
|
Dir.chdir(@current_repo_dir) do
|
80
91
|
if is_tag.nil?
|
81
|
-
|
82
|
-
|
92
|
+
analysis = git_fetch_and_analyze(ssh_cmd)
|
93
|
+
if analysis[:success]
|
94
|
+
is_tag = analysis[:tag]
|
95
|
+
is_branch = analysis[:branch]
|
96
|
+
res += analysis[:output]
|
97
|
+
else
|
98
|
+
@errors << "Failed to analyze repo: #{res}"
|
99
|
+
end
|
83
100
|
end
|
84
|
-
if
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
101
|
+
if succeded?
|
102
|
+
if is_tag && is_branch
|
103
|
+
@errors << 'Repository tag ambiguous: could be git tag or git branch'
|
104
|
+
elsif is_branch
|
105
|
+
res += `git branch #{@repo.tag} origin/#{@repo.tag} 2>&1`
|
106
|
+
@errors << res if $? != 0
|
107
|
+
elsif !is_tag # Not a branch nor a tag, SHA ref? fetch everything so we have all SHAs
|
108
|
+
res += `#{ssh_cmd} git fetch origin master --depth #{2**31 - 1} 2>&1`
|
109
|
+
@errors << res if $? != 0
|
110
|
+
end
|
111
|
+
if succeeded?
|
112
|
+
res += `git checkout #{@repo.tag} 2>&1`
|
113
|
+
@errors << res if $? != 0
|
114
|
+
end
|
96
115
|
end
|
97
116
|
end
|
98
117
|
end
|
@@ -189,16 +208,20 @@ module RightScale
|
|
189
208
|
# ssh_cmd(String):: SSH command to be used with git if any
|
190
209
|
#
|
191
210
|
# === Return
|
192
|
-
# res(
|
193
|
-
# -
|
194
|
-
# - res[
|
195
|
-
# - res[
|
196
|
-
|
197
|
-
|
211
|
+
# res(Hash)::
|
212
|
+
# - resp[:success]:: true if fetch was successful, false otherwise
|
213
|
+
# - res[:output] contains the git output
|
214
|
+
# - res[:tag]:: is true if git repo has a tag with a name corresponding to the repository tag
|
215
|
+
# - res[:branch] is true if git repo has a branch with a name corresponding to the repository tag
|
216
|
+
def git_fetch_and_analyze(ssh_cmd)
|
198
217
|
output = `#{ssh_cmd} git fetch --tags --depth 1 2>&1`
|
199
|
-
|
200
|
-
|
201
|
-
|
218
|
+
success = [0, 1].include? $?.exitstatus # git fetch returns 1 when there is nothing to fetch
|
219
|
+
is_tag = is_branch = false
|
220
|
+
if success
|
221
|
+
is_tag = `git tag`.split("\n").include?(@repo.tag)
|
222
|
+
is_branch = `git branch -r`.split("\n").map { |t| t.strip }.include?("origin/#{@repo.tag}")
|
223
|
+
end
|
224
|
+
{ :success => success, :output => output, :tag => is_tag, :branch => is_branch }
|
202
225
|
end
|
203
226
|
|
204
227
|
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.3'
|
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.3
|
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-02-
|
12
|
+
date: 2010-02-04 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|