SD/Replica/gcode.pm untested

filter: Statementstmt 0.0% 0 / 95 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 138 CC 8 SCAR 28.2
CC
8
Cov
0%
BUILD
56.0
database_settings
6.0
remote_url
2.0
CRAP 16.8
1 package App::SD::Replica::gcode;
2 use Any::Moose;
3 extends qw/App::SD::ForeignReplica/;
4  
5 use Params::Validate qw(:all);
6 use File::Temp 'tempdir';
7 use Memoize;
8 use Try::Tiny;
9  
10 use constant scheme => 'gcode';
11 use constant pull_encoder => 'App::SD::Replica::gcode::PullEncoder';
12 use constant push_encoder => 'App::SD::Replica::gcode::PushEncoder';
13 use Prophet::ChangeSet;
14  
15 our %PROP_MAP = (
16 summary => 'summary',
17 status => 'status',
18 owner => 'owner',
19 reporter => 'reporter',
20 cc => 'cc',
21 closed => 'completed',
22 reported => 'created',
23 labels => 'tags',
24 priority => 'priority',
25 mergedinto => 'merged_into',
26 blockedon => 'blocked_on',
27 );
28  
29  
30 has query => ( isa => 'Str', is => 'rw');
31 has gcode => ( isa => 'Net::Google::Code', is => 'rw');
32 has project => ( isa => 'Str', is => 'rw');
33 has foreign_username => ( isa => 'Str', is => 'rw' );
34  
35 sub remote_url { return "http://code.google.com/p/".shift->project}
36  
37 sub BUILD {
38 my $self = shift;
39  
40 # Require rather than use to defer load
41 try {
42 require Net::Google::Code;
43 require Net::Google::Code::Issue;
44 } catch {
45 die "SD requires Net::Google::Code to sync with Google Code.\n".
46 "'cpan Net::Google::Code' may sort this out for you.\n";
47 };
48  
49 $Net::Google::Code::Issue::USE_HYBRID = 1
50 if $Net::Google::Code::VERSION ge '0.15';
51  
52 my ( $userinfo, $project, $query ) =
53 $self->{url} =~ m!^gcode:(?:(.*)@)?(.*?)(?:/(.*))?$!
54 or die
55 "Can't parse Google::Code server spec. Expected gcode:k9mail or gcode:user:password\@k9mail or gcode:user:password\@k9mail/q=string&can=all";
56 $self->project($project);
57 $self->url($project); # url should be raw url minus scheme and auth info
58 $self->query($query) if defined $query;
59  
60 # Since we don't need a username / password to clone or pull, we don't save
61 # the username and password here, if specified-- we only want to save
62 # username/password combinations after they've been verified to work. (So
63 # we save later if we end up trying to auth.) We do still want to parse any
64 # username/password specified in the url.
65  
66 my ( $email, $password );
67 if ( $userinfo ) {
68 ( $email, $password ) = split /:/, $userinfo, 2;
69 }
70  
71 my %gcode_args = ( project => $self->project );
72 $gcode_args{email} = $email if $email;
73 $gcode_args{password} = $password if $password;
74 # should never fail (no auth performed on create)
75 $self->gcode( Net::Google::Code->new( %gcode_args ) );
76  
77 try {
78 $self->gcode->load();
79 } catch {
80 if ( $_ =~ m{Error GETing .*: Not Found} ) {
81 die "The Google Code project '$project' does not exist. Aborting!\n";
82 }
83 else {
84 # some other error
85 die $_;
86 }
87 }
88 }
89  
90 sub get_txn_list_by_date {
91 my $self = shift;
92 my $ticket = shift;
93  
94 my $ticket_obj = Net::Google::Code::Issue->new( project => $self->project);
95 $ticket_obj->load($ticket);
96
97 my @txns = map {
98 {
99 id => $_->sequence,
100 creator => $_->author,
101 created => $_->date->epoch,
102 }
103 }
104 sort { $b->date <=> $a->date } @{ $ticket_obj->comments };
105 return @txns;
106 }
107  
108 sub remote_uri_path_for_comment {
109 my $self = shift;
110 my $id = shift;
111 return "/comment/".$id;
112 }
113  
114 sub remote_uri_path_for_id {
115 my $self = shift;
116 my $id = shift;
117 return "/ticket/".$id;
118 }
119  
120 sub database_settings {
121 my $self = shift;
122 my $issue = $self->gcode->issue;
123 $issue->load_predefined;
124 my $status = $issue->predefined_status;
125 return {
126 project_name => $self->project,
127 $status
128 ? (
129 active_statuses => [ map { lc } @{ $status->{open} } ],
130 statuses =>
131 [ map { lc } @{ $status->{open} }, @{ $status->{closed} } ]
132 )
133 : (
134 active_statuses => [qw/new accepted started/],
135 statuses => [
136 qw/new accepted started duplicate fixed verified
137 invalid wontfix done/
138 ],
139 ),
140 };
141 }
142  
143 sub _uuid_url {
144 my $self = shift;
145 return $self->remote_url;
146 }
147  
148 __PACKAGE__->meta->make_immutable;
149 no Any::Moose;
150  
151 1;