Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use Util::CommandLine 'options';
  5. use JIRA::REST;
  6. use Date::Parse 'str2time';
  7. use Date::Format 'time2str';
  8. use Text::CSV_XS;
  9.  
  10. my $settings = options( qw( url|l=s user|u=s passwd|p=s size|s=s jqp|q=s file|f=s ) );
  11.  
  12. open( my $fh, '>:encoding(utf8)', $settings->{file} || 'out.csv' ) or die $!;
  13.  
  14. my $jira = JIRA::REST->new({
  15. url => $settings->{url},
  16. username => $settings->{user},
  17. password => $settings->{passwd},
  18. });
  19.  
  20. my $iteration_size = $settings->{size} || 500;
  21. my $max_results = $settings->{max} || 500;
  22.  
  23. my ( $total, $iteration, @issues );
  24.  
  25. while ( not defined $total or @issues < $total ) {
  26. my $search = $jira->POST( '/search', undef, {
  27. jql => $settings->{jql} || 'status != "Done"',
  28. startAt => $iteration++ * $iteration_size,
  29. maxResults => $iteration_size,
  30. fields => [ qw(
  31. summary assignee status priority subtasks created
  32. aggregateprogress aggregatetimeestimate aggregatetimespent
  33. ) ],
  34. } );
  35.  
  36. push( @issues, map {
  37. $_->{fields}{created} = time2str( '%D', str2time( $_->{fields}{created} ) );
  38. $_;
  39. } @{ $search->{issues} } );
  40.  
  41. last if ( $max_results and @issues >= $max_results );
  42. $total = $search->{total};
  43. }
  44.  
  45. my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 });
  46. $csv->say( $fh, [ 'ID', 'Task Mode', 'Name', 'Created', 'Hyperlink', 'Resource Names', 'Duration' ] );
  47.  
  48. my $id;
  49. for my $issue ( sort { $a->{fields}{created} cmp $b->{fields}{created} } @issues ) {
  50. $csv->say( $fh, [
  51. ++$id,
  52. 'Auto Scheduled',
  53. $issue->{key} . ': ' . $issue->{fields}{summary},
  54. $issue->{fields}{created},
  55. $settings->{url} . '/browse/' . $issue->{key},
  56. $issue->{fields}{assignee}{displayName},
  57. '1d',
  58. ] );
  59. }
  60.  
  61. =head1 NAME
  62.  
  63. jira2mpp - Create a CSV for importing into Microsoft Project from Jira data
  64.  
  65. =head1 SYNOPSIS
  66.  
  67. jira2mpp [OPTIONS] [FILE]
  68.  
  69. -q|jql JIRA_QUERY # Jira query (defaults to status != "Done")
  70. -f|file CSV_FILENAME # Output CSV filename (defaults to "out.csv")
  71. -m|max MAX_RESULTS # Exit pull after at least this number of results
  72. -s|size ITERATION_SIZE # Number of issues to pull per iteration loop
  73. -l|url JIRA_URL # Jira location
  74. -u|user USERNAME # Jira username
  75. -p|passwd PASSWORD # Jira password
  76. -h|help # brief help message
  77. -m|man # full documentation
  78.  
  79. =head1 DESCRIPTION
  80.  
  81. This program pulls issues data from Jira based on a Jira query and creates a
  82. CSV file that's ready for importing into Microsoft Project.
  83.  
  84. B<IMPORTANT:> Before importing in Microsoft Project, set your Microsoft Project permissions
  85. to allow for importing from non-standard sources. Go to: File, Options, Trust
  86. Center. Click "Trust Center Settings" and select "Legacy Formats."
  87.  
  88. =head2 jql
  89.  
  90. The C<jql> is the Jira query the program should use to select issues to pull.
  91. By default, the C<jql> is:
  92.  
  93. status != "Done"
  94.  
  95. =head2 size
  96.  
  97. This is purely a performance tuning option. The program will call Jira and
  98. request a certain number, limited by C<size>, of issues per each call. It will
  99. keep doing this until the program has pulled at least C<max> number of issues.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement