testrail-bulk-mark-results 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/env perl
  2. # ABSTRACT: Bulk mark entire runs/plans (or groups of tests therein) as the provided status.
  3. # PODNAME: testrail-bulk-mark-results
  4. =head1 USAGE
  5. testrail-bulk-mark-results [OPTIONS] status [reason]
  6. =head1 DESCRIPTION
  7. Sometimes it is useful to mark entire runs of tests when, for example, a prerequisite test in a sequence invalidates all further tests.
  8. For example, if a binary produced for test fails to run at all, more detailed testing will be impossible;
  9. it would save time to just mark everything as blocked.
  10. =head1 PARAMETERS:
  11. =head2 MANDATORY PARAMETERS
  12. =over 4
  13. --apiurl : full URL to get to TestRail index document
  14. --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
  15. --user : Your TestRail User Name.
  16. -j --project : desired project name.
  17. -r --run : desired run name.
  18. =back
  19. All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
  20. =head2 SEMI-OPTIONAL PARAMETERS
  21. =over 4
  22. -p --plan : desired plan name. Required if the run passed is a child of a plan.
  23. -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
  24. =back
  25. =head2 OPTIONAL PARAMETERS
  26. =over 4
  27. -c --config : configuration name to filter plans in run. Can be passed multiple times.
  28. -s --status : only mark tests already marked as [status] in testrail. Can be passed multiple times.
  29. -a --assignedto : only mark tests assigned to user. Can be passed multiple times.
  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. use strict;
  41. use warnings;
  42. use utf8;
  43. use TestRail::API;
  44. use TestRail::Utils;
  45. use TestRail::Utils::Results;
  46. use Getopt::Long;
  47. Getopt::Long::Configure('pass_through');
  48. use File::HomeDir qw{my_home};
  49. my $opts = {};
  50. # Parse config file
  51. my $homedir = my_home() || '.';
  52. if (-e $homedir . '/.testrailrc') {
  53. $opts = TestRail::Utils::parseConfig($homedir);
  54. }
  55. # Override configuration with switches
  56. GetOptions(
  57. 'apiurl=s' => \$opts->{'apiurl'},
  58. 'password=s' => \$opts->{'password'},
  59. 'user=s' => \$opts->{'user'},
  60. 'assignedto=s@' => \$opts->{'users'},
  61. 'status=s@' => \$opts->{'statuses'},
  62. 'j|project=s' => \$opts->{'project'},
  63. 'p|plan=s' => \$opts->{'plan'},
  64. 'r|run=s' => \$opts->{'run'},
  65. 'c|config=s@' => \$opts->{'configs'},
  66. 'a|assignedto=s@' => \$opts->{'users'},
  67. 'e|encoding=s' => \$opts->{'encoding'},
  68. 'h|help' => \$opts->{'help'},
  69. 'mock' => \$opts->{'mock'}
  70. );
  71. if ($opts->{help}) { TestRail::Utils::help(); }
  72. my $status = $ARGV[0];
  73. my $reason = $ARGV[1];
  74. die("No status to set provided.") unless $status;
  75. TestRail::Utils::interrogateUser($opts,qw{apiurl user password project run});
  76. my $tr = TestRail::Utils::getHandle($opts);
  77. $opts->{'set_status_to'} = $status;
  78. $opts->{'reason'} = $reason;
  79. my $results = TestRail::Utils::Results::bulkMarkResults($opts,$tr);
  80. print "Successfully set the status of ".scalar(@$results)." cases to $status.\n" if $results;
  81. exit 0;
  82. __END__
  83. L<TestRail::API>
  84. L<File::HomeDir> for the finding of .testrailrc
  85. =head1 SPECIAL THANKS
  86. Thanks to cPanel Inc, for graciously funding the creation of this distribution.