right_scraper 1.0.20 → 1.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -54,8 +54,7 @@ module RightScale
54
54
  if @incremental
55
55
  checkout = false
56
56
  Dir.chdir(@current_repo_dir) do
57
- git_fetch(:depth => 1, :remote_tag => @repo.tag)
58
- if succeeded? && @incremental && has_tag
57
+ if has_tag
59
58
  analysis = analyze_repo_tag
60
59
  if succeeded?
61
60
  is_tag = analysis[:tag]
@@ -69,23 +68,27 @@ module RightScale
69
68
  if current_sha == @repo.tag
70
69
  @callback.call("Nothing to update: already using #{@repo.tag}", is_step=false) if @callback
71
70
  return true
72
- else
71
+ else
73
72
  # Probably a SHA, retrieve all commits
74
73
  git_fetch(:depth => 2**31 - 1)
75
74
  checkout = true
76
75
  end
77
76
  end
77
+ if succeeded?
78
+ if checkout
79
+ git_checkout(@repo.tag)
80
+ else
81
+ git_checkout(@repo.tag) if is_branch && !on_branch
82
+ git_fetch(:depth => 1, :merge => true, :remote_tag => @repo.tag)
83
+ end
84
+ end
78
85
  end
79
- end
80
- if succeeded?
81
- if checkout || is_branch && !on_branch
82
- git_checkout(@repo.tag)
83
- else # Pull latest commits on same branch
84
- git_fetch(:depth => 1, :merge => true, :remote_tag => @repo.tag)
85
- end
86
+ else
87
+ git_fetch(:depth => 1, :merge => true)
86
88
  end
87
89
  end
88
90
  end
91
+
89
92
  if !@incremental && succeeded?
90
93
  git_cmd = "#{@ssh_cmd} git clone --quiet --depth 1 \"#{@repo.url}\" \"#{@current_repo_dir}\" 2>&1"
91
94
  res = @watcher.launch_and_watch(git_cmd, @current_repo_dir)
@@ -65,6 +65,7 @@ module RightScale
65
65
  cookbooks_path = [ cookbooks_path ] unless cookbooks_path.is_a?(Array)
66
66
  if @incremental
67
67
  svn_cmd = "svn update --no-auth-cache --non-interactive --quiet" +
68
+ (!@repo.tag.nil? && !@repo.tag.empty? ? " --revision #{@repo.tag}" : '') +
68
69
  (@repo.first_credential ? " --username #{@repo.first_credential}" : '') +
69
70
  (@repo.second_credential ? " --password #{@repo.second_credential}" : '') +
70
71
  ' 2>&1'
@@ -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.20'
26
+ spec.version = '1.0.21'
27
27
  spec.authors = ['Raphael Simon']
28
28
  spec.email = 'raphael@rightscale.com'
29
29
  spec.homepage = 'https://github.com/rightscale/right_scraper'
@@ -24,7 +24,7 @@
24
24
  # Not supported on Windows
25
25
  unless RUBY_PLATFORM=~/mswin/
26
26
 
27
- require File.join(File.dirname(__FILE__), 'spec_helper')
27
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
28
28
  require 'scraper_base'
29
29
  require 'repository'
30
30
  require 'watcher'
@@ -0,0 +1,165 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'git_scraper_spec_helper'))
25
+ require 'scraper_base'
26
+ require 'repository'
27
+ require 'watcher'
28
+ require File.join('scrapers', 'git_scraper')
29
+ require 'set'
30
+
31
+ describe RightScale::GitScraper do
32
+
33
+ context 'given a git repository' do
34
+
35
+ before(:each) do
36
+ @helper = RightScale::GitScraperSpecHelper.new
37
+ @helper.setup_test_repo
38
+ @scrape_dir = File.expand_path(File.join(File.dirname(__FILE__), '__scrape'))
39
+ @scraper = RightScale::GitScraper.new(@scrape_dir, max_bytes=1024**2, max_seconds=20)
40
+ @repo = RightScale::Repository.from_hash(:display_name => 'test repo',
41
+ :repo_type => :git,
42
+ :url => @helper.repo_path)
43
+ @current_repo_dir = RightScale::ScraperBase.repo_dir(@scrape_dir, @repo)
44
+ FileUtils.rm_rf(@current_repo_dir)
45
+ end
46
+
47
+ after(:each) do
48
+ @helper.delete_test_repo
49
+ FileUtils.rm_rf(@scrape_dir)
50
+ end
51
+
52
+ it 'should scrape the master branch' do
53
+ messages = []
54
+ @scraper.instance_variable_set(:@current_repo_dir, @current_repo_dir)
55
+ @scraper.incremental_update?.should be_false
56
+ @scraper.scrape(@repo) { |m, progress| messages << m if progress }
57
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
58
+ @scraper.succeeded?.should be_true
59
+ messages.size.should == 1
60
+ File.directory?(@scraper.current_repo_dir).should be_true
61
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
62
+ Set.new(@helper.repo_content)
63
+ end
64
+
65
+ it 'should scrape the master branch incrementally' do
66
+ @scraper.scrape(@repo)
67
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
68
+ @scraper.incremental_update?.should be_true
69
+ @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
70
+ @helper.commit_content
71
+ messages = []
72
+ @scraper.scrape(@repo) { |m, progress| messages << m if progress }
73
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
74
+ @scraper.succeeded?.should be_true
75
+ messages.size.should == 1
76
+ @scraper.instance_variable_get(:@incremental).should == true
77
+ File.directory?(@scraper.current_repo_dir).should be_true
78
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
79
+ Set.new(@helper.repo_content + @helper.additional_content)
80
+ end
81
+
82
+ context 'and a branch' do
83
+
84
+ before(:each) do
85
+ @helper.setup_branch('test_branch', @helper.branch_content)
86
+ @branch_repo = RightScale::Repository.from_hash(:display_name => 'test repo',
87
+ :repo_type => :git,
88
+ :url => @helper.repo_path,
89
+ :tag => 'test_branch')
90
+ end
91
+
92
+ it 'should scrape a branch' do
93
+ messages = []
94
+ @scraper.scrape(@branch_repo) { |m, progress| messages << m if progress }
95
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
96
+ @scraper.succeeded?.should be_true
97
+ messages.size.should == 1
98
+ File.directory?(@scraper.current_repo_dir).should be_true
99
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
100
+ Set.new((@helper.repo_content + @helper.branch_content))
101
+ end
102
+
103
+ it 'should scrape a branch incrementally' do
104
+ @scraper.scrape(@branch_repo)
105
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
106
+ @scraper.incremental_update?.should be_true
107
+ @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
108
+ @helper.commit_content
109
+ messages = []
110
+ @scraper.scrape(@branch_repo) { |m, progress| messages << m if progress }
111
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
112
+ @scraper.succeeded?.should be_true
113
+ messages.size.should == 1
114
+ @scraper.instance_variable_get(:@incremental).should == true
115
+ File.directory?(@scraper.current_repo_dir).should be_true
116
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
117
+ Set.new((@helper.repo_content + @helper.branch_content + @helper.additional_content))
118
+ end
119
+
120
+ end
121
+
122
+ context 'and a sha ref' do
123
+
124
+ before(:each) do
125
+ @helper.create_file_layout(@helper.repo_path, @helper.branch_content)
126
+ @helper.commit_content
127
+ @sha_repo = RightScale::Repository.from_hash(:display_name => 'test repo',
128
+ :repo_type => :git,
129
+ :url => @helper.repo_path,
130
+ :tag => @helper.commit_id(1))
131
+ end
132
+
133
+ it 'should scrape a sha' do
134
+ messages = []
135
+ @scraper.scrape(@sha_repo) { |m, progress| messages << m if progress }
136
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
137
+ @scraper.succeeded?.should be_true
138
+ messages.size.should == 1
139
+ File.directory?(@scraper.current_repo_dir).should be_true
140
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
141
+ Set.new(@helper.repo_content)
142
+ end
143
+
144
+ it 'should scrape a sha incrementally' do
145
+ @scraper.scrape(@sha_repo)
146
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
147
+ @scraper.incremental_update?.should be_true
148
+ @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
149
+ @helper.commit_content
150
+ messages = []
151
+ @scraper.scrape(@sha_repo) { |m, progress| messages << m if progress }
152
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
153
+ @scraper.succeeded?.should be_true
154
+ messages.size.should == 1
155
+ @scraper.instance_variable_get(:@incremental).should == true
156
+ File.directory?(@scraper.current_repo_dir).should be_true
157
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
158
+ Set.new(@helper.repo_content)
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+
165
+ end
@@ -0,0 +1,72 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'scraper_spec_helper_base'))
25
+
26
+ module RightScale
27
+
28
+ # Git implementation of scraper spec helper
29
+ # See parent class for methods headers comments
30
+ class GitScraperSpecHelper < ScraperSpecHelperBase
31
+
32
+ def setup_test_repo
33
+ FileUtils.rm_rf(repo_path)
34
+ FileUtils.mkdir_p(repo_path)
35
+ Dir.chdir(repo_path) do
36
+ res, status = exec('git init')
37
+ raise "Failed to initialize bare git repository: #{res}" unless status.success?
38
+ end
39
+ create_file_layout(repo_path, repo_content)
40
+ commit_content(repo_path)
41
+ end
42
+
43
+ def commit_content(commit_message='commit')
44
+ Dir.chdir(repo_path) do
45
+ res, status = exec('git add .')
46
+ res, status = exec("git commit --quiet -m \"#{commit_message}\"") if status.success?
47
+ raise "Failed to commit changes from #{repo_path}: #{res}" unless status.success?
48
+ end
49
+ end
50
+
51
+ def setup_branch(branch, new_content=nil)
52
+ Dir.chdir(repo_path) do
53
+ res, status = exec("git checkout -b #{branch}")
54
+ raise "Failed to setup branch #{branch}: #{res}" unless status.success?
55
+ end
56
+ unless new_content.nil?
57
+ create_file_layout(repo_path, new_content)
58
+ commit_content("Branch #{branch}")
59
+ end
60
+ end
61
+
62
+ def commit_id(index_from_last=0)
63
+ res = nil
64
+ Dir.chdir(repo_path) do
65
+ res, status = exec("git log --format=%H -#{index_from_last + 1}")
66
+ raise "Failed to retrieve commit sha #{index_from_last}: #{res}" unless status.success?
67
+ end
68
+ commit_id = res.split("\n").last
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,132 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
25
+
26
+ module RightScale
27
+
28
+ # Base class for all scrapers spec helpers
29
+ # Define helper methods used to manage repositories using each
30
+ # source control software
31
+ class ScraperSpecHelperBase
32
+
33
+ include SpecHelpers
34
+
35
+ # Path to test repository
36
+ #
37
+ # === Return
38
+ # repo_path(String):: Path to test repository
39
+ def repo_path
40
+ repo_path = File.join(File.dirname(__FILE__), '__repo')
41
+ end
42
+
43
+ # Default test repo content
44
+ #
45
+ # === Return
46
+ # content(String):: Default test repo content
47
+ def repo_content
48
+ content = [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => [ { 'folder3' => [ 'file4' ] } ] }, 'file1' ]
49
+ end
50
+
51
+ # Test branch content
52
+ #
53
+ # === Return
54
+ # content(String):: Branch content
55
+ def branch_content
56
+ content = [ { 'branch_folder' => [ 'bfile1', 'bfile2' ] }, 'bfile3' ]
57
+ end
58
+
59
+ # Additional content used to test incremental updates
60
+ #
61
+ # === Return
62
+ # content(String):: Additional content
63
+ def additional_content
64
+ content = [ { 'additional_folder' => [ 'afile1', 'afile2' ] }, 'afile3' ]
65
+ end
66
+
67
+ # Create test repository following given layout
68
+ # Delete any previously created repo
69
+ #
70
+ # === Return
71
+ # repo_path(String):: Path to created repositoy
72
+ #
73
+ # === Raise
74
+ # Exception:: If repository initialization fails
75
+ def setup_test_repo
76
+ raise 'Not supported'
77
+ end
78
+
79
+ # Delete test repository
80
+ #
81
+ # === Return
82
+ # true:: Always return true
83
+ def delete_test_repo
84
+ FileUtils.rm_rf(repo_path)
85
+ end
86
+
87
+ # Commit any non-commited changes of given directory
88
+ #
89
+ # === Parameters
90
+ # repo_path(String):: Path to directory where commit should be created
91
+ # commit_message(String):: Optional, commit message
92
+ #
93
+ # === Raise
94
+ # Exception:: If commit command fails
95
+ def commit_content(repo_path, commit_message='Initial commit')
96
+ raise 'Not implemented'
97
+ end
98
+
99
+ # Create a branch in given repository
100
+ # Optionally adds a new commit with given file layout
101
+ # Switch to branch so that next call to 'create_file_layout' will act
102
+ # on given branch
103
+ #
104
+ # === Parameters
105
+ # branch(String):: Name of branch that should be created
106
+ # new_content(Hash):: Layout of files to be added to branch as a single commit
107
+ #
108
+ # === Return
109
+ # true:: Always return true
110
+ #
111
+ # === Raise
112
+ # Exception:: If branch command fails
113
+ def setup_branch(branch, new_content=nil)
114
+ raise 'Not implemented'
115
+ end
116
+
117
+ # Commit id for commit in test repo
118
+ # i.e. git sha or svn rev
119
+ #
120
+ # === Parameters
121
+ # index_from_last(Integer):: Commit whose id should be returned:
122
+ # - 0 means last commit
123
+ # - 1 means 1 before last
124
+ # - etc.
125
+ #
126
+ # === Return
127
+ # commit_id(String):: Corresponding commit id
128
+ def commit_id(index_from_last=0)
129
+ raise 'Not implemented'
130
+ end
131
+ end
132
+ end
@@ -21,66 +21,32 @@
21
21
  # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- require File.join(File.dirname(__FILE__), 'spec_helper')
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'svn_scraper_spec_helper'))
25
25
  require 'scraper_base'
26
26
  require 'repository'
27
27
  require 'watcher'
28
28
  require File.join('scrapers', 'svn_scraper')
29
+ require 'set'
29
30
 
30
31
  describe RightScale::SvnScraper do
31
-
32
- include RightScale::SpecHelpers
33
-
34
- # Create svn repository following given layout
35
- # Update @repo_path with path to repository
36
- # Delete any previously created repo
37
- def setup_svn_repo
38
- @svn_repo_path = File.expand_path(File.join(File.dirname(__FILE__), '__svn_repo'))
39
- @repo_path = File.join(File.dirname(__FILE__), '__repo')
40
- @repo_content = [ { 'folder1' => [ 'file2', 'file3' ] },
41
- { 'folder2' => [ { 'folder3' => [ 'file4' ] },
42
- { 'folder5' => [ 'file6' ] } ] },
43
- 'file1' ]
44
- FileUtils.rm_rf(@svn_repo_path)
45
- res, status = exec("svnadmin create \"#{@svn_repo_path}\"")
46
- raise "Failed to initialize SVN repository: #{res}" unless status.success?
47
- FileUtils.rm_rf(@repo_path)
48
- res, status = exec("svn checkout \"file:///#{@svn_repo_path}\" \"#{@repo_path}\"")
49
- raise "Failed to checkout repository: #{res}" unless status.success?
50
- create_file_layout(@repo_path, @repo_content)
51
- Dir.chdir(@repo_path) do
52
- res, status = exec("svn add *")
53
- res, status = exec("svn commit --quiet -m \"Initial Commit\"") if status.success?
54
- raise "Failed to setup repository: #{res}" unless status.success?
55
- end
56
- end
57
-
58
- # Cleanup after ourselves
59
- def delete_svn_repo
60
- FileUtils.rm_rf(@svn_repo_path) if @svn_repo_path
61
- @svn_repo_path = nil
62
- FileUtils.rm_rf(@repo_path) if @repo_path
63
- @repo_path = nil
64
- end
65
32
 
66
33
  context 'given a SVN repository' do
67
34
 
68
- before(:all) do
69
- setup_svn_repo
70
- end
71
-
72
35
  before(:each) do
73
- file_prefix = 'file://'
74
- file_prefix += '/' if RUBY_PLATFORM =~ /mswin/
75
- @scraper = RightScale::SvnScraper.new(@repo_path, max_bytes=1024**2, max_seconds=20)
36
+ @helper = RightScale::SvnScraperSpecHelper.new
37
+ @helper.setup_test_repo
38
+ @scrape_dir = File.expand_path(File.join(File.dirname(__FILE__), '__scrape'))
39
+ @scraper = RightScale::SvnScraper.new(@scrape_dir, max_bytes=1024**2, max_seconds=20)
76
40
  @repo = RightScale::Repository.from_hash(:display_name => 'test repo',
77
41
  :repo_type => :svn,
78
- :url => "#{file_prefix}#{@svn_repo_path}")
79
- FileUtils.rm_rf(RightScale::ScraperBase.repo_dir(@repo_path, @repo))
42
+ :url => @helper.repo_url)
43
+ FileUtils.rm_rf(RightScale::ScraperBase.repo_dir(@helper.repo_path, @repo))
80
44
  end
81
45
 
82
- after(:all) do
83
- delete_svn_repo
46
+ after(:each) do
47
+ @helper.delete_test_repo
48
+ FileUtils.rm_rf(@helper.svn_repo_path)
49
+ FileUtils.rm_rf(@scrape_dir)
84
50
  end
85
51
 
86
52
  it 'should scrape' do
@@ -90,7 +56,8 @@ describe RightScale::SvnScraper do
90
56
  @scraper.succeeded?.should be_true
91
57
  messages.size.should == 1
92
58
  File.directory?(@scraper.current_repo_dir).should be_true
93
- extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == @repo_content
59
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ])).should ==
60
+ Set.new(@helper.repo_content)
94
61
  end
95
62
 
96
63
  it 'should scrape incrementally' do
@@ -98,13 +65,16 @@ describe RightScale::SvnScraper do
98
65
  @scraper.scrape(@repo)
99
66
  puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
100
67
  @scraper.incremental_update?.should be_true
68
+ @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
69
+ @helper.commit_content
101
70
  messages = []
102
71
  @scraper.scrape(@repo) { |m, progress| messages << m if progress }
103
72
  puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
104
73
  @scraper.succeeded?.should be_true
105
74
  messages.size.should == 1
106
75
  File.directory?(@scraper.current_repo_dir).should be_true
107
- extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == @repo_content
76
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ])).should ==
77
+ Set.new(@helper.repo_content + @helper.additional_content)
108
78
  end
109
79
 
110
80
  it 'should only scrape cookbooks directories' do
@@ -115,7 +85,7 @@ describe RightScale::SvnScraper do
115
85
  @scraper.succeeded?.should be_true
116
86
  messages.size.should == 1
117
87
  File.directory?(@scraper.current_repo_dir).should be_true
118
- extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => ['folder3' => [ 'file4' ] ] } ]
88
+ @helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => ['folder3' => [ 'file4' ] ] } ]
119
89
  end
120
90
 
121
91
  it 'should only scrape cookbooks directories incrementally' do
@@ -130,9 +100,49 @@ describe RightScale::SvnScraper do
130
100
  @scraper.succeeded?.should be_true
131
101
  messages.size.should == 1
132
102
  File.directory?(@scraper.current_repo_dir).should be_true
133
- extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => ['folder3' => [ 'file4' ] ] } ]
103
+ @helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => ['folder3' => [ 'file4' ] ] } ]
134
104
  end
135
105
 
106
+ context 'and a revision' do
107
+
108
+ before(:each) do
109
+ @helper.create_file_layout(@helper.repo_path, @helper.branch_content)
110
+ @helper.commit_content
111
+ @rev_repo = RightScale::Repository.from_hash(:display_name => 'test repo',
112
+ :repo_type => :svn,
113
+ :url => @helper.repo_url,
114
+ :tag => @helper.commit_id(1))
115
+ end
116
+
117
+ it 'should scrape a revision' do
118
+ messages = []
119
+ @scraper.scrape(@rev_repo) { |m, progress| messages << m if progress }
120
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
121
+ @scraper.succeeded?.should be_true
122
+ messages.size.should == 1
123
+ File.directory?(@scraper.current_repo_dir).should be_true
124
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ])).should ==
125
+ Set.new(@helper.repo_content)
126
+ end
127
+
128
+ it 'should scrape a revision incrementally' do
129
+ @scraper.scrape(@rev_repo)
130
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
131
+ @scraper.incremental_update?.should be_true
132
+ @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
133
+ @helper.commit_content
134
+ messages = []
135
+ @scraper.scrape(@rev_repo) { |m, progress| messages << m if progress }
136
+ puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
137
+ @scraper.succeeded?.should be_true
138
+ messages.size.should == 1
139
+ @scraper.instance_variable_get(:@incremental).should == true
140
+ File.directory?(@scraper.current_repo_dir).should be_true
141
+ Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ])).should ==
142
+ Set.new(@helper.repo_content)
143
+ end
144
+
145
+ end
136
146
  end
137
147
 
138
148
  end
@@ -0,0 +1,72 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'scraper_spec_helper_base'))
25
+
26
+ module RightScale
27
+
28
+ # SVN implementation of scraper spec helper
29
+ # See parent class for methods headers comments
30
+ class SvnScraperSpecHelper < ScraperSpecHelperBase
31
+
32
+ def svn_repo_path
33
+ svn_repo_path = File.expand_path(File.join(File.dirname(__FILE__), '__svn_repo'))
34
+ end
35
+
36
+ def repo_url
37
+ file_prefix = 'file://'
38
+ file_prefix += '/' if RUBY_PLATFORM =~ /mswin/
39
+ url = "#{file_prefix}#{svn_repo_path}"
40
+ end
41
+
42
+ def setup_test_repo
43
+ FileUtils.rm_rf(repo_path)
44
+ FileUtils.mkdir_p(repo_path)
45
+ FileUtils.rm_rf(svn_repo_path)
46
+ res, status = exec("svnadmin create \"#{svn_repo_path}\"")
47
+ raise "Failed to initialize SVN repository: #{res}" unless status.success?
48
+ res, status = exec("svn checkout \"#{repo_url}\" \"#{repo_path}\"")
49
+ raise "Failed to checkout repository: #{res}" unless status.success?
50
+ create_file_layout(repo_path, repo_content)
51
+ commit_content
52
+ end
53
+
54
+ def commit_content(commit_message='commit message')
55
+ Dir.chdir(repo_path) do
56
+ res, status = exec('svn add *')
57
+ res, status = exec("svn commit --quiet -m \"#{commit_message}\"") if status.success?
58
+ raise "Failed to commit changes from #{branch}: #{res}" unless status.success?
59
+ end
60
+ end
61
+
62
+ def commit_id(index_from_last=0)
63
+ res = nil
64
+ Dir.chdir(repo_path) do
65
+ res, status = exec("svn log --quiet #{repo_url}")
66
+ raise "Failed to retrieve commit revision #{index_from_last}: #{res}" unless status.success?
67
+ end
68
+ commit_id = res.split("\n")[ 1 + index_from_last * 2].split(' ').first
69
+ end
70
+
71
+ end
72
+ end
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.20
4
+ version: 1.0.21
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-06-22 00:00:00 -07:00
12
+ date: 2010-07-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -36,15 +36,18 @@ files:
36
36
  - lib/right_scraper/watcher.rb
37
37
  - lib/right_scraper/win32/process_monitor.rb
38
38
  - right_scraper.gemspec
39
- - spec/download_scraper_spec.rb
40
- - spec/git_scraper_spec.rb
39
+ - spec/download/download_scraper_spec.rb
40
+ - spec/git/git_scraper_spec.rb
41
+ - spec/git/git_scraper_spec_helper.rb
41
42
  - spec/rcov.opts
42
43
  - spec/repository_spec.rb
43
44
  - spec/scraper_base_spec.rb
44
45
  - spec/scraper_spec.rb
46
+ - spec/scraper_spec_helper_base.rb
45
47
  - spec/spec.opts
46
48
  - spec/spec_helper.rb
47
- - spec/svn_scraper_spec.rb
49
+ - spec/svn/svn_scraper_spec.rb
50
+ - spec/svn/svn_scraper_spec_helper.rb
48
51
  - spec/watcher_spec.rb
49
52
  has_rdoc: true
50
53
  homepage: https://github.com/rightscale/right_scraper
@@ -1,110 +0,0 @@
1
- #--
2
- # Copyright: Copyright (c) 2010 RightScale, Inc.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # 'Software'), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
- # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
- # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
- # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
- # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- require File.join(File.dirname(__FILE__), 'spec_helper')
25
- require 'scraper_base'
26
- require 'repository'
27
- require 'watcher'
28
- require File.join('scrapers', 'git_scraper')
29
-
30
- describe RightScale::GitScraper do
31
-
32
- include RightScale::SpecHelpers
33
-
34
- # Create git repository following given layout
35
- # Update @repo_path with path to repository
36
- # Delete any previously created repo
37
- def setup_git_repo
38
- @origin_path = File.expand_path(File.join(File.dirname(__FILE__), '__origin'))
39
- @repo_path = File.join(File.dirname(__FILE__), '__repo')
40
- @repo_content = [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => [ { 'folder3' => [ 'file4' ] } ] }, 'file1' ]
41
- FileUtils.rm_rf(@origin_path)
42
- FileUtils.mkdir_p(@origin_path)
43
- Dir.chdir(@origin_path) do
44
- res, status = exec("git init --bare")
45
- raise "Failed to initialize bare git repository: #{res}" unless status.success?
46
- end
47
- FileUtils.rm_rf(@repo_path)
48
- res, status = exec("git clone --quiet \"#{@origin_path}\" \"#{@repo_path}\"")
49
- raise "Failed to initialize git repository: #{res}" unless status.success?
50
- create_file_layout(@repo_path, @repo_content)
51
- Dir.chdir(@repo_path) do
52
- res, status = exec("git add .")
53
- res, status = exec("git commit --quiet -m \"Initial Commit\"") if status.success?
54
- res, status = exec("git push origin master") if status.success?
55
- raise "Failed to setup git repository: #{res}" unless status.success?
56
- end
57
- end
58
-
59
- # Cleanup after ourselves
60
- def delete_git_repo
61
- FileUtils.rm_rf(@origin_path) if @origin_path
62
- @origin_path = nil
63
- FileUtils.rm_rf(@repo_path) if @repo_path
64
- @repo_path = nil
65
- end
66
-
67
- context 'given a git repository' do
68
-
69
- before(:all) do
70
- setup_git_repo
71
- end
72
-
73
- before(:each) do
74
- @scraper = RightScale::GitScraper.new(@repo_path, max_bytes=1024**2, max_seconds=20)
75
- @repo = RightScale::Repository.from_hash(:display_name => 'test repo',
76
- :repo_type => :git,
77
- :url => @origin_path)
78
- FileUtils.rm_rf(RightScale::ScraperBase.repo_dir(@repo_path, @repo))
79
- end
80
-
81
- after(:all) do
82
- delete_git_repo
83
- end
84
-
85
- it 'should scrape' do
86
- messages = []
87
- @scraper.scrape(@repo) { |m, progress| messages << m if progress }
88
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
89
- @scraper.succeeded?.should be_true
90
- messages.size.should == 1
91
- File.directory?(@scraper.current_repo_dir).should be_true
92
- extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ]).should == @repo_content
93
- end
94
-
95
- it 'should scrape incrementally' do
96
- @scraper.scrape(@repo)
97
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
98
- @scraper.incremental_update?.should be_true
99
- messages = []
100
- @scraper.scrape(@repo) { |m, progress| messages << m if progress }
101
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
102
- @scraper.succeeded?.should be_true
103
- messages.size.should == 1
104
- File.directory?(@scraper.current_repo_dir).should be_true
105
- extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ]).should == @repo_content
106
- end
107
-
108
- end
109
-
110
- end