svn_hooks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -0
- data/bin/svn_rubyhooks +35 -0
- data/lib/svn_dsl.rb +33 -0
- data/lib/svn_file_stat.rb +32 -0
- data/lib/svn_hooks.rb +11 -0
- data/lib/svn_stat.rb +46 -0
- data/test/svn_hooks_test.rb +15 -0
- data/test/test_helper.rb +4 -0
- metadata +57 -0
data/README
ADDED
data/bin/svn_rubyhooks
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'ftools'
|
5
|
+
|
6
|
+
HOOK_TYPES = %w{post-commit post-lock post-revprop-change post-unlock pre-commit pre-lock pre-revprop-change pre-unlock start-commit}
|
7
|
+
HOOK_TEMPLATE = <<-END_TEMPLATE
|
8
|
+
#!#{`which ruby`.chomp}
|
9
|
+
|
10
|
+
Dir.chdir(File.dirname(__FILE__))
|
11
|
+
SVN_EVENT = File.basename(__FILE__)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'svn_hooks'
|
15
|
+
END_TEMPLATE
|
16
|
+
|
17
|
+
base_path = ARGV[0] || '.'
|
18
|
+
|
19
|
+
if(File.directory? File.join(base_path, 'hooks'))
|
20
|
+
# create hook files using HOOK_TEMPLATE
|
21
|
+
path = File.join(base_path, 'hooks')
|
22
|
+
HOOK_TYPES.each do |type|
|
23
|
+
filename = File.join(path, type)
|
24
|
+
|
25
|
+
# move old files out of the way
|
26
|
+
File.rename(filename, filename+'.old') if File.exists?(filename)
|
27
|
+
open(filename, 'w'){|f| f.write(HOOK_TEMPLATE)}
|
28
|
+
File.chmod(0755, filename)
|
29
|
+
end
|
30
|
+
|
31
|
+
# create path for hook scripts
|
32
|
+
File.makedirs File.join(path, 'scripts')
|
33
|
+
else
|
34
|
+
puts 'Usage: ruby install.rb /path/to/svn/repostiory'
|
35
|
+
end
|
data/lib/svn_dsl.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module SVN
|
2
|
+
module DSL
|
3
|
+
|
4
|
+
def for_path (*searches, &proc)
|
5
|
+
# searches = [search] if !search.kind_of?(Array)
|
6
|
+
searches = searches.map{|search| Regexp.glob(search)}
|
7
|
+
file_paths = EVENT_STATS.files.map{|f| f.path}
|
8
|
+
|
9
|
+
searches.each do |search|
|
10
|
+
if(file_paths.grep(search).length > 0)
|
11
|
+
return yield(EVENT_STATS) if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
alias for_paths for_path
|
17
|
+
|
18
|
+
def for_action(*searches, &proc)
|
19
|
+
if(searches.include? SVN_EVENT)
|
20
|
+
yield(EVENT_STATS) if block_given?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
alias for_actions for_action
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Regexp
|
30
|
+
def self.glob(search)
|
31
|
+
Regexp.new('^' + Regexp.escape(search).gsub('\\*', '.*') + '$', true)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SVN
|
2
|
+
FLAGS = {
|
3
|
+
'A' => :added,
|
4
|
+
'C' => :conflict,
|
5
|
+
'D' => :deleted,
|
6
|
+
'M' => :modified,
|
7
|
+
'U' => :updated,
|
8
|
+
'R' => :replaced,
|
9
|
+
'G' => :merged
|
10
|
+
}
|
11
|
+
|
12
|
+
class FileStat
|
13
|
+
|
14
|
+
attr_reader :path, :file_flag, :meta_flag, :lock_flag, :history_flag
|
15
|
+
|
16
|
+
def self.parse line
|
17
|
+
@file_flag = SVN::FLAGS[line[0,1]]
|
18
|
+
@meta_flag = SVN::FLAGS[line[1,1]]
|
19
|
+
@lock_flag = SVN::FLAGS[line[2,1]] == 'L'
|
20
|
+
@history_flag = SVN::FLAGS[line[3,1]] == '+'
|
21
|
+
@path = line[5,-1]
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
@path
|
26
|
+
end
|
27
|
+
|
28
|
+
def modified?
|
29
|
+
[:merged, :updated, :modified, :replaced].find{|a| a == @file_flag}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/svn_hooks.rb
ADDED
data/lib/svn_stat.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'svn_file_stat'
|
2
|
+
|
3
|
+
module SVN
|
4
|
+
class Stat
|
5
|
+
attr_reader :repository_path, :revision_number, :event
|
6
|
+
|
7
|
+
def initialize repository_path, revision_number = nil
|
8
|
+
@revision = revision_number
|
9
|
+
@repository_path = repository_path
|
10
|
+
@event = SVN_EVENT
|
11
|
+
|
12
|
+
@svnlook_path = `which svnlook`.chomp
|
13
|
+
end
|
14
|
+
|
15
|
+
def author
|
16
|
+
@author ||= svnlook "author"
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
@message ||= svnlook "cat"
|
21
|
+
end
|
22
|
+
|
23
|
+
def date
|
24
|
+
@date ||= Date.parse(svnlook("date"))
|
25
|
+
end
|
26
|
+
|
27
|
+
def files
|
28
|
+
unless @files
|
29
|
+
@files = []
|
30
|
+
svnlook('changed').each_line{|l| @files << SVN::FileStat.parse(l)}
|
31
|
+
end
|
32
|
+
|
33
|
+
@files
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def revision_string
|
39
|
+
@revision_number ? "--revision #{@revision_number}" : ''
|
40
|
+
end
|
41
|
+
|
42
|
+
def svnlook query
|
43
|
+
`#{@svnlook_path} #{query} #{@repository_path} #{revision_string}`.chomp
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: svn_hooks
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-11-25 00:00:00 -08:00
|
8
|
+
summary: svn_hooks
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- lib
|
12
|
+
- lib
|
13
|
+
email: grijalva@gmail.com
|
14
|
+
homepage: http://rubyforge.org/projects/svn-hooks/
|
15
|
+
rubyforge_project:
|
16
|
+
description: A domain specific language for implementing svn repository hooks in Ruby.
|
17
|
+
autorequire:
|
18
|
+
- svn_stat
|
19
|
+
- svn_hooks
|
20
|
+
- svn_file_stat
|
21
|
+
- svn_dsl
|
22
|
+
default_executable:
|
23
|
+
bindir: bin
|
24
|
+
has_rdoc: false
|
25
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.0
|
30
|
+
version:
|
31
|
+
platform: ruby
|
32
|
+
signing_key:
|
33
|
+
cert_chain:
|
34
|
+
post_install_message:
|
35
|
+
authors:
|
36
|
+
- Dave Grijalva
|
37
|
+
files:
|
38
|
+
- lib/svn_dsl.rb
|
39
|
+
- lib/svn_file_stat.rb
|
40
|
+
- lib/svn_hooks.rb
|
41
|
+
- lib/svn_stat.rb
|
42
|
+
- README
|
43
|
+
test_files:
|
44
|
+
- test/svn_hooks_test.rb
|
45
|
+
- test/test_helper.rb
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
extra_rdoc_files: []
|
49
|
+
|
50
|
+
executables:
|
51
|
+
- svn_rubyhooks
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
dependencies: []
|
57
|
+
|