Find.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # PODNAME: TestRail::Utils::Find
  2. # ABSTRACT: Find runs and tests according to user specifications.
  3. package TestRail::Utils::Find;
  4. use strict;
  5. use warnings;
  6. =head1 DESCRIPTION
  7. =head1 FUNCTIONS
  8. =head2 findRuns
  9. Find runs based on the options HASHREF provided.
  10. See the documentation for L<testrail-runs>, as the long argument names there correspond to hash keys.
  11. The primary routine of testrail-runs.
  12. =over 4
  13. =item HASHREF C<OPTIONS> - flags acceptable by testrail-tests
  14. =item TestRail::API C<HANDLE> - TestRail::API object
  15. =back
  16. Returns ARRAYREF of run definition HASHREFs.
  17. =cut
  18. sub findRuns {
  19. my ($opts,$tr) = @_;
  20. my ($status_ids,$user_ids);
  21. #Process statuses
  22. if ($opts->{'statuses'}) {
  23. @$status_ids = $tr->statusNamesToIds(@{$opts->{'statuses'}});
  24. }
  25. my $project = $tr->getProjectByName($opts->{'project'});
  26. confess("No such project '$opts->{project}'.\n") if !$project;
  27. my @pconfigs = ();
  28. @pconfigs = $tr->translateConfigNamesToIds($project->{'id'},$opts->{configs}) if $opts->{'configs'};
  29. my ($runs,$plans,$planRuns,$cruns,$found) = ([],[],[],[],0);
  30. $runs = $tr->getRuns($project->{'id'}) if (!$opts->{'configs'}); # If configs are passed, global runs are not in consideration.
  31. $plans = $tr->getPlans($project->{'id'});
  32. foreach my $plan (@$plans) {
  33. $cruns = $tr->getChildRuns($plan);
  34. next if !$cruns;
  35. foreach my $run (@$cruns) {
  36. next if scalar(@pconfigs) != scalar(@{$run->{'config_ids'}});
  37. #Compare run config IDs against desired, invalidate run if all conditions not satisfied
  38. $found = 0;
  39. foreach my $cid (@{$run->{'config_ids'}}) {
  40. $found++ if grep {$_ == $cid} @pconfigs;
  41. }
  42. push(@$planRuns, $run) if $found == scalar(@{$run->{'config_ids'}});
  43. }
  44. }
  45. push(@$runs,@$planRuns);
  46. if ($opts->{'statuses'}) {
  47. @$runs = $tr->getRunSummary(@$runs);
  48. @$runs = grep { defined($_->{'run_status'}) } @$runs; #Filter stuff with no results
  49. foreach my $status (@{$opts->{'statuses'}}) {
  50. @$runs = grep { $_->{'run_status'}->{$status} } @$runs; #If it's positive, keep it. Otherwise forget it.
  51. }
  52. }
  53. #Sort FIFO/LIFO by milestone or creation date of run
  54. my $sortkey = 'created_on';
  55. if ($opts->{'milesort'}) {
  56. @$runs = map {
  57. my $run = $_;
  58. $run->{'milestone'} = $tr->getMilestoneByID($run->{'milestone_id'}) if $run->{'milestone_id'};
  59. my $milestone = $run->{'milestone'} ? $run->{'milestone'}->{'due_on'} : 0;
  60. $run->{'due_on'} = $milestone;
  61. $run
  62. } @$runs;
  63. $sortkey = 'due_on';
  64. }
  65. if ($opts->{'lifo'}) {
  66. @$runs = sort { $b->{$sortkey} <=> $a->{$sortkey} } @$runs;
  67. } else {
  68. @$runs = sort { $a->{$sortkey} <=> $b->{$sortkey} } @$runs;
  69. }
  70. return $runs;
  71. }
  72. =head2 findTests
  73. Find tests based on the options HASHREF provided.
  74. See the documentation for L<testrail-tests>, as the long argument names there correspond to hash keys.
  75. The primary routine of testrail-tests.
  76. =over 4
  77. =item HASHREF C<OPTIONS> - flags acceptable by testrail-tests
  78. =item TestRail::API C<HANDLE> - TestRail::API object
  79. =back
  80. =cut
  81. sub findTests {
  82. my ($opts,$tr) = @_;
  83. }
  84. 1;
  85. __END__
  86. =head1 SPECIAL THANKS
  87. Thanks to cPanel Inc, for graciously funding the creation of this module.