testrail-bulk-mark-results 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 Getopt::Long;
  46. Getopt::Long::Configure('pass_through');
  47. use File::HomeDir qw{my_home};
  48. my $opts = {};
  49. # Parse config file
  50. my $homedir = my_home() || '.';
  51. if (-e $homedir . '/.testrailrc') {
  52. $opts = TestRail::Utils::parseConfig($homedir);
  53. }
  54. # Override configuration with switches
  55. GetOptions(
  56. 'apiurl=s' => \$opts->{'apiurl'},
  57. 'password=s' => \$opts->{'password'},
  58. 'user=s' => \$opts->{'user'},
  59. 'assignedto=s@' => \$opts->{'users'},
  60. 'status=s@' => \$opts->{'statuses'},
  61. 'j|project=s' => \$opts->{'project'},
  62. 'p|plan=s' => \$opts->{'plan'},
  63. 'r|run=s' => \$opts->{'run'},
  64. 'c|config=s@' => \$opts->{'configs'},
  65. 'a|assignedto=s@' => \$opts->{'users'},
  66. 'e|encoding=s' => \$opts->{'encoding'},
  67. 'h|help' => \$opts->{'help'}
  68. );
  69. if ($opts->{help}) { TestRail::Utils::help(); }
  70. my $status = $ARGV[0];
  71. my $reason = $ARGV[1];
  72. die("No status to set provided.") unless $status;
  73. TestRail::Utils::interrogateUser($opts,qw{apiurl user password project run});
  74. my $tr = TestRail::API->new($opts->{apiurl},$opts->{user},$opts->{password},$opts->{'encoding'},$opts->{'debug'});
  75. $opts->{'set_status_to'} = $status;
  76. $opts->{'reason'} = $reason;
  77. my $results = TestRail::Utils::Results::bulkMarkResults($opts,$tr);
  78. print "Successfully set the status of ".scalar(@$results)." cases to $status.\n" if $results;
  79. exit 0;
  80. __END__
  81. L<TestRail::API>
  82. L<File::HomeDir> for the finding of .testrailrc
  83. =head1 SPECIAL THANKS
  84. Thanks to cPanel Inc, for graciously funding the creation of this distribution.