2012年9月17日月曜日

SVNとIRC連携の巻

SVNコミットをIRCに通知してみる。
SVNにはpost-commitがあるから、たぶん楽勝。

環境もなんでもいいんだろうけど、手っ取り早そうなPHPで。

pearライブラリ検索
> pear search IR
Retrieving data...0%
.MATCHED PACKAGES, CHANNEL PEAR.PHP.NET:
=======================================
PACKAGE      STABLE/(LATEST) LOCAL
Net_IRC      0.0.7 (beta)          IRC Client Class
Net_SmartIRC 1.0.2 (stable)  1.0.2 Net_SmartIRC is a PHP class for communication with IRC networks
ネット見たらSmartIRCのほうがよさそう。

かいた。
<?php
// (*´・ω・)(・ω・`*)< イマイチ!
include_once('Net/SmartIRC.php');
if(count($argv) != 4){
die("error! invalid argment [php xxx.php 'author' 'log' 'changes']");
}
class mybot
{
function irc_disconnect(&$irc)
{
global $saytime_once_id;
$irc->unregisterTimeid($saytime_once_id);
$irc->quit('bye');
}
}
$bot = &new mybot();
$irc = &new Net_SmartIRC();
$irc->setDebug(SMARTIRC_DEBUG_NOTICE);
//$irc->setDebug(SMARTIRC_DEBUG_ALL);
$irc->setUseSockets(TRUE);
$saytime_once_id = $irc->registerTimehandler(3000, $bot, 'irc_disconnect');
// チャンネルにjoin
$irc->connect('irc.server.host', 6667);
$irc->login('svn-bot', 'bot', 8, 'bot');
$irc->join(array('#sandbox'));
// メッセージ送信
$message = 'SVN Updated!' . " [" . $argv[1] . "][" . $argv[2] . "][" . $argv[3] . "]";
$irc->message(SMARTIRC_TYPE_CHANNEL, '#sandbox', $message);
$irc->listen();
$irc->disconnect();
?>
view raw gistfile1.php hosted with ❤ by GitHub
サーバに置いて、post-commit変更
[root@hoge hooks]# vi post-commit
#!/bin/s
AUTHOR=`svnlook author -r $REV $REPOS`
LOG=`svnlook log -r $REV $REPOS`
CHANGES=`svnlook changed -r $REV $REPOS`
php /home/e2info/developer/svn-irc.php "$AUTHOR" "$LOG" "$CHANGES"

どうかな


できた!!日本語よめないのはめんどくさいからまた今度で。

(*´・ω・)かねこ(・ω・`*)

0 件のコメント:

コメントを投稿