]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
no bug - allow changing the doctype
authorDylan William Hardison <dylan@hardison.net>
Wed, 10 Apr 2019 15:48:37 +0000 (11:48 -0400)
committerGitHub <noreply@github.com>
Wed, 10 Apr 2019 15:48:37 +0000 (11:48 -0400)
Bugzilla/App/Command/report_ping.pm
Bugzilla/Report/Ping.pm
Bugzilla/Report/Ping/Simple.pm

index ca327795506372ce2c63a5d5fac2cd22bccc0aa5..c423bf384859ca98c5022800e1a1cd71644affbc 100644 (file)
@@ -9,12 +9,13 @@ package Bugzilla::App::Command::report_ping;   ## no critic (Capitalization)
 use Mojo::Base 'Mojolicious::Command';
 
 use Bugzilla::Constants;
-use JSON::MaybeXS;
 use Cwd qw(cwd);
+use JSON::MaybeXS;
+use Module::Runtime 'require_module';
 use Mojo::File 'path';
 use Mojo::Util 'getopt';
 use PerlX::Maybe 'maybe';
-use Module::Runtime 'require_module';
+use Try::Tiny;
 
 has description => 'send a report ping to a url';
 has usage       => sub { shift->extract_usage };
@@ -23,9 +24,9 @@ sub run {
   my ($self, @args) = @_;
   my $json
     = JSON::MaybeXS->new(convert_blessed => 1, canonical => 1, pretty => 1);
-  my $report_type = 'Simple';
+  my $class       = 'Simple';
   my $working_dir = cwd();
-  my ($namespace, $page, $rows, $base_url, $test, $dump_schema, $dump_documents);
+  my ($namespace, $doctype, $page, $rows, $base_url, $test, $dump_schema, $dump_documents);
 
   Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
   getopt \@args,
@@ -34,22 +35,35 @@ sub run {
     'rows|r=i'       => \$rows,
     'dump-schema'    => \$dump_schema,
     'dump-documents' => \$dump_documents,
-    'report-type=s'  => \$report_type,
-    'namespace|ns=s' => \$namespace,
+    'class|c=s'      => \$class,
+    'namespace|n=s'  => \$namespace,
+    'doctype|d=s'    => \$doctype,
     'workdir|C=s'    => \$working_dir,
     'test'           => \$test;
 
   $base_url = 'http://localhost' if $dump_schema || $dump_documents || $test;
   die $self->usage unless $base_url;
 
-  my $report_class = "Bugzilla::Report::Ping::$report_type";
-  require_module($report_class);
-  my $report = $report_class->new(
+  unless ($class =~ /::/) {
+    $class = "Bugzilla::Report::Ping::$class";
+  }
+  try {
+    require_module($class);
+  }
+  catch {
+    say "Failed to load $class.";
+    unless ($_ =~ /^Can't locate \S+ in \@INC/) {
+      say "Error: $_";
+    }
+    exit 1;
+  };
+  my $report = $class->new(
     model           => Bugzilla->dbh->model,
     base_url        => $base_url,
     maybe rows      => $rows,
     maybe page      => $page,
     maybe namespace => $namespace,
+    maybe doctype   => $doctype,
   );
 
   if ($dump_schema) {
@@ -126,7 +140,7 @@ Bugzilla::App::Command::report_ping - descriptionsend a report ping to a url';
     -u, --base-url           URL to send the json documents to.
     -r, --rows num           (Optional) Number of requests to send at once. Default: 10.
     -p, --page num           (Optional) Page to start on. Default: 1
-    --report-type word       (Optional) Report class to use. Default: Simple
+    --class word             (Optional) Report class to use. Default: Simple
     --test                   Validate the json documents against the json schema.
     --dump-schema            Print the json schema.
 
index 7cecb961d7c075779d50bc924250439bff63a9e5..8ea553e083f404c91ecef084c6c85fd86de4b0a7 100644 (file)
@@ -74,7 +74,7 @@ sub _build_namespace {
   return 'bugzilla';
 }
 
-has 'doctype' => (is => 'lazy', init_arg => undef, isa => Str);
+has 'doctype' => (is => 'lazy', isa => Str);
 
 sub _build_doctype {
   my ($self) = @_;
index eac6ba009e2d95089face2219d89d12594e34cf5..d63553c7cdcc5371902dd9fea0bc8104a8935d94 100644 (file)
@@ -53,7 +53,6 @@ sub _build_validator {
     schema => Mojo::JSON::Pointer->new($schema->compile));
 }
 
-
 sub _build_resultset {
   my ($self)  = @_;
   my $bugs    = $self->model->resultset('Bug');