4 =head1 NAME $RCSfile: JIRA.pm,v $
6 Minimal module to talk to JIRA and get a few fields
14 Andrew DeFaria <Andrew.DeFaria@WebPros.com>
38 use experimental qw(signatures);
47 sub new ( $class, %opts ) {
48 croak "JIRA::new: Username not specified" unless $opts{username};
49 croak "JIRA::new: Password not specified" unless $opts{password};
50 croak "JIRA::new: Server not specified" unless $opts{server};
56 Create a new JIRA object connecting to the JIRA database
60 =for html <blockquote>
66 Username to authenticate with
70 Password to authenticate with
74 JIRA server to connect to
78 =for html </blockquote>
82 =for html <blockquote>
92 =for html </blockquote>
96 $opts{URL} = "http://$opts{server}/rest/api/latest";
98 $opts{rest} = JIRA::REST->new( $opts{URL}, $opts{username}, $opts{password} );
100 return bless \%opts, $class;
103 sub findIssues ( $self, $condition, @fields ) {
109 Set up a find for JIRA issues based on a condition
113 =for html <blockquote>
119 Condition to use. JQL is supported
123 List of fields to retrieve data for
127 =for html </blockquote>
131 =for html <blockquote>
139 =for html </blockquote>
143 push @fields, '*all' unless @fields;
145 $findQuery{jql} = $condition || '';
146 $findQuery{startAt} = 0;
147 $findQuery{maxResults} = 1;
148 $findQuery{fields} = join ',', @fields;
153 sub getNextIssue ($self) {
158 =head2 getNextIssue ()
160 Get next qualifying issue. Call findIssues first
164 =for html <blockquote>
172 =for html </blockquote>
176 =for html <blockquote>
182 Perl hash of the fields in the next JIRA issue
186 =for html </blockquote>
190 eval { $result = $self->{rest}->GET( '/search/', \%findQuery ) };
192 $findQuery{startAt}++;
194 # Move id and key into fields
195 return unless @{ $result->{issues} };
197 $result->{issues}[0]{fields}{id} = $result->{issues}[0]{id};
198 $result->{issues}[0]{fields}{key} = $result->{issues}[0]{key};
200 return %{ $result->{issues}[0]{fields} };
203 sub getIssues ( $self, $condition, $start, $max, @fields ) {
209 Get the @fields of JIRA issues based on a condition. Note that JIRA limits the
210 amount of entries returned to 1000. You can get fewer. Or you can use $start
211 to continue from where you've left off.
215 =for html <blockquote>
221 JQL condition to apply
225 Starting point to get issues from
229 Max number of entrist to get
233 List of fields to retrieve
237 =for html </blockquote>
241 =for html <blockquote>
247 Perl array of hashes of JIRA issue records
251 =for html </blockquote>
255 push @fields, '*all' unless @fields;
257 my ( $result, %query );
259 $query{jql} = $condition || '';
260 $query{startAt} = $start || 0;
261 $query{maxResults} = $max || 50;
262 $query{fields} = join ',', @fields;
264 eval { $result = $self->{rest}->GET( '/search/', \%query ) };
266 # We sometimes get an error here when $result->{issues} is undef.
267 # I suspect this is when the number of issues just happens to be
268 # an even number like on a $query{maxResults} boundry. So when
269 # $result->{issues} is undef we assume it's the last of the issues.
270 # (I should really verify this).
271 if ( $result->{issues} ) {
272 return @{ $result->{issues} };
279 sub getIssue ( $self, $issue, @fields ) {
285 Get individual JIRA issue
289 =for html <blockquote>
299 List of fields to retrieve
303 =for html </blockquote>
307 =for html <blockquote>
313 Perl hash of JIRA issue
317 =for html </blockquote>
321 my $fields = @fields ? "?fields=" . join ',', @fields : '';
323 return $self->{rest}->GET("/issue/$issue$fields");