Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use Util::CommandLine 'options';
- use JIRA::REST;
- use Date::Parse 'str2time';
- use Date::Format 'time2str';
- use Text::CSV_XS;
- my $settings = options( qw( url|l=s user|u=s passwd|p=s size|s=s jqp|q=s file|f=s ) );
- open( my $fh, '>:encoding(utf8)', $settings->{file} || 'out.csv' ) or die $!;
- my $jira = JIRA::REST->new({
- url => $settings->{url},
- username => $settings->{user},
- password => $settings->{passwd},
- });
- my $iteration_size = $settings->{size} || 500;
- my $max_results = $settings->{max} || 500;
- my ( $total, $iteration, @issues );
- while ( not defined $total or @issues < $total ) {
- my $search = $jira->POST( '/search', undef, {
- jql => $settings->{jql} || 'status != "Done"',
- startAt => $iteration++ * $iteration_size,
- maxResults => $iteration_size,
- fields => [ qw(
- summary assignee status priority subtasks created
- aggregateprogress aggregatetimeestimate aggregatetimespent
- ) ],
- } );
- push( @issues, map {
- $_->{fields}{created} = time2str( '%D', str2time( $_->{fields}{created} ) );
- $_;
- } @{ $search->{issues} } );
- last if ( $max_results and @issues >= $max_results );
- $total = $search->{total};
- }
- my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 });
- $csv->say( $fh, [ 'ID', 'Task Mode', 'Name', 'Created', 'Hyperlink', 'Resource Names', 'Duration' ] );
- my $id;
- for my $issue ( sort { $a->{fields}{created} cmp $b->{fields}{created} } @issues ) {
- $csv->say( $fh, [
- ++$id,
- 'Auto Scheduled',
- $issue->{key} . ': ' . $issue->{fields}{summary},
- $issue->{fields}{created},
- $settings->{url} . '/browse/' . $issue->{key},
- $issue->{fields}{assignee}{displayName},
- '1d',
- ] );
- }
- =head1 NAME
- jira2mpp - Create a CSV for importing into Microsoft Project from Jira data
- =head1 SYNOPSIS
- jira2mpp [OPTIONS] [FILE]
- -q|jql JIRA_QUERY # Jira query (defaults to status != "Done")
- -f|file CSV_FILENAME # Output CSV filename (defaults to "out.csv")
- -m|max MAX_RESULTS # Exit pull after at least this number of results
- -s|size ITERATION_SIZE # Number of issues to pull per iteration loop
- -l|url JIRA_URL # Jira location
- -u|user USERNAME # Jira username
- -p|passwd PASSWORD # Jira password
- -h|help # brief help message
- -m|man # full documentation
- =head1 DESCRIPTION
- This program pulls issues data from Jira based on a Jira query and creates a
- CSV file that's ready for importing into Microsoft Project.
- B<IMPORTANT:> Before importing in Microsoft Project, set your Microsoft Project permissions
- to allow for importing from non-standard sources. Go to: File, Options, Trust
- Center. Click "Trust Center Settings" and select "Legacy Formats."
- =head2 jql
- The C<jql> is the Jira query the program should use to select issues to pull.
- By default, the C<jql> is:
- status != "Done"
- =head2 size
- This is purely a performance tuning option. The program will call Jira and
- request a certain number, limited by C<size>, of issues per each call. It will
- 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