ADD: added issue delete method
This commit is contained in:
parent
b6f404f4df
commit
37e09b68ff
@ -440,5 +440,231 @@ sub list
|
||||
return @ret;
|
||||
}
|
||||
|
||||
=method delete
|
||||
|
||||
delete the issue with the given id
|
||||
|
||||
=cut
|
||||
sub delete
|
||||
{
|
||||
my $self = shift;
|
||||
my $id = shift;
|
||||
|
||||
die("no id given") unless defined($id);
|
||||
|
||||
$id=~/^[A-Z]+-(.*)$/;
|
||||
my $hash=$1;
|
||||
|
||||
my $found=0;
|
||||
my $index=0;
|
||||
|
||||
my @root = $self->repository->getTree("issues");
|
||||
# first search for the id
|
||||
my @open = $self->repository->getTree("issues","open/");
|
||||
for my $i (@open)
|
||||
{
|
||||
if (substr($i->{ref},0,8) eq $hash)
|
||||
{
|
||||
$found=1;
|
||||
last;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
if ($found)
|
||||
{
|
||||
splice @open,$index,1;
|
||||
}
|
||||
|
||||
$index=0;
|
||||
my @assigned = $self->repository->getTree("issues","assigned/");
|
||||
if (!$found)
|
||||
{
|
||||
for my $i (@assigned)
|
||||
{
|
||||
if (substr($i->{ref},0,8) eq $hash)
|
||||
{
|
||||
$found=1;
|
||||
last;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
if ($found)
|
||||
{
|
||||
splice @assigned,$index,1;
|
||||
}
|
||||
}
|
||||
|
||||
$index=0;
|
||||
my @inprogress = $self->repository->getTree("issues","inprogress");
|
||||
if (!$found)
|
||||
{
|
||||
for my $i (@inprogress)
|
||||
{
|
||||
if (substr($i->{ref},0,8) eq $hash)
|
||||
{
|
||||
$found=1;
|
||||
last;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
if ($found)
|
||||
{
|
||||
splice @inprogress,$index,1;
|
||||
}
|
||||
}
|
||||
|
||||
$index=0;
|
||||
my @closed = $self->repository->getTree("issues","closed/");
|
||||
if (!$found)
|
||||
{
|
||||
for my $i (@closed)
|
||||
{
|
||||
if (substr($i->{ref},0,8) eq $hash)
|
||||
{
|
||||
$found=1;
|
||||
last;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
if ($found)
|
||||
{
|
||||
splice @closed,$index,1;
|
||||
}
|
||||
}
|
||||
|
||||
$self->recreate(\@root);
|
||||
$self->recreate(\@open);
|
||||
$self->recreate(\@closed);
|
||||
$self->recreate(\@assigned);
|
||||
$self->recreate(\@inprogress);
|
||||
|
||||
# now recreate tree structure
|
||||
my $openhash = $self->repository->createTree(\@open);
|
||||
my $closedhash = $self->repository->createTree(\@closed);
|
||||
my $assignedhash = $self->repository->createTree(\@assigned);
|
||||
my $inprogresshash= $self->repository->createTree(\@inprogress);
|
||||
|
||||
my $openfound=0;
|
||||
my $closedfound=0;
|
||||
my $assignedfound=0;
|
||||
my $inprogressfound=0;
|
||||
# now recreate the root tree
|
||||
my @fordelete;
|
||||
my $i=0;
|
||||
for my $r (@root)
|
||||
{
|
||||
if ($r->{name} eq "open")
|
||||
{
|
||||
if (defined($openhash) && length($openhash)==40)
|
||||
{
|
||||
$r->{ref}=$openhash;
|
||||
$openfound=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
push(@fordelete, $i);
|
||||
}
|
||||
}
|
||||
|
||||
if ($r->{name} eq "closed")
|
||||
{
|
||||
if (defined($closedhash) && length($closedhash)==40)
|
||||
{
|
||||
$r->{ref}=$closedhash;
|
||||
$closedfound=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
push(@fordelete, $i);
|
||||
}
|
||||
}
|
||||
|
||||
if ($r->{name} eq "assigned")
|
||||
{
|
||||
if (defined($assignedhash) && length($assignedhash)==40)
|
||||
{
|
||||
$r->{ref}=$assignedhash;
|
||||
$assignedfound=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
push(@fordelete, $i);
|
||||
}
|
||||
}
|
||||
|
||||
if ($r->{name} eq "inprogess")
|
||||
{
|
||||
if (defined($inprogresshash) && length($inprogresshash)==40)
|
||||
{
|
||||
$r->{ref}=$inprogresshash;
|
||||
$inprogressfound=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
push(@fordelete, $i);
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
for my $d (@fordelete)
|
||||
{
|
||||
splice @root, $d, 1;
|
||||
}
|
||||
|
||||
if (!$openfound && defined($openhash))
|
||||
{
|
||||
print "adding open " . $openhash . "\n";
|
||||
my $t = {
|
||||
path => "open",
|
||||
ref => $openhash,
|
||||
type => "tree",
|
||||
mode => "040000"
|
||||
};
|
||||
push(@root, $t);
|
||||
}
|
||||
|
||||
if (!$closedfound && defined($closedhash))
|
||||
{
|
||||
my $t = {
|
||||
path => "closed",
|
||||
ref => $closedhash,
|
||||
type => "tree",
|
||||
mode => "040000"
|
||||
};
|
||||
push(@root, $t);
|
||||
}
|
||||
|
||||
if (!$assignedfound && defined($assignedhash))
|
||||
{
|
||||
my $t = {
|
||||
path => "assigned",
|
||||
ref => $assignedhash,
|
||||
type => "tree",
|
||||
mode => "040000"
|
||||
};
|
||||
push(@root, $t);
|
||||
}
|
||||
|
||||
if (!$inprogressfound && defined($inprogresshash))
|
||||
{
|
||||
my $t = {
|
||||
path => "inprogress",
|
||||
ref => $inprogresshash,
|
||||
type => "tree",
|
||||
mode => "040000"
|
||||
};
|
||||
push(@root, $t);
|
||||
}
|
||||
|
||||
my $roothash = $self->repository->createTree(\@root);
|
||||
|
||||
# commit the issue
|
||||
my $commit=$self->repository->createTreeCommit($roothash,$self->repository->getBranchRef("heads/issues") || "start", "RM: " . $id);
|
||||
|
||||
#now update branch refs/heads/issues
|
||||
$self->repository->updateRef("refs/heads/issues",$commit);
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user