testrail-runs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env perl
  2. # ABSTRACT: List runs in a TestRail project matching the provided filters
  3. # PODNAME: testrail-runs
  4. =head1 SYNOPSIS
  5. testrail-runs [OPTIONS] | xargs prove -PTestrail=...
  6. =head1 DESCRIPTION
  7. testrail-tests - list runs in a TestRail project matching the provided filters.
  8. Groups by plan for runs which are children of a plan.
  9. =head1 PARAMETERS:
  10. =head2 MANDATORY PARAMETERS
  11. =over 4
  12. --apiurl : full URL to get to TestRail index document
  13. --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
  14. --user : Your TestRail User Name.
  15. -j --project : desired project name.
  16. =back
  17. All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
  18. =head2 OPTIONAL PARAMETERS
  19. =over 4
  20. -c --config : configuration name to filter runs. Can be passed multiple times.
  21. -s --status : only list runs with one or more tests having [status] in testrail. Can be passed multiple times.
  22. -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
  23. -l --lifo : LIFO sorting of results. Defaults to FIFO sort if not passed.
  24. -m --milesort : Sort by milestone due time. Defaults to sorting by run creation time if not passed.
  25. Be aware that when sorting by milestone, if a run has no milestone set, it is considered "earlier" than anything else by perl's comparison routines.
  26. Ergo if they are the lowest priority, you should consider running LIFO.
  27. =back
  28. =head1 CONFIGURATION FILE
  29. In your \$HOME, (or the current directory, if your system has no concept of a home directory) put a file called .testrailrc with key=value syntax separated by newlines.
  30. Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>.
  31. All options specified thereby are overridden by passing the command-line switches above.
  32. =head1 MISCELLANEOUS OPTIONS:
  33. =over 4
  34. --mock : don't do any real HTTP requests.
  35. --help : show this output
  36. =back
  37. =cut
  38. use strict;
  39. use warnings;
  40. use utf8;
  41. use TestRail::API;
  42. use TestRail::Utils;
  43. use TestRail::Utils::Find;
  44. use Getopt::Long;
  45. use File::HomeDir qw{my_home};
  46. my $opts ={};
  47. # Parse config file
  48. my $homedir = my_home() || '.';
  49. if (-e $homedir . '/.testrailrc') {
  50. $opts = TestRail::Utils::parseConfig($homedir);
  51. }
  52. GetOptions(
  53. 'apiurl=s' => \$opts->{'apiurl'},
  54. 'password=s' => \$opts->{'password'},
  55. 'user=s' => \$opts->{'user'},
  56. 'j|project=s' => \$opts->{'project'},
  57. 'c|config=s@' => \$opts->{'configs'},
  58. 's|status=s@' => \$opts->{'statuses'},
  59. 'mock' => \$opts->{'mock'},
  60. 'e|encoding=s' => \$opts->{'encoding'},
  61. 'l|lifo' => \$opts->{'lifo'},
  62. 'm|milesort' => \$opts->{'milesort'},
  63. 'h|help' => \$opts->{'help'}
  64. );
  65. if ($opts->{help}) { TestRail::Utils::help(); }
  66. TestRail::Utils::interrogateUser($opts,qw{apiurl user password project});
  67. if ($opts->{mock}) {
  68. use Test::LWP::UserAgent::TestRailMock;
  69. $opts->{browser} = $Test::LWP::UserAgent::TestRailMock::mockObject;
  70. $opts->{debug} = 1;
  71. }
  72. my $tr = TestRail::API->new($opts->{apiurl},$opts->{user},$opts->{password},$opts->{'encoding'},$opts->{'debug'});
  73. $tr->{'browser'} = $opts->{'browser'} if $opts->{'browser'};
  74. $tr->{'debug'} = 0;
  75. my $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  76. @$runs = map {$_->{name}} @$runs;
  77. print join("\n",@$runs)."\n" if scalar(@$runs);
  78. exit 0;
  79. __END__
  80. L<TestRail::API>
  81. L<File::HomeDir> for the finding of .testrailrc
  82. =head1 SPECIAL THANKS
  83. Thanks to cPanel Inc, for graciously funding the creation of this distribution.