Added the first work on the scm post commit hooks.

This commit is contained in:
Loic d'Anterroches 2010-04-14 10:54:16 +02:00
parent 738a8bdd60
commit e5ee6d8fca
3 changed files with 112 additions and 2 deletions

22
scripts/git-post-update Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh
#
# This hook does only one thing:
#
# 1. It calls the gitpostupdate.php script with the current $GIT_DIR
# as argument. The gitpostupdate.php script will then trigger
# the 'gitpostupdate.php::run' event with the $GIT_DIR as argument
# together with merged $_ENV and $_SERVER array.
#
# This hook is normally installed automatically at the creation of your
# repository if you have everything configured correctly. If you want
# to enable it later, you need to symlink it as "post-update" in your
# $GIT_DIR/hooks folder.
#
# git$ cd /home/git/repositories/project.git/hooks
# git$ ln -s /home/www/indefero/scripts/git-post-update post-update
#
SCRIPTDIR=$(dirname $(readlink -f $0))
PHP_POST_UPDATE=$SCRIPTDIR/gitpostupdate.php
echo php $PHP_POST_UPDATE $GIT_DIR | at now

58
scripts/gitpostupdate.php Normal file
View File

@ -0,0 +1,58 @@
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008-2010 Céondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* This script will send the notifications after a push in your
* repository.
*/
require dirname(__FILE__).'/../src/IDF/conf/path.php';
require 'Pluf.php';
Pluf::start(dirname(__FILE__).'/../src/IDF/conf/idf.php');
Pluf_Dispatcher::loadControllers(Pluf::f('idf_views'));
/**
* [signal]
*
* gitpostupdate.php::run
*
* [sender]
*
* gitpostupdate.php
*
* [description]
*
* This signal allows an application to perform a set of tasks on a
* post update of a git repository.
*
* [parameters]
*
* array('git_dir' => '/path/to/git/repository.git',
* 'env' => array_merge($_ENV, $_SERVER));
*
*/
$params = array('git_dir' => $argv[1],
'env' => array_merge($_ENV, $_SERVER));
Pluf_Signal::send('gitpostupdate.php::run', 'gitpostupdate.php', $params);

View File

@ -42,11 +42,41 @@ class IDF_Plugin_SyncGit
*/ */
static public function entry($signal, &$params) static public function entry($signal, &$params)
{ {
Pluf_Log::event('IDF_Plugin_SyncGit called.');
// First check for the single mandatory config variable. // First check for the single mandatory config variable.
if (!Pluf::f('idf_plugin_syncgit_sync_file', false)) { if (!Pluf::f('idf_plugin_syncgit_sync_file', false)) {
Pluf_Log::debug('IDF_Plugin_SyncGit plugin not configured.');
return; return;
} }
@touch(Pluf::f('idf_plugin_syncgit_sync_file')); if ($signal != 'gitpostupdate.php::run') {
@chmod(Pluf::f('idf_plugin_syncgit_sync_file'), 0777); @touch(Pluf::f('idf_plugin_syncgit_sync_file'));
@chmod(Pluf::f('idf_plugin_syncgit_sync_file'), 0777);
} else {
self::postUpdate($signal, $params);
}
}
/**
* Entry point for the post-update signal.
*
* It tries to find the name of the project, when found it runs an
* update of the timeline.
*/
static public function postUpdate($signal, &$params)
{
// Find the corresponding project.
$git_dir = substr($params['git_dir'], 0, -4); // Chop the ".git"
$elts = explode('#/#', $git_dir, -1, PREG_SPLIT_NO_EMPTY);
$pname = array_pop($elts);
try {
$project = IDF_Project::getOr404($pname);
} catch (Pluf_HTTP_Error404 $e) {
Pluf_Log::event(array('IDF_Plugin_SyncGit::postUpdate', 'Project not found.', array($pname, $params)));
return false; // Project not found
}
// Now we have the project and can update the timeline
Pluf_Log::debug(array('IDF_Plugin_SyncGit::postUpdate', 'Project found', $pname, $project->id));
IDF_Scm::syncTimeline($project, true);
Pluf_Log::event(array('IDF_Plugin_SyncGit::postUpdate', 'sync', array($pname, $project->id)));
} }
} }