testrail-runs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env perl
  2. # ABSTRACT: List runs in a TestRail project matching the provided filters
  3. # PODNAME: TestRail::Bin::Runs
  4. =head1 SYNOPSIS
  5. testrail-runs [OPTIONS] | xargs prove -PTestrail=...
  6. require `which testrail-runs`;
  7. TestRail::Bin::Run::run(@args);
  8. =head1 DESCRIPTION
  9. testrail-runs - list runs in a TestRail project matching the provided filters.
  10. Groups by plan for runs which are children of a plan.
  11. Can be used as the modulino TestRail::Bin::Runs.
  12. =head1 PARAMETERS:
  13. =head2 MANDATORY PARAMETERS
  14. =over 4
  15. --apiurl : full URL to get to TestRail index document
  16. --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
  17. --user : Your TestRail User Name.
  18. -j --project : desired project name.
  19. =back
  20. All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
  21. =head2 OPTIONAL PARAMETERS
  22. =over 4
  23. -c --config : configuration name to filter runs. Can be passed multiple times.
  24. -s --status : only list runs with one or more tests having [status] in testrail. Can be passed multiple times.
  25. -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
  26. -l --lifo : LIFO sorting of results. Defaults to FIFO sort if not passed.
  27. -m --milesort : Sort by milestone due time. Defaults to sorting by run creation time if not passed.
  28. 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.
  29. Ergo if they are the lowest priority, you should consider running LIFO.
  30. =back
  31. =head1 CONFIGURATION FILE
  32. 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.
  33. Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>.
  34. All options specified thereby are overridden by passing the command-line switches above.
  35. =head1 MISCELLANEOUS OPTIONS:
  36. =over 4
  37. --help : show this output
  38. =back
  39. =cut
  40. package TestRail::Bin::Runs;
  41. use strict;
  42. use warnings;
  43. use utf8;
  44. use TestRail::API;
  45. use TestRail::Utils;
  46. use TestRail::Utils::Find;
  47. use Getopt::Long qw{GetOptionsFromArray};
  48. use File::HomeDir qw{my_home};
  49. if (!caller()) {
  50. my ($out,$code) = run(@ARGV);
  51. print $out;
  52. exit $code;
  53. }
  54. sub run {
  55. my $args = \@_;
  56. my $opts = {};
  57. # Parse config file
  58. my $homedir = my_home() || '.';
  59. if (-e $homedir . '/.testrailrc') {
  60. $opts = TestRail::Utils::parseConfig($homedir);
  61. }
  62. GetOptionsFromArray($args,
  63. 'apiurl=s' => \$opts->{'apiurl'},
  64. 'password=s' => \$opts->{'password'},
  65. 'user=s' => \$opts->{'user'},
  66. 'j|project=s' => \$opts->{'project'},
  67. 'c|config=s@' => \$opts->{'configs'},
  68. 's|status=s@' => \$opts->{'statuses'},
  69. 'e|encoding=s' => \$opts->{'encoding'},
  70. 'l|lifo' => \$opts->{'lifo'},
  71. 'm|milesort' => \$opts->{'milesort'},
  72. 'h|help' => \$opts->{'help'},
  73. 'mock' => \$opts->{'mock'}
  74. );
  75. if ($opts->{help}) { return ('',TestRail::Utils::help()); }
  76. TestRail::Utils::interrogateUser($opts,qw{apiurl user password project});
  77. my $tr = TestRail::Utils::getHandle($opts);
  78. my $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  79. @$runs = map {$_->{name}} @$runs;
  80. return (join("\n",@$runs)."\n", 0) if scalar(@$runs);
  81. return ("No runs found matching your criterion.\n",255);
  82. }
  83. 1;
  84. __END__
  85. L<TestRail::API>
  86. L<File::HomeDir> for the finding of .testrailrc
  87. =head1 SPECIAL THANKS
  88. Thanks to cPanel Inc, for graciously funding the creation of this distribution.