86 lines
2.4 KiB
Perl
86 lines
2.4 KiB
Perl
package App::Git::IssueManager::Add;
|
|
#ABSTRACT: class implementing the add issue command of the GIT IssueManager
|
|
use strict;
|
|
use warnings;
|
|
use MooseX::App::Command;
|
|
extends qw(App::Git::IssueManager);
|
|
use Git::RepositoryHL;
|
|
use Git::IssueManager;
|
|
use Git::IssueManager::Issue;
|
|
use App::Git::IssueManager::Config;
|
|
use File::Temp qw/ tempfile/;
|
|
use File::Slurp;
|
|
use Term::ANSIColor;
|
|
use Try::Tiny;
|
|
|
|
|
|
command_short_description 'create an issue within a project';
|
|
command_usage 'git issue add -s Humbug';
|
|
|
|
option 'subject' => (
|
|
is => 'ro',
|
|
isa => 'Str',
|
|
required => 1,
|
|
documentation => q[the subject/title of the issue],
|
|
cmd_aliases => [qw(s)]
|
|
);
|
|
|
|
option 'priority' => (
|
|
is => 'ro',
|
|
isa => 'Str',
|
|
required => 0,
|
|
documentation => q[the priority of the issue (low, medium, high, urgent)],
|
|
cmd_aliases => [qw(p)],
|
|
default => "low"
|
|
);
|
|
|
|
option 'severity' => (
|
|
is => 'ro',
|
|
isa => 'Str',
|
|
required => 0,
|
|
documentation => q[the severity of the issue (low, medium, high, critical)],
|
|
cmd_aliases => [qw(e)],
|
|
default => "low"
|
|
);
|
|
|
|
option 'type' => (
|
|
is => 'ro',
|
|
isa => 'Str',
|
|
required => 0,
|
|
documentation => q[the type of the issue (bug, security-bug, improvement, feature, task)],
|
|
cmd_aliases => [qw(t)],
|
|
default => "bug"
|
|
);
|
|
|
|
|
|
|
|
|
|
sub run
|
|
{
|
|
my $self = shift;
|
|
my $manager = Git::IssueManager->new(repository=>Git::RepositoryHL->new(git_dir=> "."));
|
|
if (!$manager->ready)
|
|
{
|
|
print("IssueManager not initialized yet. Please call \"init\" command to do so.");
|
|
exit(-1);
|
|
}
|
|
my ($fh, $filename) = tempfile();
|
|
close($fh);
|
|
|
|
my $config=App::Git::IssueManager::Config->new(confname => 'config');
|
|
my $editor = $config->get(key=>"core.editor") || ENV{'EDITOR'} || "vim";
|
|
|
|
system($editor . " " .$filename);
|
|
|
|
my $text = read_file($filename);
|
|
|
|
my $issue = Git::IssueManager::Issue->new(subject => $self->subject);
|
|
$issue->description($text);
|
|
$issue->priority($self->priority);
|
|
$issue->severity($self->severity);
|
|
$issue->type($self->type);
|
|
$manager->add($issue);
|
|
}
|
|
|
|
1;
|