Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable datacheck Jira ticket CSV output #871

Open
wants to merge 2 commits into
base: release/114
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions modules/Bio/EnsEMBL/Compara/RunnableDB/CreateDCJiraTickets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,43 @@ sub param_defaults {
my $self = shift;
return {
%{$self->SUPER::param_defaults},
'merge_ticket_key' => undef,
'test_mode' => 0,
'csv_mode' => 0,
}
}

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)" );
}

}
Expand Down
23 changes: 8 additions & 15 deletions modules/t/createDCJiraTickets.t
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
67 changes: 49 additions & 18 deletions scripts/jira_tickets/create_datacheck_tickets.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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> <PATH>

Optional. Instead of creating JIRA tickets,
output to a CSV file to be imported to JIRA.

=item B<-merge_ticket_key> <STR>

Optional. Merge ticket key. If specified, datacheck
tickets will be created as subtasks of this ticket.

=item B<-h[elp]>

Print usage information.
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 = {
Expand All @@ -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;
Expand Down