testrail-runs 3.8 KB

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