line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Redmine::Fetch; |
2
|
1
|
|
|
1
|
|
414
|
use 5.008001; |
|
1
|
|
|
|
|
2
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
16
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
778
|
use DateTime; |
|
1
|
|
|
|
|
68571
|
|
|
1
|
|
|
|
|
31
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
479
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
144904
|
|
|
1
|
|
|
|
|
8
|
|
11
|
1
|
|
|
1
|
|
458
|
use DDP; |
|
1
|
|
|
|
|
22780
|
|
|
1
|
|
|
|
|
9
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $_config; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
1
|
|
my ( $self, $server, $api_key, $project_id, $filter ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
$_config = { |
20
|
|
|
|
|
|
|
server => $server, |
21
|
|
|
|
|
|
|
api_key => $api_key, |
22
|
|
|
|
|
|
|
project_id => $project_id, |
23
|
|
|
|
|
|
|
filter => $filter, |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub ua_config { |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return $_config; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub redmine_ua { |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
0
|
1
|
|
my ( $self, $mode, $call, $payload ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $config = $self->ua_config; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $response = ''; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
eval { |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $header = { "X-Redmine-API-Key" => $config->{api_key} }; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $tx = ''; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $params = { project_id => $config->{project_id}, }; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ( $mode eq 'put' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$tx = $ua->put( $config->{server} . '/' . $call . '.json' => $header => json => $payload ); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} elsif ( $mode eq 'delete' ) { |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$tx = $ua->delete( $config->{server} . '/' . $call . '.json' => $header ); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} elsif ( $mode eq 'post' ) { |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$tx = $ua->post( $config->{server} . '/' . $call . '.json' => $header => json => $payload ); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} else { |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $combined_payload = { %$payload, %$params }; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$tx = $ua->get( $config->{server} . '/' . $call . '.json' => $header => form => $combined_payload ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ( my $res = $tx->success ) { |
74
|
0
|
|
|
|
|
|
$response = $res->json; |
75
|
|
|
|
|
|
|
} else { |
76
|
0
|
|
|
|
|
|
warn 'fail'; |
77
|
0
|
|
|
|
|
|
p $tx->body; |
78
|
0
|
|
|
|
|
|
my $err = $tx->error; |
79
|
0
|
0
|
|
|
|
|
die "$err->{code} response: $err->{message}" if $err->{code}; |
80
|
0
|
|
|
|
|
|
die "Connection error: $err->{message}"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $response; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub update_or_create_wiki_page { |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
1
|
|
my ( $self, $project_name, $path, $name, $content, $parent_title, $comment ) = @_; |
91
|
0
|
|
0
|
|
|
|
$parent_title ||= ''; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
0
|
|
|
|
my $attach = { wiki_page => { title => $name, text => $content, comments => $comment || "automaticly generated by Redmine::Fetch", parent_title => $parent_title } }; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $call = 'projects/' . $project_name . '/wiki/' . $path; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $response = $self->redmine_ua( 'put', $call, $attach ); |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return $response; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub delete_wiki_page { |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
0
|
1
|
|
my ( $self, $project_name, $path ) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $call = 'projects/' . $project_name . '/wiki/' . $path; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my $response = $self->redmine_ua( 'delete', $call, '' ); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $response; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub get_tickets { |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
0
|
1
|
|
my ( $self, $params ) = @_; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
0
|
|
|
|
$params->{tracker_id} ||= 1; |
119
|
0
|
|
0
|
|
|
|
$params->{limit} ||= 500; |
120
|
0
|
|
0
|
|
|
|
$params->{sort} ||= 'created_on:desc'; |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
if ( my $filter = $self->ua_config->{filter} ) { |
123
|
0
|
|
|
|
|
|
$params->{cf_3} = $filter; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $tickets = { issues => [] }; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$params->{status_id} = join( "|", @{ $params->{states} } ); |
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$tickets = $self->redmine_ua( 'get', 'issues', $params ); |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return $tickets->{issues}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub create_ticket { |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
0
|
1
|
|
my ( $self, $subject, $description, $payload ) = @_; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $default_payload = { subject => $subject, description => $description, project_id => $self->ua_config->{project_id} }; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$payload = { issue => { %$default_payload, %$payload } }; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $response = $self->redmine_ua( 'post', 'issues', $payload ); |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
return $response; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub delete_ticket { |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
0
|
1
|
|
my ( $self, $ticket_id ) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $response = $self->redmine_ua( 'delete', 'issues/' . $ticket_id ); |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
return $response; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub get_ticket_by_id { |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
0
|
1
|
|
my ( $self, $ticket_id, $build_link_callback ) = @_; |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
my $params = { |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
include => 'relations', |
166
|
|
|
|
|
|
|
}; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my $ticket = $self->redmine_ua( 'get', 'issues/' . $ticket_id, $params ); |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
$ticket = $ticket->{issue}; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
$ticket->{description} =~ s/(\#)(\d+)/''.$1.$2.'<\/a>'/ge; |
|
0
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
$ticket->{related_tickets} = []; |
175
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
if ( $ticket->{relations} ) { |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
foreach my $relation ( @{ $ticket->{relations} } ) { |
|
0
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
0
|
0
|
|
|
|
|
next if $relation->{relation_type} ne 'relates'; |
181
|
|
|
|
|
|
|
|
182
|
0
|
0
|
|
|
|
|
my $relation_id = ( $ticket->{id} == $relation->{issue_id} ) ? $relation->{issue_to_id} : $relation->{issue_id}; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
my $related_ticket = $self->redmine_ua( 'get', 'issues/' . $relation_id, {} ); |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
push @{ $ticket->{related_tickets} }, $related_ticket->{issue}; |
|
0
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
return $ticket; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
__END__ |