Add hook for project:* tag
This commit is contained in:
parent
d3e723f65a
commit
b7bbbea5b8
8
Makefile
8
Makefile
@ -1,6 +1,6 @@
|
||||
COPY=cp -v
|
||||
DEST=/usr/local/share/perl/`ls -1 /usr/lib/perl/ | tail -1`/
|
||||
GITOLITE_DEST=/srv/git/repositories/.gitolite
|
||||
GITOLITE_DEST=/usr/share/gitolite/hooks/common
|
||||
MAKEDIR=mkdir
|
||||
PROVER=prove -f
|
||||
RM=rm
|
||||
@ -9,11 +9,13 @@ TESTDIR=t
|
||||
install:
|
||||
$(MAKEDIR) -p $(DEST)
|
||||
$(COPY) -r ACU/ $(DEST)
|
||||
test -d $(GITOLITE_DEST)/src && $(COPY) hooks/* $(GITOLITE_DEST)/src
|
||||
test -d $(GITOLITE_DEST) && $(MAKEDIR) -p $(GITOLITE_DEST)/update.secondary.d
|
||||
test -d $(GITOLITE_DEST) && $(COPY) hooks/* $(GITOLITE_DEST)/update.secondary.d/
|
||||
|
||||
unstall:
|
||||
$(RM) -r $(DEST)/ACU/
|
||||
test -d $(GITOLITE_DEST)/src && $(RM) $(GITOLITE_DEST)/src/*
|
||||
test -d $(GITOLITE_DEST) && $(RM) -rf $(GITOLITE_DEST)/update.secondary.d
|
||||
test -d $(GITOLITE_DEST) && $(MAKEDIR) -p $(GITOLITE_DEST)/update.secondary.d
|
||||
|
||||
test:
|
||||
$(PROVER) $(TESTDIR)
|
||||
|
163
hooks/subjects.pl
Executable file
163
hooks/subjects.pl
Executable file
@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use v5.10;
|
||||
|
||||
use ACU::LDAP;
|
||||
use ACU::Log;
|
||||
$ACU::Log::log_file = undef;
|
||||
use ACU::Process;
|
||||
|
||||
# First, check if the repository is in the subjects/ directory
|
||||
exit 0 if ($ENV{GL_REPO} !~ /^subjects\//);
|
||||
|
||||
my ($ref, $oldsha, $newsha) = @ARGV;
|
||||
|
||||
log WARN, "This is a subject!";
|
||||
|
||||
my %known_tags = (
|
||||
"defense" => \&tag_defense,
|
||||
"grades" => \&tag_grades,
|
||||
"project" => \&tag_project,
|
||||
"subject" => \&tag_document,
|
||||
"ref" => \&tag_ref,
|
||||
"tests" => \&tag_tests,
|
||||
);
|
||||
|
||||
if ($ref =~ m<^refs/tags(/.+)$>)
|
||||
{
|
||||
my $tag = $1;
|
||||
my @args;
|
||||
|
||||
while ($tag =~ m<[:/]([^:]+)>g) {
|
||||
push @args, $1;
|
||||
}
|
||||
|
||||
my $create = ($newsha ne '0' x 40);
|
||||
|
||||
if (exists $known_tags{$args[0]}) {
|
||||
exit $known_tags{$args[0]}($create, @args);
|
||||
}
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
||||
sub check_xml
|
||||
{
|
||||
my $content = shift;
|
||||
my $dtd = shift;
|
||||
|
||||
my $fh;
|
||||
if ($dtd) {
|
||||
open $fh, "|xmllint --noout --dtdvalid $dtd -";
|
||||
}
|
||||
else {
|
||||
open $fh, "|xmllint --noout -";
|
||||
}
|
||||
print $fh $content;
|
||||
close $fh;
|
||||
|
||||
return $?;
|
||||
}
|
||||
|
||||
sub repository_name
|
||||
{
|
||||
my $repo = $ENV{GL_REPO};
|
||||
$repo =~ s/^subjects\\(.*)/$1/;
|
||||
return $repo;
|
||||
}
|
||||
|
||||
|
||||
sub tag_defense
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
sub tag_document
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
sub tag_grades
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
sub tag_project
|
||||
{
|
||||
my $creation = shift;
|
||||
|
||||
my $project_id = repository_name();
|
||||
if ($_[1]) {
|
||||
|
||||
# Check on ID/flavour_id
|
||||
if ($_[1] =~ /^\d+$/) {
|
||||
log ERROR, "project:* tag can't take version. Tag format: project:id:year";
|
||||
}
|
||||
|
||||
$project_id .= "-" . $_[1];
|
||||
}
|
||||
lc $project_id;
|
||||
$project_id =~ s/[^a-z0-9-_]/_/g;
|
||||
|
||||
my $year;
|
||||
if ($_[2]) {
|
||||
# Check on year
|
||||
if ($_[2] !~ /^\d+$/) {
|
||||
log ERROR, "project:*:* second argument is the year. Tag format: project:id:year";
|
||||
}
|
||||
|
||||
$year = $_[2];
|
||||
}
|
||||
else {
|
||||
$year = LDAP::get_year;
|
||||
}
|
||||
|
||||
if ($creation)
|
||||
{
|
||||
my $newref = $ARGV[2];
|
||||
|
||||
log INFO, "Création/mise à jour du projet...";
|
||||
|
||||
my $content = qx(git show $newref:project.xml);
|
||||
# Check file exists
|
||||
if ($?) {
|
||||
log ERROR, "Créez un fichier project.xml à la racine du dépôt.";
|
||||
}
|
||||
|
||||
# Check DTD validity
|
||||
if (check_xml($content, "http://acu.epita.fr/dtd/project.dtd")) {
|
||||
log ERROR, "Corrigez les erreurs du fichier project.xml avant de lancer la création du projet.";
|
||||
}
|
||||
|
||||
# TODO: check user permissions
|
||||
|
||||
# Generate token for VCS submission
|
||||
|
||||
# Send data to intradata
|
||||
Process::Client::launch("intradata_get", { action => "update", type => "project", id => $project_id, "year" => $year }, { "butler.xml" => $content });
|
||||
|
||||
# Call API
|
||||
my $err = API::Projects::add($project_id, $year);
|
||||
log ERROR, $err if ($err);
|
||||
|
||||
# FIXME: Remove next line after 2016 piscine: ça ne devrait pas être fait à ce moment là
|
||||
$err = API::Projects::gen_groups($project_id, $year);
|
||||
log ERROR, $err if ($err);
|
||||
}
|
||||
else
|
||||
{
|
||||
log USAGE, "Suppression du projet !";
|
||||
}
|
||||
}
|
||||
|
||||
sub tag_ref
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
sub tag_tests
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user