Agnus Dei (jackal) wrote,
Agnus Dei
jackal

Parsing JSON returned by JIRA

#---------------------------
# JIRA returns it's data in JSON, 
#   but it's a hash reference inside an array list... so that's pretty confusing.
#----------------------------
use strict;
use Data::Dumper;
use JSON qw( decode_json );

sub get_current_issues {
   my $jira_username="mememe";
   my $jira_password="lalalal";
   my $jira_hostname="jira.mycompany.com";
   ########################################################################################
   # Pull in the current open tickets for this user
   ########################################################################################
   my $jira_url="https://${jira_hostname}/rest/api/2/search?jql=status+%21%3D+Closed+AND+status+%21%3D+Resolved+AND+assignee+%3D+${jira_username}";

   my $current_issues_str=`curl -u $jira_username:$jira_password -X GET -H 'Content-Type: application/json' --insecure --silent $jira_url`;

   my $json = JSON->new->allow_nonref;

   my $obj= $json->decode($current_issues_str);
   foreach ( @{ $obj->{'issues'} }) {
      #print Dumper($_);
      #print $_->{'fields'}->{'description'} . "\n";
      print $_->{'key'} . ": " . $_->{'fields'}->{'summary'} . "\n";
   }
   exit; 
}
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 0 comments