blastr 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -1
- data/lib/blastr.rb +8 -18
- data/lib/scm/git.rb +2 -3
- data/lib/scm/hg.rb +2 -2
- data/lib/scm/svn.rb +1 -1
- data/test/people/test_people.rb +1 -1
- data/test/scm/test_git.rb +1 -1
- data/test/scm/test_svn.rb +1 -1
- data/test/test_blastr.rb +67 -1
- data/test/test_filesystem.rb +34 -0
- metadata +5 -3
data/Rakefile
CHANGED
@@ -3,6 +3,8 @@ require 'hoe'
|
|
3
3
|
$:.unshift(File.dirname(__FILE__) + "/lib")
|
4
4
|
require File.expand_path(File.join(File.dirname(__FILE__), 'lib/blastr'))
|
5
5
|
|
6
|
+
Hoe.plugin :git
|
7
|
+
|
6
8
|
Hoe.spec 'blastr' do
|
7
9
|
name = "blastr"
|
8
10
|
developer('Lasse Koskela', 'lasse.koskela@gmail.com')
|
@@ -14,6 +16,6 @@ Hoe.spec 'blastr' do
|
|
14
16
|
remote_rdoc_dir = '' # Release to root
|
15
17
|
rsync_args = '-av --delete --ignore-errors'
|
16
18
|
extra_deps = [
|
17
|
-
['git','>= 1.
|
19
|
+
['git','>= 1.2.5'],
|
18
20
|
]
|
19
21
|
end
|
data/lib/blastr.rb
CHANGED
@@ -3,26 +3,20 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) unless
|
|
3
3
|
|
4
4
|
module Blastr
|
5
5
|
require File.expand_path(File.join(File.dirname(__FILE__), 'error.rb'))
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'filesystem.rb'))
|
6
7
|
require File.expand_path(File.join(File.dirname(__FILE__), 'scm/scm.rb'))
|
7
8
|
require File.expand_path(File.join(File.dirname(__FILE__), 'tts/tts.rb'))
|
8
9
|
require File.expand_path(File.join(File.dirname(__FILE__), 'people/people.rb'))
|
9
10
|
|
10
|
-
VERSION = '0.1.
|
11
|
+
VERSION = '0.1.1'
|
11
12
|
COPYRIGHT = "Copyright (c) 2009-#{Time.now.year}, Lasse Koskela. All Rights Reserved."
|
12
13
|
|
13
14
|
def self.trap_and_exit(signal)
|
14
15
|
trap(signal) {
|
15
|
-
puts ""
|
16
|
+
puts "\nBye!"
|
16
17
|
exit 0
|
17
18
|
}
|
18
19
|
end
|
19
|
-
|
20
|
-
def self.delete_at_exit(file_or_directory)
|
21
|
-
at_exit do
|
22
|
-
puts "Cleaning up leftovers: #{temp_dir}" if File.directory?(temp_dir) if $DEBUG
|
23
|
-
FileUtils.remove_dir(temp_dir, :force => true)
|
24
|
-
end
|
25
|
-
end
|
26
20
|
|
27
21
|
class Process
|
28
22
|
def initialize(args)
|
@@ -36,7 +30,7 @@ module Blastr
|
|
36
30
|
|
37
31
|
def run
|
38
32
|
puts "Polling #{@scm.name} commits since revision #{@since_revision}..."
|
39
|
-
while
|
33
|
+
while should_run?
|
40
34
|
announce_new_commits
|
41
35
|
sleep 30
|
42
36
|
end
|
@@ -48,6 +42,9 @@ module Blastr
|
|
48
42
|
end
|
49
43
|
|
50
44
|
private
|
45
|
+
|
46
|
+
def should_run? ; true ; end
|
47
|
+
|
51
48
|
def announce_new_commits
|
52
49
|
@scm.commits_since(@since_revision.to_s).each do |commit|
|
53
50
|
if @since_revision.before?(commit.revision)
|
@@ -56,16 +53,9 @@ module Blastr
|
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
56
|
+
|
59
57
|
def validate(args=[])
|
60
58
|
raise UsageError.new if args.size == 0 or args.size > 2
|
61
59
|
end
|
62
60
|
end
|
63
|
-
|
64
|
-
def Blastr::temp_dir
|
65
|
-
temp_file = Tempfile.new("tmp")
|
66
|
-
temp_dir = temp_file.path
|
67
|
-
temp_file.unlink
|
68
|
-
FileUtils.mkdir_p(temp_dir)
|
69
|
-
temp_dir
|
70
|
-
end
|
71
61
|
end
|
data/lib/scm/git.rb
CHANGED
@@ -57,7 +57,6 @@ module Blastr::SourceControl
|
|
57
57
|
|
58
58
|
def as_revision(arg)
|
59
59
|
raise "Invalid revision: #{arg}" unless arg =~ /^(HEAD(~\d+)?)|([\d\w:-]+)$/
|
60
|
-
obj = nil
|
61
60
|
revision = nil
|
62
61
|
with_clone do |clone|
|
63
62
|
obj = clone.object(arg.to_s)
|
@@ -91,8 +90,8 @@ module Blastr::SourceControl
|
|
91
90
|
end
|
92
91
|
|
93
92
|
def with_clone
|
94
|
-
temp_dir = Blastr::temp_dir
|
95
|
-
Blastr::delete_at_exit(temp_dir)
|
93
|
+
temp_dir = Blastr::FileSystem.temp_dir
|
94
|
+
Blastr::FileSystem.delete_at_exit(temp_dir)
|
96
95
|
begin
|
97
96
|
clone = ::Git.clone(@git_url, temp_dir)
|
98
97
|
clone.chdir do
|
data/lib/scm/hg.rb
CHANGED
@@ -74,8 +74,8 @@ module Blastr::SourceControl
|
|
74
74
|
|
75
75
|
private
|
76
76
|
def with_clone
|
77
|
-
clone_dir = Blastr::temp_dir
|
78
|
-
Blastr::delete_at_exit(clone_dir)
|
77
|
+
clone_dir = Blastr::FileSystem.temp_dir
|
78
|
+
Blastr::FileSystem::delete_at_exit(clone_dir)
|
79
79
|
%x[hg clone #{@repo_url} #{clone_dir}]
|
80
80
|
current_dir = Dir.pwd
|
81
81
|
Dir.chdir(clone_dir)
|
data/lib/scm/svn.rb
CHANGED
@@ -86,7 +86,7 @@ module Blastr::SourceControl
|
|
86
86
|
|
87
87
|
def svn_log(since_revision = as_revision("1"))
|
88
88
|
temp_file = Tempfile.new("svn.log").path
|
89
|
-
Blastr::delete_at_exit(temp_file)
|
89
|
+
Blastr::FileSystem::delete_at_exit(temp_file)
|
90
90
|
begin
|
91
91
|
revision = "#{since_revision}:#{as_revision('HEAD')}"
|
92
92
|
revision = as_revision("HEAD") if since_revision.to_s == as_revision("HEAD").to_s
|
data/test/people/test_people.rb
CHANGED
@@ -28,7 +28,7 @@ class TestPeopleFile < Test::Unit::TestCase
|
|
28
28
|
private
|
29
29
|
def backup_people_file
|
30
30
|
people_file = Blastr::People::PEOPLE_FILE
|
31
|
-
@backup_of_people_file = File.join(Blastr::temp_dir, File.basename(people_file))
|
31
|
+
@backup_of_people_file = File.join(Blastr::FileSystem.temp_dir, File.basename(people_file))
|
32
32
|
FileUtils.cp(people_file, @backup_of_people_file)
|
33
33
|
end
|
34
34
|
def restore_people_file
|
data/test/scm/test_git.rb
CHANGED
data/test/scm/test_svn.rb
CHANGED
data/test/test_blastr.rb
CHANGED
@@ -1,6 +1,28 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper.rb'))
|
2
|
+
require 'mocha'
|
2
3
|
|
3
|
-
|
4
|
+
module Blastr
|
5
|
+
class Process
|
6
|
+
attr_accessor :scm
|
7
|
+
attr_reader :seconds_slept
|
8
|
+
|
9
|
+
# override sleep() to speed up test runs
|
10
|
+
def sleep(seconds)
|
11
|
+
@seconds_slept ||= 0
|
12
|
+
@seconds_slept += seconds
|
13
|
+
end
|
14
|
+
|
15
|
+
# override should_run? to make the process
|
16
|
+
# stop after three polling iterations
|
17
|
+
def should_run?
|
18
|
+
@iterations ||= 0
|
19
|
+
@iterations += 1
|
20
|
+
@iterations <= 3
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class TestBlastrProcessArguments < Test::Unit::TestCase
|
4
26
|
def test_command_line_arguments_are_validated
|
5
27
|
assert_raise Blastr::UsageError do
|
6
28
|
Blastr::Process.new([])
|
@@ -12,4 +34,48 @@ class TestBlastrProcess < Test::Unit::TestCase
|
|
12
34
|
Blastr::Process.new(["http://svn.com", "123"])
|
13
35
|
end
|
14
36
|
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class TestBlastrProcess < Test::Unit::TestCase
|
40
|
+
def setup
|
41
|
+
@since_revision = '1'
|
42
|
+
@process = create_blastr_process_polling("http://svn.com", @since_revision)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_polls_for_new_commits_every_30_seconds
|
46
|
+
@process.expects(:announce_new_commits).times(3)
|
47
|
+
@process.run
|
48
|
+
assert_equal 3*30, @process.seconds_slept
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_announcing_all_new_commits
|
52
|
+
commits = [ fake_commit('2'), fake_commit('3') ]
|
53
|
+
commit_sequence = sequence('commit sequence')
|
54
|
+
@process.scm.expects(:commits_since).with(@since_revision).returns(commits)
|
55
|
+
@process.expects(:announce).with(commits.first).in_sequence(commit_sequence)
|
56
|
+
@process.expects(:announce).with(commits.last).in_sequence(commit_sequence)
|
57
|
+
@process.send(:announce_new_commits)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_announcing_a_given_commit
|
61
|
+
commit = fake_commit('42')
|
62
|
+
Blastr::People.stubs(:full_name_of).returns('Full Name')
|
63
|
+
Blastr::TTS.expects(:speak).with("Commit by Full Name: #{commit.comment}")
|
64
|
+
@process.expects(:puts).with("[#{commit.revision}] Commit by #{commit.author}: #{commit.comment}")
|
65
|
+
@process.announce(commit)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def fake_commit(rev)
|
71
|
+
revision = Blastr::SourceControl::SubversionRevision.new(rev)
|
72
|
+
Blastr::SourceControl::LogEntry.new(revision, 'author', 'comment')
|
73
|
+
end
|
74
|
+
|
75
|
+
def create_blastr_process_polling(url, since_revision)
|
76
|
+
process = Blastr::Process.new([url, since_revision])
|
77
|
+
process.scm = mock()
|
78
|
+
process.scm.class.any_instance.stubs(:name).returns('Fake')
|
79
|
+
process
|
80
|
+
end
|
15
81
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper.rb'))
|
2
|
+
|
3
|
+
module Blastr::FileSystem
|
4
|
+
# intercept calls to Kernel.at_exit to allow invoking
|
5
|
+
# registered at_exit blocks before the process exits
|
6
|
+
def self.at_exit(&block)
|
7
|
+
@at_exit_blocks ||= []
|
8
|
+
@at_exit_blocks << block
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.execute_all_at_exit_blocks
|
12
|
+
@at_exit_blocks.each { |block| block.call }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class FileSystemTest < Test::Unit::TestCase
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@file_to_delete = File.expand_path(File.join(Blastr::FileSystem.temp_dir, 'file_to_be_deleted'))
|
20
|
+
FileUtils.touch(@file_to_delete)
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
FileUtils.rm(@file_to_delete) if File.exist?(@file_to_delete)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_delete_at_exit
|
28
|
+
Blastr::FileSystem.delete_at_exit(@file_to_delete)
|
29
|
+
assert File.exist?(@file_to_delete)
|
30
|
+
Blastr::FileSystem.execute_all_at_exit_blocks
|
31
|
+
assert ! File.exist?(@file_to_delete)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blastr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lasse Koskela
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- test/test_helper.rb
|
105
105
|
- test/tts/test_tts.rb
|
106
106
|
- website/index.html
|
107
|
+
- test/test_filesystem.rb
|
107
108
|
has_rdoc: true
|
108
109
|
homepage: http://rubyforge.org/projects/blastr/
|
109
110
|
licenses: []
|
@@ -152,5 +153,6 @@ test_files:
|
|
152
153
|
- test/scm/test_svn_log.rb
|
153
154
|
- test/scm/test_svn_revision.rb
|
154
155
|
- test/test_blastr.rb
|
156
|
+
- test/test_filesystem.rb
|
155
157
|
- test/test_helper.rb
|
156
158
|
- test/tts/test_tts.rb
|