66
77use App \Api \Issue \IssueApi ;
88use App \Api \PullRequest \PullRequestApi ;
9+ use App \Api \Status \Status ;
10+ use App \Api \Status \StatusApi ;
911use App \Command \SuggestReviewerCommand ;
1012use App \Entity \Task ;
1113use App \Service \RepositoryProvider ;
14+ use App \Service \TaskScheduler ;
1215
1316/**
1417 * @author Tobias Nyholm <[email protected] > @@ -18,12 +21,16 @@ class SuggestReviewerHandler implements TaskHandlerInterface
1821 private $ issueApi ;
1922 private $ repositoryProvider ;
2023 private $ pullRequestApi ;
24+ private $ statusApi ;
25+ private $ scheduler ;
2126
22- public function __construct (PullRequestApi $ pullRequestApi , IssueApi $ issueApi , RepositoryProvider $ repositoryProvider )
27+ public function __construct (PullRequestApi $ pullRequestApi , IssueApi $ issueApi , RepositoryProvider $ repositoryProvider, StatusApi $ statusApi , TaskScheduler $ scheduler )
2328 {
2429 $ this ->issueApi = $ issueApi ;
2530 $ this ->repositoryProvider = $ repositoryProvider ;
2631 $ this ->pullRequestApi = $ pullRequestApi ;
32+ $ this ->statusApi = $ statusApi ;
33+ $ this ->scheduler = $ scheduler ;
2734 }
2835
2936 /**
@@ -32,8 +39,16 @@ public function __construct(PullRequestApi $pullRequestApi, IssueApi $issueApi,
3239 public function handle (Task $ task ): void
3340 {
3441 $ repository = $ this ->repositoryProvider ->getRepository ($ task ->getRepositoryFullName ());
35- if (!$ this ->issueApi ->hasActivity ($ repository , $ task ->getNumber ())) {
42+ if ($ this ->issueApi ->hasActivity ($ repository , $ task ->getNumber ())) {
43+ return ;
44+ }
45+
46+ $ status = $ this ->statusApi ->getIssueStatus ($ task ->getNumber (), $ repository );
47+ if (Status::NEEDS_REVIEW === $ status || null === $ status ) {
3648 $ this ->pullRequestApi ->findReviewer ($ repository , $ task ->getNumber (), SuggestReviewerCommand::TYPE_SUGGEST );
49+ } else {
50+ // Try again later
51+ $ this ->scheduler ->runLater ($ repository , $ task ->getNumber (), Task::ACTION_SUGGEST_REVIEWER , new \DateTimeImmutable ('+20hours ' ));
3752 }
3853 }
3954
0 commit comments