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>
35 Friday, October 21, 2022
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. CPANEL-1928) can be just a number and if so "CPANEL-" 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.
72 Note: If you don't specify a case ID then an attempt will be made to determine
73 the case ID from the branch name.
78 use experimental qw(signatures);
85 use lib "$FindBin::Bin/../lib";
91 my $conf = "$ENV{HOME}/.jira";
93 my %opts = GetConfig::GetConfig($conf);
95 $opts{usage} = sub { pod2usage };
97 pod2usage( -verbose => 2 );
100 sub display_info ($case) {
101 say "$case->{key}: $case->{fields}{summary}";
105 if ( $opts{assignee} ) {
106 if ( $case->{fields}{assignee} ) {
107 $assignee = "$case->{fields}{assignee}{displayName} <$case->{fields}{assignee}{emailAddress}>";
110 $assignee = 'Unassigned';
113 say "Assigned to: $assignee";
116 if ( $opts{reporter} ) {
117 say "Reporter: $case->{fields}{reporter}{displayName} <$case->{fields}{reporter}{emailAddress}>";
120 if ( $opts{status} ) {
121 say "Status: $case->{fields}{status}{name}";
139 unless ( $ARGV[0] ) {
141 # Try to get case number from branch
142 my ( $status, @output ) = Utils::Execute("git branch --show-current 2>&1");
145 if ($output[0] =~ /(\w+-)*(\d+)/) {
151 pod2usage("ERROR: A case ID required\n") unless $ARGV[0];
153 $opts{server} //= 'jira.cpanel.net';
155 my $jira = JIRA->new(%opts);
159 for my $caseID (@cases) {
160 if ( $caseID =~ /^(\d+)$/ ) {
161 $caseID = "CPANEL-$1";
167 eval { $case = $jira->getIssue($caseID); };
169 if ( $jira->status() == 401 ) {
170 die "Unable to authenticate username/password\n";
172 elsif ( $jira->status() == 404 ) {
173 say STDERR "ERROR: $caseID does not exist";
175 elsif ( $jira->status == 200 ) {
176 display_info($case) if $jira->status == 200;
180 die "ERROR: Unknown status returned - $status\n";