To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / extra / soundsoftware / create-repo-authormaps.rb @ 1544:e9e55585ebf2

History | View | Annotate | Download (2.46 KB)

1
#!/usr/bin/env ruby
2

    
3
# Create authormap files for hg repos based on the changeset & project
4
# member info available to Redmine.
5
#
6
# We have a set of hg repos in a given directory:
7
#
8
# /var/hg/repo_1
9
# /var/hg/repo_2
10
# /var/hg/repo_3
11
#
12
# and we want to produce authormap files in another directory:
13
#
14
# /var/repo-export/authormap/authormap_repo_1
15
# /var/repo-export/authormap/authormap_repo_2
16
# /var/repo-export/authormap/authormap_repo_3
17
#
18
# This script does that, if given the two directory names as arguments
19
# to the -s and -o options. In the above example:
20
#
21
# script/rails runner create-repo-authormaps.rb -s /var/hg -o /var/repo-export/authormap
22
#
23
# Note that this script will overwrite any existing authormap
24
# files. (That's why the output files are given an authormap_ prefix,
25
# so we're less likely to clobber something else if the user gets the
26
# arguments wrong.)
27

    
28
require 'getoptlong'
29

    
30
opts = GetoptLong.new(
31
                      ['--scm-dir',      '-s', GetoptLong::REQUIRED_ARGUMENT],
32
                      ['--out-dir',      '-o', GetoptLong::REQUIRED_ARGUMENT],
33
                      ['--environment',  '-e', GetoptLong::REQUIRED_ARGUMENT]
34
)
35

    
36
$repos_base   = ''
37
$out_base     = ''
38

    
39
def usage
40
  puts "See source code for supported options"
41
  exit
42
end
43

    
44
begin
45
  opts.each do |opt, arg|
46
    case opt
47
    when '--scm-dir';   $repos_base   = arg.dup
48
    when '--out-dir';   $out_base     = arg.dup
49
    end
50
  end
51
rescue
52
  exit 1
53
end
54

    
55
if ($repos_base.empty? or $out_base.empty?)
56
  usage
57
end
58

    
59
unless File.directory?($repos_base)
60
  puts "input directory '#{$repos_base}' doesn't exist"
61
  exit 1
62
end
63

    
64
unless File.directory?($out_base)
65
  puts "output directory '#{$out_base}' doesn't exist"
66
  exit 1
67
end
68

    
69
projects = Project.find(:all)
70

    
71
if projects.nil?
72
  puts 'No projects found'
73
  exit 1
74
end
75

    
76
projects.each do |proj|
77
  next unless proj.respond_to?(:repository)
78

    
79
  repo = proj.repository
80
  next if repo.nil? or repo.url.empty?
81

    
82
  repo_url = repo.url
83
  repo_url = repo_url.gsub(/^file:\/*/, "/");
84
  if repo_url != File.join($repos_base, proj.identifier)
85
    puts "Project #{proj.identifier} has repo in unsupported location #{repo_url}, skipping"
86
    next
87
  end
88

    
89
  committers = repo.committers
90

    
91
  authormap = ""
92
  committers.each do |c, uid|
93
    if not c =~ /[^<]+<.*@.*>/ then
94
      user = User.find_by_id uid
95
      authormap << "#{c}=#{user.name} <#{user.mail}>\n" unless user.nil?
96
    end
97
  end
98

    
99
  File.open(File.join($out_base, "authormap_#{proj.identifier}"), "w") do |f|
100
    f.puts(authormap)
101
  end
102

    
103
end
104