| 1 | require 'rubygems' |
|---|
| 2 | require 'rake' |
|---|
| 3 | require 'rake/clean' |
|---|
| 4 | |
|---|
| 5 | desc 'update svn log' |
|---|
| 6 | file '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] |
|---|
| 9 | end |
|---|
| 10 | |
|---|
| 11 | desc 'generate data file from svn_log.txt' |
|---|
| 12 | task '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 |
|---|
| 44 | end |
|---|
| 45 | |
|---|
| 46 | desc 'commit count by committer from svn_log.txt' |
|---|
| 47 | task '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 |
|---|
| 60 | end |
|---|
| 61 | |
|---|
| 62 | desc 'cleanbackup' |
|---|
| 63 | task :cleanbackup do |
|---|
| 64 | require 'pathname' |
|---|
| 65 | Pathname.glob('data/*/*.yaml.backup*') do |path| |
|---|
| 66 | path.delete |
|---|
| 67 | end |
|---|
| 68 | end |
|---|
| 69 | |
|---|
| 70 | task :clean => [:cleanbackup] |
|---|