Skip to content

Instantly share code, notes, and snippets.

@therealjasonkenney
Created July 1, 2013 21:52
Show Gist options
  • Save therealjasonkenney/5904962 to your computer and use it in GitHub Desktop.
Save therealjasonkenney/5904962 to your computer and use it in GitHub Desktop.
JIRA Client Example
#!/usr/bin/perl -w
#
#
use Data::Dumper;
use JSON;
use REST::Client;
sub fetch_jira_query {
my ($encrypted_user_pass, $query) = @_;
my $host = 'https://liaison-intl.atlassian.net';
my $fields = 'project,key,summary,priority,duedate,status';
my @rs = ();
# Don't change this part its the REST API
# See: https://docs.atlassian.com/jira/REST/latest/#idp1389824
my $headers = {
Accept => 'application/json',
Authorization => 'Basic ' . $encrypted_user_pass,
Content-Type => 'application/json'
};
my $client = REST::Client->new();
$client->setHost($host);
$client->GET(
'/rest/api/2/search?jql=' . $query . '&fields=' . $fields,
$headers
);
my $response = from_json($client->responseContent());
# print Dumper($response);
# This is the structure of the json response.
foreach (@{$response->{'issues'}}) {
my ($project, $issue, $description, $severity, $duedate, $status) =
(
$_->{fields}->{project}->{name},
$_->{key},
$_->{fields}->{summary},
$_->{fields}->{priority}->{name},
$_->{fields}->{duedate},
$_->{fields}->{status}->{name}
);
push @rs, {
service => $project,
ticket => $issue,
description => $description,
severity => $severity,
due => $duedate,
status => $status };
}
return \@rs;
}
# To set the encrypted_user_pass run the following command:
# perl -e ' use MIME::Base64; print encode_base64("user:pass");'
my $encrypted_user_pass = '<PUT COMMAND OUTPUT HERE>';
# Copy this from the query box for the filter.
my $query = 'project in (NUR, RFPTCAS, DHCAS, AHCAS) AND resolutiondate >= -1w AND ' .
'reporter in (dquilty, twhite, ltarassiouk, kodell, jfranco, kkendall, ' .
'bchin, lkuhnley, mlove) AND Type = "Production Issue" ORDER BY updated ' .
'DESC';
# List of fields, this should remain the same.
my $rs = fetch_jira_query($encrypted_user_pass, $query);
print Dumper $rs;
print "\n";
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment