[vhffs-dev] [2263] Added cgit configuration file generator

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


Revision: 2263
Author:   gradator
Date:     2015-01-25 20:54:34 +0100 (Sun, 25 Jan 2015)
Log Message:
-----------
Added cgit configuration file generator

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

Modified: trunk/vhffs-api/src/Vhffs/Robots/Git.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Git.pm	2015-01-05 19:41:06 UTC (rev 2262)
+++ trunk/vhffs-api/src/Vhffs/Robots/Git.pm	2015-01-25 19:54:34 UTC (rev 2263)
@@ -131,6 +131,7 @@
 		return undef;
 	}
 
+	cgit_conf( $vhffs );
 	return 1;
 }
 
@@ -144,13 +145,13 @@
 	if( $git->is_public ) {
 		chmod 02775, $dir;
 
-		Vhffs::Robots::vhffs_log( $vhffs, 'Svn repository '.$git->get_reponame.' is now public' );
+		Vhffs::Robots::vhffs_log( $vhffs, 'Git 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' );
+		Vhffs::Robots::vhffs_log( $vhffs, 'Git repository '.$git->get_reponame.' is now private' );
 		$git->add_history( 'Is now private');
 	}
 
@@ -216,7 +217,50 @@
 	$git->set_status( Vhffs::Constants::ACTIVATED );
 	$git->commit;
 
+	cgit_conf( $vhffs );
 	return 1;
 }
 
+sub cgit_conf {
+	require File::Copy;
+
+	my $vhffs = shift;
+
+	my $confdir = $vhffs->get_config->get_datadir.'/git/conf';
+	unless( -d $confdir ) {
+		mkdir( $confdir ) or Vhffs::Robots::vhffs_log( $vhffs, 'Unable to create git confdir '.$confdir.': '.$! );
+	}
+
+	my ( $tmpfile, $tmppath ) = Vhffs::Robots::tmpfile( $vhffs );
+	return undef unless defined $tmpfile;
+
+	my $gits = Vhffs::Services::Git::getall( $vhffs, Vhffs::Constants::ACTIVATED );
+	foreach my $git ( @{$gits} )  {
+		next unless $git->is_public;
+
+		my $description = $git->get_description;
+		$description =~ s/\r\n/\n/g; # change CRLF to LF
+		$description =~ s/\n\s*\n/\n/g; # remove empty lines
+		$description =~ s/^\n//; # remove first LF
+		$description =~ s/\n$//; # remove latest LF
+		$description =~ s/\n/ /g; # replace LF to space
+
+		print $tmpfile 'repo.url='.$_->get_reponame."\n";
+		print $tmpfile 'repo.path='.$_->get_dir."\n";
+		print $tmpfile 'repo.desc='.$description."\n";
+
+		require Vhffs::Services::MailGroup;
+		my $mg = new Vhffs::Services::MailGroup( $vhffs, $git->get_group );
+		print $tmpfile 'repo.owner='.$mg->get_localpart->get_localpart.'@'.$mg->get_domain."\n" if defined $mg and defined $mg->get_localpart;
+
+		print $tmpfile "\n";		
+	}
+
+	close( $tmpfile );
+
+	chmod 0644, $tmppath;
+	File::Copy::move( $tmppath, $confdir.'/cgitrepos.inc' );
+	return 1;
+}
+
 1;


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