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);
46 sub new ( $class, %opts ) {
47 croak "JIRA::new: Username not specified" unless $opts{username};
48 croak "JIRA::new: Password not specified" unless $opts{password};
49 croak "JIRA::new: Server not specified" unless $opts{server};
55 Create a new JIRA object connecting to the JIRA database
59 =for html <blockquote>
65 Username to authenticate with
69 Password to authenticate with
73 JIRA server to connect to
77 =for html </blockquote>
81 =for html <blockquote>
91 =for html </blockquote>
95 $opts{URL} = "http://$opts{server}/rest/api/latest";
97 $opts{rest} = JIRA::REST->new( $opts{URL}, $opts{username}, $opts{password} );
99 #$opts{rest} = JIRA::REST->new( { url => $opts{URL}, anonymous => 1 } );
101 return bless \%opts, $class;
104 sub findIssues ( $self, $condition, @fields ) {
110 Set up a find for JIRA issues based on a condition
114 =for html <blockquote>
120 Condition to use. JQL is supported
124 List of fields to retrieve data for
128 =for html </blockquote>
132 =for html <blockquote>
140 =for html </blockquote>
144 push @fields, '*all' unless @fields;
146 $findQuery{jql} = $condition || '';
147 $findQuery{startAt} = 0;
148 $findQuery{maxResults} = 1;
149 $findQuery{fields} = join ',', @fields;
154 sub getNextIssue ($self) {
159 =head2 getNextIssue ()
161 Get next qualifying issue. Call findIssues first
165 =for html <blockquote>
173 =for html </blockquote>
177 =for html <blockquote>
183 Perl hash of the fields in the next JIRA issue
187 =for html </blockquote>
191 eval { $result = $self->{rest}->GET( '/search/', \%findQuery ) };
193 $findQuery{startAt}++;
195 # Move id and key into fields
196 return unless @{ $result->{issues} };
198 $result->{issues}[0]{fields}{id} = $result->{issues}[0]{id};
199 $result->{issues}[0]{fields}{key} = $result->{issues}[0]{key};
201 return %{ $result->{issues}[0]{fields} };
205 return $self->{rest}{rest}->responseCode();
208 sub getIssues ( $self, $condition, $start, $max, @fields ) {
214 Get the @fields of JIRA issues based on a condition. Note that JIRA limits the
215 amount of entries returned to 1000. You can get fewer. Or you can use $start
216 to continue from where you've left off.
220 =for html <blockquote>
226 JQL condition to apply
230 Starting point to get issues from
234 Max number of entrist to get
238 List of fields to retrieve
242 =for html </blockquote>
246 =for html <blockquote>
252 Perl array of hashes of JIRA issue records
256 =for html </blockquote>
260 push @fields, '*all' unless @fields;
262 my ( $result, %query );
264 $query{jql} = $condition || '';
265 $query{startAt} = $start || 0;
266 $query{maxResults} = $max || 50;
267 $query{fields} = join ',', @fields;
269 eval { $result = $self->{rest}->GET( '/search/', \%query ) };
271 # We sometimes get an error here when $result->{issues} is undef.
272 # I suspect this is when the number of issues just happens to be
273 # an even number like on a $query{maxResults} boundry. So when
274 # $result->{issues} is undef we assume it's the last of the issues.
275 # (I should really verify this).
276 if ( $result->{issues} ) {
277 return @{ $result->{issues} };
284 sub getIssue ( $self, $issue, @fields ) {
290 Get individual JIRA issue
294 =for html <blockquote>
304 List of fields to retrieve
308 =for html </blockquote>
312 =for html <blockquote>
318 Perl hash of JIRA issue
322 =for html </blockquote>
326 my $fields = @fields ? "?fields=" . join ',', @fields : '';
328 return $self->{rest}->GET("/issue/$issue$fields");