FIX: fixed changing issue keys

This commit is contained in:
Dominik Meyer 2018-09-13 21:28:17 +02:00
parent 5f4f7638ca
commit 50e5ccdfe1
No known key found for this signature in database
GPG Key ID: B4C312B600606B64

View File

@ -188,7 +188,7 @@ sub parseIssue
my $d = shift; my $d = shift;
my $tag = shift; my $tag = shift;
my $status = shift; my $status = shift;
my $subject = $d->mypath(); my $subject = $d->find("subject");
my $description = $d->find("description"); my $description = $d->find("description");
my $priority = $d->find("priority"); my $priority = $d->find("priority");
my $severity = $d->find("severity"); my $severity = $d->find("severity");
@ -199,7 +199,7 @@ sub parseIssue
my $estimated = $d->find("estimated"); my $estimated = $d->find("estimated");
my $working = $d->find("working"); my $working = $d->find("working");
my $tags = $d->find("tags"); my $tags = $d->find("tags");
my $id = $tag . "-" . substr($d->hash(),0,8); my $id = $tag . "-" . substr($subject->hash(),0,8);
my $cd = $d->timestamp_added(); my $cd = $d->timestamp_added();
my $ld = $d->timestamp_last(); my $ld = $d->timestamp_last();
my $author = $d->committer(); my $author = $d->committer();
@ -212,7 +212,7 @@ sub parseIssue
my $tz=DateTime::TimeZone->new( name => 'local' ); my $tz=DateTime::TimeZone->new( name => 'local' );
my $issue = Git::IssueManager::Issue->new(subject => $subject); my $issue = Git::IssueManager::Issue->new(subject => $subject->content);
$issue->status($status); $issue->status($status);
$issue->description($description->content()); $issue->description($description->content());
$issue->priority($priority->content()); $issue->priority($priority->content());
@ -297,7 +297,8 @@ sub delete
{ {
if (ref($i) eq "Git::LowLevel::Tree") if (ref($i) eq "Git::LowLevel::Tree")
{ {
my $mytag = $tag . "-" . substr($i->hash(),0,8); my $subject = $i->find("subject");
my $mytag = $tag . "-" . substr($subject->hash(),0,8);
if ($id eq $mytag) if ($id eq $mytag)
{ {
$status->del($i); $status->del($i);
@ -312,16 +313,20 @@ sub delete
} }
=method close =method changeStatus
set a issue as closed set status of an issue
=cut =cut
sub close sub changeStatus
{ {
my $self = shift; my $self = shift;
my $id = shift; my $id = shift;
my @statusse = ("open","assigned","inprogress"); my $status= shift;
die("unknown status") unless $status eq "open" || $status eq "closed" || $status eq "inprogress" || $status eq "assigned";
my @statusse = ("open","assigned","inprogress","closed");
die("IssueManager not initialized") unless $self->ready(); die("IssueManager not initialized") unless $self->ready();
my $ref = $self->repository->getReference('refs/heads/issues'); my $ref = $self->repository->getReference('refs/heads/issues');
@ -331,27 +336,30 @@ sub close
for my $s (@statusse) for my $s (@statusse)
{ {
for my $status ($root->find($s)) next unless $s ne $status;
for my $stat ($root->find($s))
{ {
for my $i ($status->get()) for my $i ($stat->get())
{ {
if (ref($i) eq "Git::LowLevel::Tree") if (ref($i) eq "Git::LowLevel::Tree")
{ {
my $mytag = $tag . "-" . substr($i->hash(),0,8); my $subject = $i->find("subject");
my $mytag = $tag . "-" . substr($subject->hash(),0,8);
if ($id eq $mytag) if ($id eq $mytag)
{ {
$status->del($i); my $base=$root->find($status);
my $issue = $self->parseIssue($i, $tag, "open"); $stat->del($i);
$issue->status("closed"); my $issue = $self->parseIssue($i, $tag, $s);
$issue->status($status);
my $issueTree=$issue->createIssue($self->repository); my $issueTree=$issue->createIssue($self->repository);
my $closed=$root->find("closed");
if (!defined($closed)) if (!defined($base))
{ {
$closed = $root->newTree(); $base = $root->newTree();
$closed->path("closed"); $base->path($status);
$root->add($closed); $root->add($base);
} }
$closed->add($issueTree); $base->add($issueTree);
$ref->commit("closed issue " . $i->mypath); $ref->commit("closed issue " . $i->mypath);
return; return;
} }
@ -362,5 +370,106 @@ sub close
die("issue " . $id . " not found\n"); die("issue " . $id . " not found\n");
} }
=method assign
assign a worker to an issue
=cut
sub assign
{
my $self = shift;
my $id = shift;
my $worker_name = shift;
my $worker_email = shift;
my $status = "assigned";
my @statusse = ("open","assigned","inprogress","closed");
die("IssueManager not initialized") unless $self->ready();
my $ref = $self->repository->getReference('refs/heads/issues');
my $tag = $ref->find(".tag")->content();
my $root = $ref->getTree();
for my $s (@statusse)
{
next unless $s ne $status;
for my $stat ($root->find($s))
{
for my $i ($stat->get())
{
if (ref($i) eq "Git::LowLevel::Tree")
{
my $subject = $i->find("subject");
my $mytag = $tag . "-" . substr($subject->hash(),0,8);
if ($id eq $mytag)
{
my $base=$root->find($status);
$stat->del($i);
my $issue = $self->parseIssue($i, $tag, $s);
$issue->status($status);
$issue->worker($worker_name);
$issue->worker_email($worker_email);
my $issueTree=$issue->createIssue($self->repository);
if (!defined($base))
{
$base = $root->newTree();
$base->path($status);
$root->add($base);
}
$base->add($issueTree);
$ref->commit("closed issue " . $i->mypath);
return;
}
}
}
}
}
die("issue " . $id . " not found\n");
}
=method close
close an issue
=cut
sub close
{
my $self = shift;
my $id = shift;
$self->changeStatus($id, "closed");
}
=method open
open an issue
=cut
sub open
{
my $self = shift;
my $id = shift;
$self->changeStatus($id, "open");
}
=method start
start an issue
=cut
sub start
{
my $self = shift;
my $id = shift;
$self->changeStatus($id, "inprogress");
}
1; 1;