Debian Codegraph @

README

raw
1 NAME
2
3 JIRA::Client::Automated - A JIRA REST Client for automated scripts
4
5 VERSION
6
7 version 1.9
8
9 SYNOPSIS
10
11 use JIRA::Client::Automated;
12
13 my $jira = JIRA::Client::Automated->new($url, $user, $password);
14
15 # If your JIRA instance does not use username/password for authorization
16 my $jira = JIRA::Client::Automated->new($url);
17
18 my $jira_ua = $jira->ua(); # to add in a proxy
19
20 $jira->trace(1); # enable tracing of requests and responses
21
22 # The simplest way to create an issue
23 my $issue = $jira->create_issue($project, $type, $summary, $description);
24
25 # The simplest way to create a subtask
26 my $subtask = $jira->create_subtask($project, $summary, $description, $parent_key);
27
28 # A complex but flexible way to create a new issue, story, task or subtask
29 # if you know Jira issue hash structure well.
30 my $issue = $jira->create({
31 # Jira issue 'fields' hash
32 project => {
33 key => $project,
34 },
35 issuetype => {
36 name => $type, # "Bug", "Task", "Sub-task", etc.
37 },
38 summary => $summary,
39 description => $description,
40 parent => { # only required for a subtask
41 key => $parent_key,
42 },
43 ...
44 });
45
46
47 my $search_results = $jira->search_issues($jql, 1, 100); # query should be a single string of JQL
48 my @issues = $jira->all_search_results($jql, 1000); # query should be a single string of JQL
49
50 my $issue = $jira->get_issue($key);
51
52 $jira->update_issue($key, $update_hash); # update_hash is { field => value, ... }
53 $jira->create_comment($key, $text);
54 $jira->attach_file_to_issue($key, $filename);
55
56 $jira->transition_issue($key, $transition, $transition_hash); # transition_hash is { field => value, ... }
57
58 $jira->close_issue($key, $resolve, $comment); # resolve is the resolution value
59 $jira->delete_issue($key);
60
61 $jira->add_issue_watchers($key, $watcher1, ......);
62 $jira->add_issue_labels($key, $label1, ......);
63
64 DESCRIPTION
65
66 JIRA::Client::Automated is an adapter between any automated system and
67 JIRA's REST API. This module is explicitly designed to easily create
68 and close issues within a JIRA instance via automated scripts.
69
70 For example, if you run nightly batch jobs, you can use
71 JIRA::Client::Automated to have those jobs automatically create issues
72 in JIRA for you when the script runs into errors. You can attach error
73 log files to the issues and then they'll be waiting in someone's open
74 issues list when they arrive at work the next day.
75
76 If you want to avoid creating the same issue more than once you can
77 search JIRA for it first, only creating it if it doesn't exist. If it
78 does already exist you can add a comment or a new error log to that
79 issue.
80
81 WORKING WITH JIRA 6 Atlassian has made a very complete REST API for recent
82 (> 5.0) versions of JIRA. By virtue of being complete it is also somewhat
83 large and a little complex for the beginner. Reading their tutorials is
84 *highly* recommended before you start making hashes to update or transition
85 issues.
86
87 https://developer.atlassian.com/cloud/jira/platform/rest/#about
88
89 This module was designed for the JIRA 5.2.11 REST API, as of March
90 2013, but it works fine with JIRA 6.0 as well. Your mileage may vary
91 with future versions.
92
93 JIRA ISSUE HASH FORMAT
94
95 When you work with an issue in JIRA's REST API, it gives you a JSON
96 file that follows this spec:
97
98 https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-post
99
100 JIRA::Client::Automated tries to be nice to you and not make you deal
101 directly with JSON. When you create a new issue, you can pass in just
102 the pieces you want and "create_issue" will transform them to JSON for
103 you. The same for closing and deleting issues.
104
105 Updating and transitioning issues is more complex. Each JIRA
106 installation will have different fields available for each issue type
107 and transition screen and only you will know what they are. So in those
108 cases you'll need to pass in an "update_hash" which will be transformed
109 to the proper JSON by the method.
110
111 An update_hash looks like this:
112
113 { field1 => value, field2 => value2, ...}
114
115 For example:
116
117 {
118 host_id => "example.com",
119 { resolution => { name => "Resolved" } }
120 }
121
122 If you do not read JIRA's documentation about their JSON format you
123 will hurt yourself banging your head against your desk in frustration
124 the first few times you try to use "update_issue". Please RTFM.
125
126 Note that even though JIRA requires JSON, JIRA::Client::Automated will
127 helpfully translate it to and from regular hashes for you. You only
128 pass hashes to JIRA::Client::Automated, not direct JSON.
129
130 I recommend connecting to your JIRA server and calling "get_issue" with
131 a key you know exists and then dump the result. That'll get you
132 started.
133
134 METHODS
135
136 new
137
138 my $jira = JIRA::Client::Automated->new($url, $user, $password);
139
140 Create a new JIRA::Client::Automated object by passing in the
141 following:
142
143 1. URL for the JIRA server, such as "http://example.atlassian.net/"
144
145 2. Username to use to login to the JIRA server
146
147 3. Password for that user
148
149 All three parameters are required if your JIRA instance uses basic
150 authorization, for which JIRA::Client::Automated must connect to the
151 JIRA instance using some username and password. You may want to set up
152 a special "auto" or "batch" username to use just for use by scripts.
153
154 If you are using Google Account integration, the username and password
155 to use are the ones you set up at the very beginning of the
156 registration process and then never used again because Google logged
157 you in.
158
159 If you have other ways of authorization, like GSSAPI based
160 authorization, do not provide username or password.
161
162 my $jira = JIRA::Client::Automated->new($url);
163
164 ua
165
166 my $ua = $jira->ua();
167
168 Returns the LWP::UserAgent object used to connect to the JIRA instance.
169 Typically used to setup proxies or make other customizations to the
170 UserAgent. For example:
171
172 my $ua = $jira->ua();
173 $ua->env_proxy();
174 $ua->ssl_opts(...);
175 $ua->conn_cache( LWP::ConnCache->new() );
176
177 trace
178
179 $jira->trace(1); # enable
180 $jira->trace(0); # disable
181 $trace = $jira->trace;
182
183 When tracing is enabled each request and response is logged using carp.
184
185 create
186
187 my $issue = $jira->create({
188 # Jira issue 'fields' hash
189 project => {
190 key => $project,
191 },
192 issuetype => {
193 name => $type, # "Bug", "Task", "SubTask", etc.
194 },
195 summary => $summary,
196 description => $description,
197 parent => { # only required for a subtask
198 key => $parent_key,
199 },
200 ...
201 });
202
203 Creating a new issue, story, task, subtask, etc.
204
205 Returns a hash containing only the basic information about the new
206 issue, or dies if there is an error. The hash looks like:
207
208 {
209 id => 24066,
210 key => "TEST-57",
211 self => "https://example.atlassian.net/rest/api/latest/issue/24066"
212 }
213
214 See also
215 https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-post
216
217 create_issue
218
219 my $issue = $jira->create_issue($project, $type, $summary, $description, $fields);
220
221 Creating a new issue requires the project key, type ("Bug", "Task",
222 etc.), and a summary and description.
223
224 The optional $fields parameter can be used to pass a reference to a
225 hash of extra fields to be set when the issue is created, which avoids
226 the need for a separate "update_issue" call. For example:
227
228 $jira->create_issue($project, $type, $summary, $description, {
229 labels => [ "foo", "bar" ]
230 });
231
232 This method calls "create" and return the same hash reference that it
233 does.
234
235 create_subtask
236
237 my $subtask = $jira->create_subtask($project, $summary, $description, $parent_key);
238 # or with optional subtask type
239 my $subtask = $jira->create_subtask($project, $summary, $description, $parent_key, 'sub-task');
240
241 Creating a subtask. If your JIRA instance does not call subtasks
242 "Sub-task" or "sub-task", then you will need to pass in your subtask
243 type.
244
245 This method calls "create" and return the same hash reference that it
246 does.
247
248 update_issue
249
250 $jira->update_issue($key, $field_update_hash, $update_verb_hash);
251
252 There are two ways to express the updates you want to make to an issue.
253
254 For simple changes you pass $field_update_hash as a reference to a hash
255 of field_name => new_value pairs. For example:
256
257 $jira->update_issue($key, { summary => $new_summary });
258
259 That works for simple fields, but there are some, like comments, that
260 can't be updated in this way. For them you need to use
261 $update_verb_hash.
262
263 The $update_verb_hash parameter allow you to express a series of
264 specific operations (verbs) to be performed on each field. For example:
265
266 $jira->update_issue($key, undef, {
267 labels => [ { remove => "test" }, { add => "another" } ],
268 comments => [ { remove => { id => 10001 } } ]
269 });
270
271 The two forms of update can be combined in a single call.
272
273 For more information see:
274
275 L<https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-put>
276
277 get_issue
278
279 my $issue = $jira->get_issue($key);
280
281 Returns details for any issue, given its key. This call returns a hash
282 containing the information for the issue in JIRA's format. See "JIRA
283 ISSUE HASH FORMAT" for details.
284
285 transition_issue
286
287 $jira->transition_issue($key, $transition);
288 $jira->transition_issue($key, $transition, $update_hash);
289
290 Transitioning an issue is what happens when you click the button that
291 says "Resolve Issue" or "Start Progress" on it. Doing this from code is
292 harder, but JIRA::Client::Automated makes it as easy as possible.
293
294 You pass this method the issue key, the name of the transition or the
295 target status (spacing and capitalization matter), and an optional
296 update_hash containing any fields that you want to update.
297
298 Specifying The Transition
299
300 The provided $transition name is first matched against the available
301 transitions for the $key issue ('Start Progress', 'Close Issue'). If
302 there's no match then the names is matched against the available target
303 status names ('Open', 'Closed'). You can use whichever is most
304 appropriate. For example, in your configuration the transition names
305 might vary between different kinds of projects but the status names
306 might be the same. In which case scripts that are meant to work across
307 multiple projects might prefer to use the status names.
308
309 The $transition parameter can also be specified as a reference to an
310 array of names. In this case the first one that matches either a
311 transition name or status name is used. This makes it easier for
312 scripts to work across multiple kinds of projects and/or handle the
313 migration of names by allowing current and future names to be used, so
314 the later change in JIRA config doesn't cause any breakage.
315
316 Specifying Updates
317
318 If you have required fields on the transition screen (such as
319 "Resolution" for the "Resolve Issue" screen), you must pass those
320 fields in as part of the update_hash or you will get an error from the
321 server. See "JIRA ISSUE HASH FORMAT" for the format of the update_hash.
322
323 (Note: it appears that in some obscure cases missing required fields
324 may cause the transition to fail without causing an error from the
325 server. For example a field that's required but isn't configured to
326 appear on the transition screen.)
327
328 The $update_hash is a combination of the $field_update_hash and
329 $update_verb_hash parameters used by the "update_issue" method. Like
330 this:
331
332 $update_hash = {
333 fields => $field_update_hash,
334 update => $update_verb_hash
335 };
336
337 You can use it to express both simple field settings and more complex
338 update operations. For example:
339
340 $jira->transition_issue($key, $transition, {
341 fields => { summary => $new_summary },
342 update => {
343 labels => [ { remove => "test" }, { add => "another" } ],
344 comments => [ { remove => { id => 10001 } } ]
345 }
346 });
347
348 close_issue
349
350 $jira->close_issue($key);
351 $jira->close_issue($key, $resolve);
352 $jira->close_issue($key, $resolve, $comment);
353 $jira->close_issue($key, $resolve, $comment, $update_hash);
354 $jira->close_issue($key, $resolve, $comment, $update_hash, $operation);
355
356 Pass in the resolution reason and an optional comment to close an
357 issue. Using this method requires that the issue is is a status where
358 it can use the "Close Issue" transition (or other one, specified by
359 $operation). If not, you will get an error from the server.
360
361 Resolution ("Fixed", "Won't Fix", etc.) is only required if the issue
362 hasn't already been resolved in an earlier transition. If you try to
363 resolve an issue twice, you will get an error.
364
365 If you do not supply a comment, the default value is "Issue closed by
366 script".
367
368 The $update_hash can be used to set or edit the values of other fields.
369
370 The $operation parameter can be used to specify the closing transition
371 type. This can be useful when your JIRA configuration uses nonstandard
372 or localized transition and status names, e.g.
373
374 use utf8;
375 $jira->close_issue($key, $resolve, $comment, $update_hash, "Done");
376
377 See "transition_issue" for more details.
378
379 This method is a wrapper for "transition_issue".
380
381 delete_issue
382
383 $jira->delete_issue($key);
384
385 Deleting issues is for testing your JIRA code. In real situations you
386 almost always want to close unwanted issues with an "Oops!" resolution
387 instead.
388
389 create_comment
390
391 $jira->create_comment($key, $text);
392
393 You may use any valid JIRA markup in comment text. (This is handy for
394 tables of values explaining why something in the database is wrong.)
395 Note that comments are all created by the user you used to create your
396 JIRA::Client::Automated object, so you'll see that name often.
397
398 search_issues
399
400 my @search_results = $jira->search_issues($jql, 1, 100, $fields);
401
402 You've used JQL before, when you did an "Advanced Search" in the JIRA
403 web interface. That's the only way to search via the REST API.
404
405 This is a paged method. Pass in the starting result number and number
406 of results per page and it will return issues a page at a time. If you
407 know you want all of the results, you can use "all_search_results"
408 instead.
409
410 Optional parameter $fields is the arrayref containing the list of
411 fields to be returned.
412
413 This method returns a hashref containing up to five values:
414
415 1. total => total number of results
416
417 2. start => result number for the first result
418
419 3. max => maximum number of results per page
420
421 4. issues => an arrayref containing the actual found issues
422
423 5. errors => an arrayref containing error messages
424
425 For example, to page through all results $max at a time:
426
427 my (@all_results, @issues);
428 do {
429 $results = $self->search_issues($jql, $start, $max);
430 if ($results->{errors}) {
431 die join "\n", @{$results->{errors}};
432 }
433 @issues = @{$results->{issues}};
434 push @all_results, @issues;
435 $start += $max;
436 } until (scalar(@issues) < $max);
437
438 (Or just use "all_search_results" instead.)
439
440 all_search_results
441
442 my @issues = $jira->all_search_results($jql, 1000);
443
444 Like "search_issues", but returns all the results as an array of
445 issues. You can specify the maximum number to return, but no matter
446 what, it can't return more than the value of
447 jira.search.views.default.max for your JIRA installation.
448
449 get_issue_comments
450
451 $jira->get_issue_comments($key);
452
453 Returns arryref of all comments to the given issue.
454
455 attach_file_to_issue
456
457 $jira->attach_file_to_issue($key, $filename);
458
459 This method does not let you attach a comment to the issue at the same
460 time. You'll need to call "create_comment" for that.
461
462 Watch out for file permissions! If the user running the script does not
463 have permission to read the file it is trying to upload, you'll get
464 weird errors.
465
466 make_browse_url
467
468 my $url = $jira->make_browse_url($key);
469
470 A helper method to return the ".../browse/$key" url for the issue. It's
471 handy to make emails containing lists of bugs easier to create.
472
473 This just appends the key to the URL for the JIRA server so that you
474 can click on it and go directly to that issue.
475
476 get_link_types
477
478 my $all_link_types = $jira->get_link_types();
479
480 Get the arrayref of all possible link types.
481
482 link_issues
483
484 $jira->link_issues($from, $to, $type);
485
486 Establish a link of the type named $type from issue key $from to issue
487 key $to . Returns nothing on success; structure containing error
488 messages otherwise.
489
490 add_issue_labels
491
492 $jira->add_issue_labels($issue_key, @labels);
493
494 Adds one more more labels to the specified issue.
495
496 remove_issue_labels
497
498 $jira->remove_issue_labels($issue_key, @labels);
499
500 Removes one more more labels from the specified issue.
501
502 add_issue_watchers
503
504 $jira->add_issue_watchers($key, @watchers);
505
506 Adds watchers to the specified issue. Returns nothing if success;
507 otherwise returns a structure containing error message.
508
509 get_issue_watchers
510
511 $jira->get_issue_watchers($key);
512
513 Returns arryref of all watchers of the given issue.
514
515 assign_issue
516
517 $jira->assign_issue($key, $assignee_name);
518
519 Assigns the issue to that person. Returns the key of the issue if it
520 succeeds.
521
522 add_issue_worklog
523
524 $jira->add_issue_worklog($key, $worklog);
525
526 Adds a worklog to the specified issue. Returns nothing if success;
527 otherwise returns a structure containing error message.
528
529 Sample worklog: { "comment" => "I did some work here.", "started" =>
530 "2016-05-27T02:32:26.797+0000", "timeSpentSeconds" => 12000, }
531
532 get_issue_worklogs
533
534 $jira->get_issue_worklogs($key);
535
536 Returns arryref of all worklogs of the given issue.
537
538 FAQ
539
540 Why is there no object for a JIRA issue?
541
542 Because it seemed silly. You could write such an object and give it
543 methods to transition itself, close itself, etc., but when you are
544 working with JIRA from batch scripts, you're never really working with
545 just one issue at a time. And when you have a hundred of them, it's
546 easier to not objectify them and just use JIRA::Client::Automated as a
547 mediator. That said, if this is important to you, I wouldn't say no to
548 a patch offering this option.
549
550 BUGS
551
552 Please report bugs or feature requests to the author.
553
554 AUTHOR
555
556 Michael Friedman <[email protected]>
557
558 CREDITS
559
560 Thanks very much to:
561
562 Tim Bunce <[email protected]>
563
564 Dominique Dumont <[email protected]>
565
566 Zhuang (John) Li <[email protected]>
567
568 Ivan E. Panchenko <[email protected]>
569
570 José Antonio Perez Testa <[email protected]>
571
572 Frank Schophuizen <[email protected]>
573
574 Zhenyi Zhou <[email protected]>
575
576 Roy Lyons <[email protected]>
577
578 Neil Hemingway <[email protected]>
579
580 Andreas Mager <[email protected]>
581
582 Mike Svendsen <[email protected]>
583
584 COPYRIGHT AND LICENSE
585
586 This software is copyright (c) 2016 by Polyvore, Inc.
587
588 This is free software; you can redistribute it and/or modify it under
589 the same terms as the Perl 5 programming language system itself.
590