1 #!/usr/local/cpanel/3rdparty/bin/perl
3 # cpanel - t/medium/Cpanel-LogReader.t Copyright 2022 cPanel, L.L.C.
5 # copyright@cpanel.net http://cpanel.net
6 # This code is subject to the cPanel license. Unauthorized copying is prohibited
15 Get info about a JIRA case
23 Andrew DeFaria <Andrew.DeFaria@WebPros.com>
41 Usage: jira [-assignee] [-reporter] [-username <username>] [-password <password>] [-server <server>]
46 -usa|ge: Displays this usage
47 -h|elp: Display full help
48 -a|ssginee: Display assignee info
49 -r|eporter: Display Reporter info
50 -st|atus: Display status
51 -use|rname: Username for JIRA
52 -p|assword: Password for JIRA
53 -se|rver: JIRA server (Default: jira.cpanel.net)
58 This script looks up a JIRA case and displays its summary. It can also display
59 the reporter and assignee. More fields can be added later on.
61 Note: Case ID (e.g. ART-1928) can be just a number and if so "ART-" will be
64 Credentials should be put in ~/.jira and the file properly secured
68 server: <jira.cpanel.net>
70 If server is not specified jira.cpanel.net will be assumed
75 use experimental qw(signatures);
82 use lib "$FindBin::Bin/../lib";
87 my $conf = "$ENV{HOME}/.jira";
89 my %opts = GetConfig::GetConfig($conf);
91 $opts{usage} = sub { pod2usage };
93 pod2usage( -verbose => 2 );
96 sub display_info ($case) {
97 say "$case->{key}: $case->{fields}{summary}";
101 if ( $opts{assignee} ) {
102 if ( $case->{fields}{assignee} ) {
103 $assignee = "$case->{fields}{assignee}{displayName} <$case->{fields}{assignee}{emailAddress}>";
106 $assignee = 'Unassigned';
109 say "Assigned to: $assignee";
112 if ( $opts{reporter} ) {
113 say "Reporter: $case->{fields}{reporter}{displayName} <$case->{fields}{reporter}{emailAddress}>";
116 if ( $opts{status} ) {
117 say "Status: $case->{fields}{status}{name}";
135 pod2usage("ERROR: A case ID required\n") unless $ARGV[0];
137 $opts{server} //= 'jira.cpanel.net';
139 my $jira = JIRA->new(%opts);
143 for my $caseID (@cases) {
144 if ( $caseID =~ /^(\d+)$/ ) {
151 eval { $case = $jira->getIssue($caseID); };
153 if ( $jira->status() == 401 ) {
154 die "Unable to authenticate username/password\n";
156 elsif ( $jira->status() == 404 ) {
157 say STDERR "ERROR: $caseID does not exist";
159 elsif ( $jira->status == 200 ) {
160 display_info($case) if $jira->status == 200;
164 die "ERROR: Unknown status returned - $status\n";