root/lang/ruby/coderepos_stat/Rakefile

Revision 3094, 2.0 kB (checked in by walf443, 12 months ago)

lang/ruby/coderepos_stat/Rakefile: added task to count of commit by author.

Line 
1require 'rubygems'
2require 'rake'
3require 'rake/clean'
4
5desc 'update svn log'
6file 'svn_log.txt' do |t|
7  # FIXME: it's better to user can specify revision range and limit number
8  sh %[svn log --xml -v -r {2007-12-01}:HEAD http://svn.coderepos.org/share/ > svn_log.txt]
9end
10
11desc 'generate data file from svn_log.txt'
12task 'gendata' => ['svn_log.txt'] do
13  require 'hpricot'
14  require 'pathname'
15  require 'yaml'
16  require 'date'
17  doc = Hpricot.parse(open('svn_log.txt').read)
18  doc.search('/log/logentry') do |logentry|
19    # SEE: http://coderepos.org/share/wiki/commit-ping/SITEINFO
20    data = {}
21    data['author'] = logentry.search('/author').inner_text
22    data['comment'] = logentry.search('/msg').inner_text
23    date = DateTime.parse(logentry.search('/date').inner_text).new_offset('jst')
24    data['date'] = date.strftime('%Y-%m-%d %H:%M:%S %z')
25    data['files'] = []
26    logentry.search('/paths/path').each do |path|
27      file = {
28        'path'  => path.inner_text,
29        'status' => path['action'],
30      }
31      data['files'].push file
32    end
33    path = Pathname("data/#{date.strftime('%Y%m%d/commit-%H%M%S')}.yaml")
34    unless path.parent.exist?
35      path.parent.mkpath
36    end
37    if path.exist?
38      path.rename("#{path.to_s}.backup#{Time.now.strftime('%Y%m%d%H%M%S')}")
39    end
40    path.open('w') do |f|
41      YAML.dump(data, f)
42    end
43  end
44end
45
46desc 'commit count by committer from svn_log.txt'
47task 'commit_ranking' => ['svn_log.txt'] do
48  require 'hpricot'
49
50  doc = Hpricot.parse(open('svn_log.txt').read)
51  commit_count_of = Hash.new(0)
52  doc.search('/log/logentry') do |logentry|
53    author = logentry.search('/author').inner_text
54    commit_count_of[author] += 1
55  end
56  commit_count_of.sort_by {|key,val| -1 * val }.each do |arr|
57    author, commit_count = *arr
58    puts "#{author}\t#{commit_count}"
59  end
60end
61
62desc 'cleanbackup'
63task :cleanbackup do
64  require 'pathname'
65  Pathname.glob('data/*/*.yaml.backup*') do |path|
66    path.delete
67  end
68end
69
70task :clean => [:cleanbackup]
Note: See TracBrowser for help on using the browser.