LoginSignup
2
1

More than 5 years have passed since last update.

[subversion]指定ファイルの最新ログから任意の情報を取得したい

Last updated at Posted at 2018-07-05

svnの更新通知がほしいなぁ。
でもフックスクリプトをsvnサーバーへ置く権限はないなぁ。。。
ログから必要な情報を取得して通知する機能を実現してみよう
 ⇒ 今回はログから必要な情報をパースするためのスクリプトを書いてみる

対象

  • subversionを使用している
  • 指定ファイルの最新ログがほしい
  • 指定ファイルのリストは別ファイルとして持っていたい
  • 全部ではなく必要な情報だけほしい
  • Rubyでやってみたい(Rubyしか使えない)

準備するもの

  • Rubyが動く環境

ファイル構成

./list      :svnのファイルパスが書かれたファイル
./svnlog.rb :ログ取得、パースを行うrubyスクリプト

ファイルの内容

listへはログを出力したいファイルパスを列挙

list
svn://<ファイルパス>
http://<ファイルパス>
svnlog.rb
#!/usr/bin/env ruby
#listに記載されたファイルの最新ログをxml形式で取得し、必要な情報をパースするためのrubyスクリプト

require 'rexml/document'

#listの内容を1行ずつ読み込む
files = []
File.foreach(ARGV[0]) do |line|
  files.push(line.chomp)
end

#svnからlistの記載されたファイルの最新ログをxml形式で取得
logs = []
for file in files do
  command = "svn log -l 1 --xml " + file
  log = `#{command}`
  logs.push(log)
end

#日付/コミットユーザー/コメントをログからパース
dates = []
authors = []
comments = []
for log in logs do
  xml = REXML::Document.new(log)
  dates.push(xml.elements['log/logentry/date'].text)
  authors.push(xml.elements['log/logentry/author'].text)
  comments.push(xml.elements['log/logentry/msg'].text)
end

puts(dates)
puts(authors)
puts(comments)

実行方法

  • list, svnlog.rb があるフォルダへ移動し、下記コマンドを実行
ruby ./svnlog.rb list
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1