App-SD
view release on metacpan or search on metacpan
lib/App/SD/CLI/Model/Ticket.pm view on Meta::CPAN
=cut
sub add_comment {
my $self = shift;
validate(@_, { content => 1, uuid => 1 } );
my %args = @_;
require App::SD::CLI::Command::Ticket::Comment::Create;
$self->context->mutate_attributes( args => \%args );
my $command = App::SD::CLI::Command::Ticket::Comment::Create->new(
uuid => $args{uuid},
cli => $self->cli,
context => $self->context,
type => 'comment',
);
$command->run();
}
=head2 metadata_separator
A string of text that goes in the comment denoting the beginning of
immutable ticket metadata in a string representing a ticket.
Immutable ticket metadata includes things such as ticket id and
creation date that are useful to display to the user when editing a
ticket but are automatically assigned by sd and are not intended to
be changed manually.
=cut
use constant metadata_separator => 'required ticket metadata (changes here will not be saved)';
use constant mutable_props_separator => 'edit ticket details below';
use constant comment_separator => 'add new ticket comment below';
=head2 create_record_template [ RECORD ]
Creates a string representing a new record, prefilling default props
and props specified on the command line. Intended to be presented to
the user for editing using L<Prophet::CLI::TextEditorCommand->try_to_edit>
and then parsed using L</parse_record_template>.
If RECORD is given, then we are updating that record rather than
creating a new one, and the ticket string will be created from its
props rather than prop defaults.
=cut
sub create_record_template {
my $self = shift;
my $record = shift;
my $update;
if ($record) { $update = 1 }
else {
$record = $self->_get_record_object;
$update = 0;
}
my @do_not_edit = $record->immutable_props;
my ( @metadata_order, @mutable_order );
my ( %immutable_props, %mutable_props );
# separate out user-editable props so we can both show all
# the props that will be added to the new ticket and prevent
# users from being able to break things by changing props
# that shouldn't be changed, such as uuid
#
# filter out props we don't want to present for editing
my %do_not_edit = map { $_ => 1 } @do_not_edit;
for my $prop ( $record->props_to_show(
# only call props_to_show with --verbose if we're in an update
# because new tickets have no declared props
{ 'verbose' => ($self->has_arg('all-props') && $update),
update => $update } ) ) {
if ( $do_not_edit{$prop}) {
if ( $prop eq 'id' && $update ) {
# id isn't a *real* prop, so we have to mess with it some more
push @metadata_order, $prop;
$immutable_props{$prop}
= $record->luid . ' (' . $record->uuid . ")";
} elsif ( !( ( $prop eq 'id' or $prop eq 'created' ) && !$update ) )
{
push @metadata_order, $prop;
# which came first, the chicken or the egg?
#
# we don't want to display id/created for ticket creates
# because they can't by their nature be specified until the
# ticket is actually created
$immutable_props{$prop}
= $update ? $record->prop($prop) : undef;
}
} else {
push @mutable_order, $prop;
$mutable_props{$prop} = $update ? $record->prop($prop) : undef;
}
}
# fill in prop defaults if we're creating a new ticket
if ( !$update ) {
$record->default_props( \%immutable_props );
$record->default_props( \%mutable_props );
}
# fill in props specified on the commandline (overrides defaults)
if ( $self->has_arg('edit') ) {
map { $mutable_props{$_} = $self->prop($_) if $self->has_prop($_) }
@mutable_order;
$self->delete_arg('edit');
}
my $immutable_props_string = $self->_build_kv_pairs(
order => \@metadata_order,
data => \%immutable_props,
verbose => $self->has_arg('verbose'),
record => $record,
);
my $mutable_props_string = $self->_build_kv_pairs(
order => \@mutable_order,
data => \%mutable_props,
verbose => $self->has_arg('verbose'),
record => $record,
);
# glue all the parts together
return join(
"\n",
$self->build_template_section(
header => metadata_separator,
data => $immutable_props_string
),
( run in 1.921 second using v1.01-cache-2.11-cpan-39bf76dae61 )