App-SD
view release on metacpan or search on metacpan
lib/App/SD/Replica/gcode/PushEncoder.pm view on Meta::CPAN
# Build up a ticket object out of all the record's attributes
my $ticket = $self->sync_source->gcode->issue;
my $id =
$ticket->create( %{ $self->_recode_props_for_integrate($change) } );
return $id;
}
sub integrate_comment {
my $self = shift;
my ( $change, $changeset ) = validate_pos(
@_,
{ isa => 'Prophet::Change' },
{ isa => 'Prophet::ChangeSet' }
);
# Figure out the remote site's ticket ID for this change's record
my %props = map { $_->name => $_->new_value } $change->prop_changes;
my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'} );
my $ticket = $self->sync_source->gcode->issue( id => $ticket_id );
my %content = ( comment => $props{'content'}, );
$ticket->update(%content);
return $ticket_id;
}
sub integrate_attachment {
my ( $self, $change, $changeset ) = validate_pos(
@_,
{ isa => 'App::SD::Replica::gcode::PushEncoder' },
{ isa => 'Prophet::Change' },
{ isa => 'Prophet::ChangeSet' }
);
my %props = map { $_->name => $_->new_value } $change->prop_changes;
my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'} );
my $ticket = $self->sync_source->gcode->issue( id => $ticket_id, );
my $tempdir = File::Temp::tempdir( CLEANUP => 1 );
my $file = File::Spec->catfile( $tempdir, ( $props{'name'} || 'unnamed' ) );
open my $fh, '>', $file or die $!;
print $fh $props{content};
close $fh;
my %content = ( comment => '(See attachments)', files => ["$file"] );
$ticket->update(%content);
return $ticket_id;
}
sub _recode_props_for_integrate {
my $self = shift;
my ($change) = validate_pos( @_, { isa => 'Prophet::Change' } );
my %props = map { $_->name => $_->new_value } $change->prop_changes;
my %attr;
for my $key ( keys %props ) {
if ( $key =~ /^(summary|owner|cc|blocked_on)/ ) {
$attr{$key} = $props{$key};
}
elsif ( $key eq 'status' ) {
$attr{$key} = ucfirst $props{$key};
}
elsif ( $key eq 'merged_into' ) {
# yeah, the comment form use 'merge_into' name
$attr{merge_into} = $props{$key};
}
elsif ( $key eq 'tags' ) {
$attr{labels} ||= [];
push @{$attr{labels}}, split /\s*,\s*/, $props{$key};
}
else {
$attr{labels} ||= [];
push @{ $attr{labels} },
( ucfirst $key ) . '-' . ucfirst $props{$key};
}
}
return \%attr;
}
__PACKAGE__->meta->make_immutable;
no Any::Moose;
1;
( run in 0.897 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )