[vhffs-dev] [2049] Reworked Git robots the same way we did for Cvs,Bazaar and Svn

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 2049
Author:   gradator
Date:     2012-02-25 01:50:48 +0100 (Sat, 25 Feb 2012)
Log Message:
-----------
Reworked Git robots the same way we did for Cvs,Bazaar and Svn

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Git.pm
    trunk/vhffs-robots/Makefile.am

Added Paths:
-----------
    trunk/vhffs-robots/src/git.pl

Removed Paths:
-------------
    trunk/vhffs-robots/src/git_create.pl
    trunk/vhffs-robots/src/git_delete.pl
    trunk/vhffs-robots/src/git_public.pl

Modified: trunk/vhffs-api/src/Vhffs/Robots/Git.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Git.pm	2012-02-25 00:27:28 UTC (rev 2048)
+++ trunk/vhffs-api/src/Vhffs/Robots/Git.pm	2012-02-25 00:50:48 UTC (rev 2049)
@@ -37,32 +37,34 @@
 use File::Basename;
 use File::Copy;
 
-package Vhffs::Robots::Git;
-
-use Vhffs::Services::Git;
 use Vhffs::Constants;
 use Vhffs::Functions;
 use Vhffs::Robots;
+use Vhffs::Services::Git;
 
-sub create_repo {
+package Vhffs::Robots::Git;
+
+sub create {
 	my $git = shift;
-	return -1 unless defined $git;
-	return -1 if $git->get_status != Vhffs::Constants::WAITING_FOR_CREATION;
+	return undef unless defined $git and $git->get_status == Vhffs::Constants::WAITING_FOR_CREATION;
 
+	my $vhffs = $git->get_main;
 	my $dir = $git->get_dir;
 
 	if( -e $dir ) {
 		$git->set_status( Vhffs::Constants::CREATION_ERROR );
 		$git->commit();
-		$git->add_history('Error, directory of this git repository already exists! Administrators must fix the problem.');
-		return -1;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating git repository '.$git->get_reponame.' to the filesystem' );
+		return undef;
 	}
 
-	# TODO: check make_path
-	File::Path::make_path( $dir );
-	Vhffs::Robots::chmod_recur( $dir , 0664 , 02775 );
-	Vhffs::Robots::chown_recur( $dir , $git->get_owner_uid , $git->get_owner_gid );
-	$git->add_history('Ok, robots find the empty directory and will create git repository');
+	File::Path::make_path( $dir, { error => \my $errors });
+	if(@$errors) {
+		$git->set_status( Vhffs::Constants::CREATION_ERROR );
+		$git->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating git repository '.$git->get_reponame.' to the filesystem' );
+		return undef;
+	}
 
 	my $oldcwd = Cwd::getcwd();
 	if( chdir($dir) ) {
@@ -81,37 +83,76 @@
 
 	unless( -f $dir.'/config' ) {
 		$git->set_status( Vhffs::Constants::CREATION_ERROR );
-		$git->commit();
-		$git->add_history('Error, nothing was created after calling the git binary, something is wrong.');
-		return -1;
+		$git->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating git repository '.$git->get_reponame.' to the filesystem' );
+		return undef;
 	}
 
-	# Write a description to enhance pushed mails.
-	open( my $description, '>', $dir.'/description' );
-	print $description $git->get_reponame."\n";
-	close( $description );
-
 	Vhffs::Robots::chmod_recur( $dir, 0664, 02775 );
 	Vhffs::Robots::chown_recur( $dir, $git->get_owner_uid, $git->get_owner_gid );
 
 	# './hooks' directory must be owned by root to prevent abuse of servers
-	Vhffs::Robots::chmod_recur( $dir.'/hooks' , 0644 , 0755 );
-	Vhffs::Robots::chown_recur( $dir.'/hooks' , 0 , 0 );
+	Vhffs::Robots::chmod_recur( $dir.'/hooks', 0644, 0755 );
+	Vhffs::Robots::chown_recur( $dir.'/hooks', 0, 0 );
 
-	$git->add_history('The Robots created the git repository');
-	$git->set_status( Vhffs::Constants::ACTIVATED );
-	$git->commit;
+	Vhffs::Robots::vhffs_log( $vhffs, 'Created git repository '.$git->get_reponame );
+	return modify( $git );
+}
 
-	return 0;
+sub delete {
+	my $git = shift;
+	return undef unless defined $git and $git->get_status == Vhffs::Constants::WAITING_FOR_DELETION;
+
+	my $vhffs = $git->get_main;
+	my $dir = $git->get_dir;
+
+	Vhffs::Robots::archive_targz( $git, $dir );
+
+	File::Path::remove_tree( $dir, { error => \my $errors });
+	my $groupdir = File::Basename::dirname($dir);
+	rmdir($groupdir);
+
+	if(@$errors) {
+		$git->set_status( Vhffs::Constants::DELETION_ERROR );
+		$git->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while removing git repository '.$git->get_reponame.' from the filesystem' );
+		return undef;
+	}
+
+	if( $git->delete ) {
+		Vhffs::Robots::vhffs_log( $vhffs, 'Deleted git repository '.$git->get_reponame );
+	} else {
+		$git->set_status( Vhffs::Constants::DELETION_ERROR );
+		$git->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while deleting git repository '.$git->get_reponame.' object' );
+		return undef;
+	}
+
+	return 1;
 }
 
-sub change_conf {
+sub modify {
 	my $git = shift;
-	return -1 unless defined $git;
+	return undef unless defined $git and ( $git->get_status == Vhffs::Constants::WAITING_FOR_MODIFICATION or $git->get_status == Vhffs::Constants::WAITING_FOR_CREATION );
 
+	my $vhffs = $git->get_main;
 	my $dir = $git->get_dir;
-	my $mail_from = $git->get_main->get_config->get_service('git')->{notify_from};
 
+	if( $git->is_public ) {
+		chmod 02775, $dir;
+
+		Vhffs::Robots::vhffs_log( $vhffs, 'Svn repository '.$git->get_reponame.' is now public' );
+		$git->add_history( 'Is now public');
+	}
+	else {
+		chmod 02770, $dir;
+
+		Vhffs::Robots::vhffs_log( $vhffs, 'Svn repository '.$git->get_reponame.' is now private' );
+		$git->add_history( 'Is now private');
+	}
+
+	my $mail_from = $git->get_main->get_config->get_service('git')->{'notify_from'};
+
 	# Always unlink since git init create a dummy post-receive
 	unlink $dir.'/hooks/post-receive';
 
@@ -127,7 +168,11 @@
 				# wait for the child to finish
 				waitpid( $childpid, 0 );
 
-				# TODO: check if git config succedded
+				if( $? ) {
+					$git->set_status( Vhffs::Constants::MODIFICATION_ERROR );
+					$git->commit;
+					return undef;
+				} 
 			}
 		}
 
@@ -140,30 +185,34 @@
 				# wait for the child to finish
 				waitpid( $childpid, 0 );
 
-				# TODO: check if git config succedded
+				if( $? ) {
+					$git->set_status( Vhffs::Constants::MODIFICATION_ERROR );
+					$git->commit;
+					return undef;
+				} 
 			}
 		}
+
+		Vhffs::Robots::vhffs_log( $vhffs, 'Git repository '.$git->get_reponame.' commit mail set to '.$git->{ml_name} );
+		$git->add_history( 'Commit mail set to '.$git->{ml_name} );
 	}
 
-	return 0;
-}
+	# Write a description to enhance pushed mails.
+	open( my $description, '>', $dir.'/description' );
+	unless( defined $description ) {
+		$git->set_status( Vhffs::Constants::MODIFICATION_ERROR );
+		$git->commit;
+		return undef;
+	}
 
-sub delete_repo
-{
-	my $git = shift;
-	return -1 unless defined $git;
+	print $description $git->get_reponame."\n";
+	close( $description );
+	chmod 0664, $dir.'/description';
 
-	# Remove GIT dir and group dir if empty
-	my $dir = $git->get_dir;
-	Vhffs::Robots::archive_targz( $git, $dir );
+	$git->set_status( Vhffs::Constants::ACTIVATED );
+	$git->commit;
 
-	# TODO: check remove_tree
-	File::Path::remove_tree($dir) if(-d $dir);
-	my $groupdir = File::Basename::dirname($dir);
-	rmdir($groupdir);
-
-	return 0;
+	return 1;
 }
 
-
 1;

Modified: trunk/vhffs-robots/Makefile.am
===================================================================
--- trunk/vhffs-robots/Makefile.am	2012-02-25 00:27:28 UTC (rev 2048)
+++ trunk/vhffs-robots/Makefile.am	2012-02-25 00:50:48 UTC (rev 2049)
@@ -49,9 +49,7 @@
 	src/repository_quota.pl \
 	src/repository_stats.pl \
 	src/svn.pl \
-	src/git_create.pl \
-	src/git_delete.pl \
-	src/git_public.pl \
+	src/git.pl \
 	src/mercurial_create.pl \
 	src/mercurial_delete.pl \
 	src/mercurial_public.pl \

Copied: trunk/vhffs-robots/src/git.pl (from rev 2043, trunk/vhffs-robots/src/git_create.pl)
===================================================================
--- trunk/vhffs-robots/src/git.pl	                        (rev 0)
+++ trunk/vhffs-robots/src/git.pl	2012-02-25 00:50:48 UTC (rev 2049)
@@ -0,0 +1,60 @@
+#!%PERL%
+# Copyright (c) vhffs project and its contributors
+# Copyright (c) 2007 Julien Danjou <julien@xxxxxxxxxxx>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without 
+# modification, are permitted provided that the following conditions 
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright 
+#   notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in 
+#   the documentation and/or other materials provided with the 
+#   distribution.
+#3. Neither the name of vhffs nor the names of its contributors 
+#   may be used to endorse or promote products derived from this 
+#   software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+# POSSIBILITY OF SUCH DAMAGE.
+
+use strict;
+use utf8;
+
+use lib '%VHFFS_LIB_DIR%';
+use Vhffs::Robots::Git;
+
+my $vhffs = init Vhffs::Main;
+exit 1 unless defined $vhffs;
+
+Vhffs::Robots::lock( $vhffs, 'git' );
+
+my $repos = Vhffs::Services::Git::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
+foreach ( @{$repos} ) {
+	Vhffs::Robots::Git::create( $_ );
+}
+
+$repos = Vhffs::Services::Git::getall( $vhffs, Vhffs::Constants::WAITING_FOR_DELETION );
+foreach ( @{$repos} ) {
+	Vhffs::Robots::Git::delete( $_ );
+}
+
+$repos = Vhffs::Services::Git::getall( $vhffs, Vhffs::Constants::WAITING_FOR_MODIFICATION );
+foreach ( @{$repos} ) {
+	Vhffs::Robots::Git::modify( $_ );
+}
+
+Vhffs::Robots::unlock( $vhffs, 'git' );
+exit 0;

Deleted: trunk/vhffs-robots/src/git_create.pl
===================================================================
--- trunk/vhffs-robots/src/git_create.pl	2012-02-25 00:27:28 UTC (rev 2048)
+++ trunk/vhffs-robots/src/git_create.pl	2012-02-25 00:50:48 UTC (rev 2049)
@@ -1,60 +0,0 @@
-#!%PERL%
-# Copyright (c) vhffs project and its contributors
-# Copyright (c) 2007 Julien Danjou <julien@xxxxxxxxxxx>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Main;
-use Vhffs::Robots;
-use Vhffs::Robots::Git;
-use Vhffs::Services::Git;
-use Vhffs::Constants;
-
-
-my $vhffs = init Vhffs::Main;
-
-Vhffs::Robots::lock( $vhffs , 'git' );
-
-my $repos = Vhffs::Services::Git::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION);
-foreach my $git ( @{$repos} )
-{
-	if( Vhffs::Robots::Git::create_repo( $git ) != 0 ) {
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'Cannot create GIT %s' , $git->get_reponame ));
-	} else {
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'Created GIT %s' , $git->get_reponame ));
-	}
-}
-
-
-Vhffs::Robots::unlock( $vhffs , 'git' );
-exit 0;

Deleted: trunk/vhffs-robots/src/git_delete.pl
===================================================================
--- trunk/vhffs-robots/src/git_delete.pl	2012-02-25 00:27:28 UTC (rev 2048)
+++ trunk/vhffs-robots/src/git_delete.pl	2012-02-25 00:50:48 UTC (rev 2049)
@@ -1,65 +0,0 @@
-#!%PERL%
-# Copyright (c) vhffs project and its contributors
-# Copyright (c) 2007 Julien Danjou <julien@xxxxxxxxxxx>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Main;
-use Vhffs::Robots;
-use Vhffs::Robots::Git;
-use Vhffs::Services::Git;
-use Vhffs::Constants;
-
-
-my $vhffs = init Vhffs::Main;
-
-Vhffs::Robots::lock( $vhffs , 'git' );
-
-my $repos = Vhffs::Services::Git::getall( $vhffs , Vhffs::Constants::WAITING_FOR_DELETION );
-foreach my $git ( @{$repos} )
-{
-	if( Vhffs::Robots::Git::delete_repo( $git ) != 0 )	{
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'Cannot delete files from GIT repository %s' , $git->get_reponame ));
-	} else {
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'Delete files from GIT repository %s' , $git->get_reponame ));
-	}
-
-	if( $git->delete < 0 ) {
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'Cannot delete GIT repository object %s' , $git->get_reponame ));
-	} else {
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'Delete GIT repository object %s' , $git->get_reponame ));
-	}
-}
-
-Vhffs::Robots::unlock( $vhffs , 'git' );
-exit 0;

Deleted: trunk/vhffs-robots/src/git_public.pl
===================================================================
--- trunk/vhffs-robots/src/git_public.pl	2012-02-25 00:27:28 UTC (rev 2048)
+++ trunk/vhffs-robots/src/git_public.pl	2012-02-25 00:50:48 UTC (rev 2049)
@@ -1,72 +0,0 @@
-#!%PERL%
-# Copyright (c) vhffs project and its contributors
-# Copyright (c) 2007 Julien Danjou <julien@xxxxxxxxxxx>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Main;
-use Vhffs::Robots;
-use Vhffs::Robots::Git;
-use Vhffs::Services::Git;
-use Vhffs::Constants;
-
-
-my $vhffs = init Vhffs::Main;
-
-Vhffs::Robots::lock( $vhffs , 'git' );
-
-my $repos = Vhffs::Services::Git::getall( $vhffs , Vhffs::Constants::WAITING_FOR_MODIFICATION );
-foreach my $git ( @{$repos} )
-{
-	if( $git->is_public == 1 ) {
-		chmod 02775 , $git->get_dir;
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'GIT status %s is now public' , $git->get_dir ) );
-	} else {
-		chmod 02770 , $git->get_dir;
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'GIT status %s is now private' , $git->get_dir ) );
-	}
-
-	Vhffs::Robots::Git::change_conf( $git );
-	$git->set_status( Vhffs::Constants::ACTIVATED );
-	
-	if( $git->commit < 0 ) {
-		$git->add_history( 'Error while updating repository configuration' );
-	} else {
-		$git->add_history( 'Successfully modify repository configuration' );
-	}
-}
-
-
-Vhffs::Robots::unlock( $vhffs , 'git' );
-
-exit 0;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/