New hook post-update
This commit is contained in:
parent
84c34f8fea
commit
dfb66035eb
3 changed files with 103 additions and 33 deletions
1
Makefile
1
Makefile
|
@ -17,6 +17,7 @@ install:
|
||||||
$(COPY) -r ACU/ $(DEST)
|
$(COPY) -r ACU/ $(DEST)
|
||||||
! test -d $(GITOLITE_DEST) || $(MAKEDIR) -p $(GITOLITE_DEST)/update.secondary.d
|
! test -d $(GITOLITE_DEST) || $(MAKEDIR) -p $(GITOLITE_DEST)/update.secondary.d
|
||||||
! test -d $(GITOLITE_DEST) || $(COPY) hooks/gl-pre-git $(GITOLITE_DEST)/
|
! test -d $(GITOLITE_DEST) || $(COPY) hooks/gl-pre-git $(GITOLITE_DEST)/
|
||||||
|
! test -d $(GITOLITE_DEST) || $(COPY) hooks/post-update $(GITOLITE_DEST)/
|
||||||
! test -d $(GITOLITE_DEST) || $(COPY) hooks/subjects.pl $(GITOLITE_DEST)/update.secondary.d/
|
! test -d $(GITOLITE_DEST) || $(COPY) hooks/subjects.pl $(GITOLITE_DEST)/update.secondary.d/
|
||||||
! test -d $(GITOLITE_DEST) || $(COPY) hooks/conferences.pl $(GITOLITE_DEST)/update.secondary.d/
|
! test -d $(GITOLITE_DEST) || $(COPY) hooks/conferences.pl $(GITOLITE_DEST)/update.secondary.d/
|
||||||
! test -d $(GITOLITE_DEST) || $(COPY) hooks/submissions.pl $(GITOLITE_DEST)/update.secondary.d/
|
! test -d $(GITOLITE_DEST) || $(COPY) hooks/submissions.pl $(GITOLITE_DEST)/update.secondary.d/
|
||||||
|
|
96
hooks/post-update
Executable file
96
hooks/post-update
Executable file
|
@ -0,0 +1,96 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use v5.10;
|
||||||
|
use File::Basename;
|
||||||
|
use utf8;
|
||||||
|
|
||||||
|
use ACU::API::Projects;
|
||||||
|
use ACU::API::Submission;
|
||||||
|
use ACU::LDAP;
|
||||||
|
use ACU::Log;
|
||||||
|
$ACU::Log::log_file = "/var/log/hooks/" . basename($0) . ".log";
|
||||||
|
use ACU::Process;
|
||||||
|
|
||||||
|
my $promo;
|
||||||
|
my $id_project;
|
||||||
|
my $repo_login;
|
||||||
|
|
||||||
|
# First, extract information, from config then guess from repository adress
|
||||||
|
if (my $tmp = `git config hooks.promo`) { chomp $tmp; $promo = $tmp; }
|
||||||
|
if (my $tmp = `git config hooks.idproject`) { chomp $tmp; $id_project = $tmp; }
|
||||||
|
if (my $tmp = `git config hooks.login`) { chomp $tmp; $repo_login = $tmp; }
|
||||||
|
|
||||||
|
$promo = $1 if (!$promo && $ENV{'GL_REPO'} =~ m/([0-9]{4}).*/);
|
||||||
|
$id_project = $1 if (!$id_project && $ENV{'GL_REPO'} =~ m/.*\/(.*)\//);
|
||||||
|
$repo_login = $1 if (!$repo_login && $ENV{'GL_REPO'} =~ m/.*\/.*\/(.*)/);
|
||||||
|
|
||||||
|
exit(0) if (!$promo || !$id_project || !$repo_login);
|
||||||
|
|
||||||
|
for my $ref (@ARGV)
|
||||||
|
{
|
||||||
|
if ($ref =~ m<^refs/tags/(.+)$>)
|
||||||
|
{
|
||||||
|
my $tag = $1;
|
||||||
|
log DEBUG, "Tag $tag on repository $ENV{GL_REPO} from IP $ENV{'SSH_CLIENT'} updated.";
|
||||||
|
|
||||||
|
# Get project informations
|
||||||
|
my $project;
|
||||||
|
eval {
|
||||||
|
$project = API::Projects::get($id_project, $promo);
|
||||||
|
};
|
||||||
|
if ($@ or !$project)
|
||||||
|
{
|
||||||
|
my $err = $@;
|
||||||
|
log TRACE, $err;
|
||||||
|
log ERROR, "Impossible d'envoyer de tags ; si le problème persiste, passez au laboratoire.";
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Extract lot of data
|
||||||
|
my @rendus = grep {
|
||||||
|
exists $_->{vcs} and $_->{vcs}{tag} eq $tag;
|
||||||
|
} @{ $project->{submissions} };
|
||||||
|
|
||||||
|
if (@rendus)
|
||||||
|
{
|
||||||
|
eval
|
||||||
|
{
|
||||||
|
Process::Client::launch("send_git",
|
||||||
|
{
|
||||||
|
"year" => $promo,
|
||||||
|
"id" => $id_project,
|
||||||
|
"rendu" => $tag,
|
||||||
|
"login" => $repo_login,
|
||||||
|
# "path" => "ssh://git\@localhost/".$ENV{GL_REPO}, # Optional
|
||||||
|
},
|
||||||
|
undef, # Don't give any file
|
||||||
|
1 # Launch in background
|
||||||
|
);
|
||||||
|
};
|
||||||
|
if ($@)
|
||||||
|
{
|
||||||
|
my $err = $@;
|
||||||
|
log DEBUG, "ERROR: ".$err;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Send data to API
|
||||||
|
my $last_commit = `git log "refs/tags/$tag" -1 --decorate --tags`;
|
||||||
|
eval {
|
||||||
|
API::Submission::add($promo, $id_project, $tag, $repo_login, $last_commit);
|
||||||
|
};
|
||||||
|
if ($@)
|
||||||
|
{
|
||||||
|
my $err = $@;
|
||||||
|
log DEBUG, "ERROR: ".$err;
|
||||||
|
log DONE, "Tag '$tag' effectué avec succès !";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log DONE, "Tag '$tag' effectué avec succès ! Vérifiez-le sur l'intranet.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit 0;
|
|
@ -52,7 +52,7 @@ if ($ref =~ m<^refs/tags/(.+)$>)
|
||||||
my $err = $@;
|
my $err = $@;
|
||||||
log TRACE, $err;
|
log TRACE, $err;
|
||||||
log ERROR, "Impossible d'envoyer de tags ; si le problème persiste, passez au laboratoire.";
|
log ERROR, "Impossible d'envoyer de tags ; si le problème persiste, passez au laboratoire.";
|
||||||
exit 1;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
log TRACE, $project;
|
log TRACE, $project;
|
||||||
|
@ -119,40 +119,13 @@ if ($ref =~ m<^refs/tags/(.+)$>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($newsha eq '0' x 40) {
|
if (@rendus && $newsha eq '0' x 40)
|
||||||
|
{
|
||||||
log USAGE, "Mais pour quelle raison voudriez-vous supprimer un tag ?!";
|
log USAGE, "Mais pour quelle raison voudriez-vous supprimer un tag ?!";
|
||||||
|
exit(7);
|
||||||
}
|
}
|
||||||
else
|
# elsif @rendus : new rendu => accepted
|
||||||
{
|
# else user defined tag => accepted
|
||||||
eval {
|
|
||||||
Process::Client::launch("send_git",
|
|
||||||
{
|
|
||||||
"year" => $promo,
|
|
||||||
"id" => $id_project,
|
|
||||||
"rendu" => $tag,
|
|
||||||
"login" => $repo_login,
|
|
||||||
# "path" => "ssh://git\@localhost/".$ENV{GL_REPO},
|
|
||||||
}, undef, 1);
|
|
||||||
};
|
|
||||||
if ($@) {
|
|
||||||
my $err = $@;
|
|
||||||
log DEBUG, "ERROR: ".$err;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Send data to API
|
|
||||||
my $last_commit = `git log $newsha -1 --decorate --tags`;
|
|
||||||
eval {
|
|
||||||
API::Submission::add($promo, $id_project, $tag, $repo_login, $last_commit);
|
|
||||||
};
|
|
||||||
if ($@) {
|
|
||||||
my $err = $@;
|
|
||||||
log DEBUG, "ERROR: ".$err;
|
|
||||||
log DONE, "Tag '$tag' effectué avec succès !";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log DONE, "Tag '$tag' effectué avec succès ! Vérifiez-le sur l'intranet.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|
Reference in a new issue