PageRenderTime 38ms CodeModel.GetById 20ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/jira-dump.pl

https://code.google.com/
Perl | 82 lines | 53 code | 13 blank | 16 comment | 4 complexity | 64533757624095125d6e5b3767d78422 MD5 | raw file
 1#!/usr/bin/env perl
 2
 3# Copyright (C) 2012 by CPqD
 4
 5# This program is free software: you can redistribute it and/or modify
 6# it under the terms of the GNU General Public License as published by
 7# the Free Software Foundation, either version 3 of the License, or
 8# (at your option) any later version.
 9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18use 5.014;
19use utf8;
20use autodie;
21use warnings;
22use open ':utf8';
23use JIRA::Client;
24use Data::Dumper;
25use Getopt::Long;
26
27my $usage = "$0 [--projects] [--verbose] JIRAURL USER PASS\n";
28my $Projects;
29my $Verbose;
30GetOptions(
31    'projects+' => \$Projects,
32    'verbose+'  => \$Verbose,
33) or die $usage;
34
35@ARGV == 3 or die "usage: $usage\n";
36
37my $jira = JIRA::Client->new(@ARGV);
38
39sub hash_of {
40    my ($array, $key) = @_;
41    $key //= 'name';
42    my %hash;
43    foreach my $e (@$array) {
44	$hash{$e->{$key}} = $e;
45    }
46    return \%hash;
47}
48
49my %JIRA = (
50    Configuration     => $jira->getConfiguration(),
51    CustomFields      => hash_of($jira->getCustomFields()),
52    FavouriteFilters  => hash_of($jira->getFavouriteFilters()),
53    IssueTypes 	      => hash_of($jira->getIssueTypes()),
54    Permissions       => hash_of($jira->getAllPermissions()),
55    Priorities 	      => hash_of($jira->getPriorities()),
56    Projects          => hash_of($jira->getProjectsNoSchemes(), 'key'),
57    Resolutions       => hash_of($jira->getResolutions()),
58    ServerInfo        => $jira->getServerInfo(),
59    Statuses          => hash_of($jira->getStatuses()),
60    SubTaskIssueTypes => hash_of($jira->getSubTaskIssueTypes()),
61);
62
63if ($Projects) {
64    warn "Grokking ", scalar(keys %{$JIRA{Projects}}), " projects:\n" if $Verbose;
65    foreach my $key (sort keys %{$JIRA{Projects}}) {
66	warn "Grokking project $key\n" if $Verbose;
67	my $project = $JIRA{Projects}{$key};
68	$project->{info} = {
69	    Components 	      => hash_of($jira->getComponents($key)),
70#	    IssueTypes 	      => hash_of(jira->getIssueTypesForProject($key)),
71#	    Avatars    	      => hash_of(jira->getProjectAvatars($key, 0)),
72#	    SecurityLevels    => hash_of(jira->getSecurityLevels($key)),
73#	    SubTaskIssueTypes => hash_of(jira->getSubTaskIssueTypesForProject($key)),
74	    Versions          => hash_of($jira->getVersions($key)),
75	};
76    }
77}
78
79$Data::Dumper::Indent = 1;
80$Data::Dumper::Sortkeys = 1;
81
82say Dumper(\%JIRA);