diff --git a/modules/Bio/EnsEMBL/Compara/RunnableDB/CreateDCJiraTickets.pm b/modules/Bio/EnsEMBL/Compara/RunnableDB/CreateDCJiraTickets.pm index 718dac7c4f3..cab092ea9bc 100644 --- a/modules/Bio/EnsEMBL/Compara/RunnableDB/CreateDCJiraTickets.pm +++ b/modules/Bio/EnsEMBL/Compara/RunnableDB/CreateDCJiraTickets.pm @@ -36,7 +36,9 @@ sub param_defaults { my $self = shift; return { %{$self->SUPER::param_defaults}, + 'merge_ticket_key' => undef, 'test_mode' => 0, + 'csv_mode' => 0, } } @@ -44,22 +46,33 @@ sub run { my $self = shift; my $jira_exe = $self->param_required('create_datacheck_tickets_exe'); + my $tap_file = $self->param_required('output_results'); + + my $merge_ticket_key_param = $self->param_is_defined('merge_ticket_key') + ? sprintf('--merge_ticket_key %s', $self->param('merge_ticket_key')) + : ''; + + my $csv_param = $self->param('csv_mode') + ? sprintf('--csv %s.csv', $tap_file) + : ''; my $command = join(" ", ( - $jira_exe, $self->param_required('output_results'), "--update", + $jira_exe, $tap_file, "--update", "--division", $self->param_required('division'), ( $self->param('datacheck_type') ? '--label ' . $self->param('datacheck_type') : '' ), - ( $self->param('dry_run') ? '--dry_run' : '') + ( $self->param('dry_run') ? '--dry_run' : ''), + $merge_ticket_key_param, + $csv_param, )); $self->warning( "Command: " . $command ); return if $self->param('test_mode'); - if (defined $ENV{'JIRA_AUTH_TOKEN'}) { + if (defined $ENV{'JIRA_AUTH_TOKEN'} || $self->param('csv_mode')) { $self->run_command($command, { die_on_failure => 1, }); } else { - $self->warning( "ERROR: ENV variable not defined: \$JIRA_AUTH_TOKEN. Define with:\nexport JIRA_AUTH_TOKEN=$(echo -n 'user:pass' | openssl base64)" ); + $self->die_no_retry( "ERROR: ENV variable not defined: \$JIRA_AUTH_TOKEN. Define with:\nexport JIRA_AUTH_TOKEN=$(echo -n 'user:pass' | openssl base64)" ); } } diff --git a/modules/t/createDCJiraTickets.t b/modules/t/createDCJiraTickets.t index 45aff1d3fd1..4827a046f41 100644 --- a/modules/t/createDCJiraTickets.t +++ b/modules/t/createDCJiraTickets.t @@ -36,14 +36,11 @@ standaloneJob( 'dry_run' => 1, 'create_datacheck_tickets_exe' => '$ENSEMBL_ROOT_DIR/ensembl-compara/scripts/jira_tickets/create_datacheck_tickets.pl', 'division' => 'vertebrates', - 'test_mode' => 1, }, - [ - [ - 'WARNING', - "Command: \$ENSEMBL_ROOT_DIR/ensembl-compara/scripts/jira_tickets/create_datacheck_tickets.pl $test_infile --update --division vertebrates --dry_run", - ], - ] + undef, + { + 'expect_failure' => 1, + }, ); standaloneJob( @@ -54,15 +51,11 @@ standaloneJob( 'dry_run' => 1, 'create_datacheck_tickets_exe' => '$ENSEMBL_ROOT_DIR/ensembl-compara/scripts/jira_tickets/create_datacheck_tickets.pl', 'division' => 'vertebrates', - 'test_mode' => 1, - }, - [ - [ - 'WARNING', - "Command: \$ENSEMBL_ROOT_DIR/ensembl-compara/scripts/jira_tickets/create_datacheck_tickets.pl $test_infile --update --division vertebrates --label critical --dry_run", - ], - ] + undef, + { + 'expect_failure' => 1, + }, ); done_testing(); diff --git a/scripts/jira_tickets/create_datacheck_tickets.pl b/scripts/jira_tickets/create_datacheck_tickets.pl index b6bf64f525b..2ee0a5caae1 100755 --- a/scripts/jira_tickets/create_datacheck_tickets.pl +++ b/scripts/jira_tickets/create_datacheck_tickets.pl @@ -57,6 +57,16 @@ =head1 OPTIONS In dry-run mode, the JIRA tickets will not be submitted to the JIRA server. By default, dry-run mode is off. +=item B<-csv> + +Optional. Instead of creating JIRA tickets, +output to a CSV file to be imported to JIRA. + +=item B<-merge_ticket_key> + +Optional. Merge ticket key. If specified, datacheck +tickets will be created as subtasks of this ticket. + =item B<-h[elp]> Print usage information. @@ -77,7 +87,7 @@ =head1 OPTIONS use Bio::EnsEMBL::Compara::Utils::JIRA; -my ( $release, $division, @labels, $update, $dry_run, $help ); +my ( $release, $division, @labels, $update, $dry_run, $csv, $merge_ticket_key, $help ); $update = 0; $dry_run = 0; $help = 0; @@ -87,6 +97,8 @@ =head1 OPTIONS "label=s" => \@labels, "update" => \$update, 'dry_run|dry-run' => \$dry_run, + 'csv=s' => \$csv, + 'merge_ticket_key=s' => \$merge_ticket_key, "h|help" => \$help, ); pod2usage(1) if $help; @@ -97,15 +109,19 @@ =head1 OPTIONS my $dc_abs_path = abs_path($dc_file); # Get a new Utils::JIRA object to create the tickets for the given division and # release -my $jira_adaptor = Bio::EnsEMBL::Compara::Utils::JIRA->new(-DIVISION => $division, -RELEASE => $release); +my $jira_adaptor = Bio::EnsEMBL::Compara::Utils::JIRA->new(-DIVISION => $division, -RELEASE => $release, -CSV => $csv); # Parse Datacheck information from input TAP file my $testcase_failures = parse_datachecks($dc_file); unless ( %$testcase_failures ) { print "No failed DCs found in $dc_file\n"; exit; } + +if (!defined $merge_ticket_key) { + $merge_ticket_key = find_labeled_ticket($jira_adaptor, 'Merge_anchor'); +} + # Create a task ticket for each datacheck subtest failure -my $merge_ticket_key = find_labeled_ticket($jira_adaptor, 'Merge_anchor'); my @json_subtasks; foreach my $testcase ( keys %$testcase_failures ) { my $failure_subtask_json = { @@ -117,21 +133,36 @@ =head1 OPTIONS } my $components = ['Datachecks', 'Production tasks']; my $categories = ['Bug::Internal', 'Production::Tasks']; -# Create all JIRA tickets -my $dc_task_keys = $jira_adaptor->create_tickets( - -JSON_OBJ => \@json_subtasks, - -DEFAULT_ISSUE_TYPE => 'Sub-task', - -DEFAULT_PRIORITY => 'Blocker', - -EXTRA_COMPONENTS => $components, - -EXTRA_CATEGORIES => $categories, - -EXTRA_LABELS => \@labels, - -UPDATE => $update, - -DRY_RUN => $dry_run -); -# Create a blocker issue link between the newly created datacheck ticket and the -# handover ticket if it doesn't already exist -my $blocked_ticket_key = find_labeled_ticket($jira_adaptor, 'Handover_anchor'); -$jira_adaptor->link_tickets('Blocks', $dc_task_keys->[0], $blocked_ticket_key, $dry_run); + +if ($csv) { + $jira_adaptor->create_ticket_csv( + -JSON_OBJ => \@json_subtasks, + -DEFAULT_ISSUE_TYPE => 'Sub-task', + -DEFAULT_PRIORITY => 'Blocker', + -EXTRA_COMPONENTS => $components, + -EXTRA_CATEGORIES => $categories, + -EXTRA_LABELS => \@labels, + -DRY_RUN => $dry_run, + -CSV_FILE => $csv, + -PARENT_LINK => $merge_ticket_key, + ); +} else { + # Create all JIRA tickets + my $dc_task_keys = $jira_adaptor->create_tickets( + -JSON_OBJ => \@json_subtasks, + -DEFAULT_ISSUE_TYPE => 'Sub-task', + -DEFAULT_PRIORITY => 'Blocker', + -EXTRA_COMPONENTS => $components, + -EXTRA_CATEGORIES => $categories, + -EXTRA_LABELS => \@labels, + -UPDATE => $update, + -DRY_RUN => $dry_run + ); + # Create a blocker issue link between the newly created datacheck ticket and the + # handover ticket if it doesn't already exist + my $blocked_ticket_key = find_labeled_ticket($jira_adaptor, 'Handover_anchor'); + $jira_adaptor->link_tickets('Blocks', $dc_task_keys->[0], $blocked_ticket_key, $dry_run); +} sub parse_datachecks { my $dc_file = shift;