Getting a JIRA issue’s priority using Perl

JIRA::Client is a great and useful module. Too bad some of its usage is so cryptic!

For example – suppose you want to print an issue’s priority field. if you simply use $issue->{priority} you will get the priority id, not the display name which everyone is used too.
So, how to get the display name? documentation is very vague on this subject. Google doesn’t help much here.

After a lot of trial & error I figured out a way.

I’m not big on hashes, arrays, and their conversions, so I’m sure this perl code can be easily optimized. But at least it works!

sub jira_get_priority
    my ($jira, $issue) = @_;
    my $prios = $jira->get_priorities();
    my %Priorities = %$prios;
    my $prio = $issue->{priority};
    foreach my $key (keys(%Priorities))
        if ($prio eq $Priorities{$key}->{id})
            return $key;
    return "";

If you can help make it more “perl-ish”, be sure to drop me a line in the comments below 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s