From 62b07b3cc9383814a200ae21f17667bcc9b670dd Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Mon, 9 Jul 2018 21:17:13 +0200 Subject: [PATCH] ADD: close an issue --- lib/Git/IssueManager.pm | 104 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/lib/Git/IssueManager.pm b/lib/Git/IssueManager.pm index ee60211..4cbaebf 100644 --- a/lib/Git/IssueManager.pm +++ b/lib/Git/IssueManager.pm @@ -414,6 +414,9 @@ sub add } + + + =method _to_issue - internal method, do not call directly returns the issue converted from a tree hash entry @@ -653,4 +656,105 @@ sub delete $self->repository->updateRef("refs/heads/issues",$commit); } + + +=method close + +set the given issue as closed + +=cut +sub close +{ + my $self = shift; + + my $id = shift; + + die("no id given") unless defined($id); + + $id=~/^[A-Z]+-(.*)$/; + my $hash=$1; + + $self->_load(); + + my $found=0; + my $index=0; + + # check if issue is already closed + for my $i (@{$self->_closed}) + { + if (substr($i->{ref},0,8) eq $hash) + { + $found=1; + last; + } + $index++; + } + if ($found) + { + die("issue is already closed"); + } + + $index=0; + # search for the id in other status arrays + for my $i (@{$self->_open}) + { + if (substr($i->{ref},0,8) eq $hash) + { + $found=1; + last; + } + $index++; + } + if ($found) + { + push(@{$self->_closed}, $self->_open()->[$index]); + splice @{$self->_open},$index,1; + } + + $index=0; + + for my $i (@{$self->_assigned}) + { + if (substr($i->{ref},0,8) eq $hash) + { + $found=1; + last; + } + $index++; + } + if ($found) + { + push(@{$self->_closed}, $self->_assigned()->[$index]); + splice @{$self->_assigned},$index,1; + } + + $index=0; + + for my $i (@{$self->_inprogress}) + { + if (substr($i->{ref},0,8) eq $hash) + { + $found=1; + last; + } + $index++; + } + if ($found) + { + push(@{$self->_closed}, $self->_inprogress()->[$index]); + splice @{$self->_inprogress},$index,1; + } + + + my $roothash = $self->_createTree(); + + # commit the issue + my $commit=$self->repository->createTreeCommit($roothash,$self->repository->getBranchRef("heads/issues") || "start", "Close: " . $id); + + #now update branch refs/heads/issues + $self->repository->updateRef("refs/heads/issues",$commit); + +} + + 1;