164 lines
2.8 KiB
Perl
Executable File
164 lines
2.8 KiB
Perl
Executable File
#!/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
|
|
{
|
|
|
|
}
|