33namespace App \Command ;
44
55use App \Api \Issue \IssueApi ;
6+ use App \Api \Issue \IssueType ;
67use App \Entity \Task ;
78use App \Service \RepositoryProvider ;
9+ use App \Service \StaleIssueCommentGenerator ;
810use App \Service \TaskScheduler ;
911use Symfony \Component \Console \Command \Command ;
1012use Symfony \Component \Console \Input \InputArgument ;
@@ -22,13 +24,15 @@ class CloseStaleIssuesCommand extends Command
2224 private $ repositoryProvider ;
2325 private $ issueApi ;
2426 private $ scheduler ;
27+ private $ commentGenerator ;
2528
26- public function __construct (RepositoryProvider $ repositoryProvider , IssueApi $ issueApi , TaskScheduler $ scheduler )
29+ public function __construct (RepositoryProvider $ repositoryProvider , IssueApi $ issueApi , TaskScheduler $ scheduler, StaleIssueCommentGenerator $ commentGenerator )
2730 {
2831 parent ::__construct ();
2932 $ this ->repositoryProvider = $ repositoryProvider ;
3033 $ this ->issueApi = $ issueApi ;
3134 $ this ->scheduler = $ scheduler ;
35+ $ this ->commentGenerator = $ commentGenerator ;
3236 }
3337
3438 protected function configure ()
@@ -51,21 +55,40 @@ protected function execute(InputInterface $input, OutputInterface $output)
5155 $ issues = $ this ->issueApi ->findStaleIssues ($ repository , $ notUpdatedAfter );
5256
5357 foreach ($ issues as $ issue ) {
54- $ this ->issueApi -> commentOnIssue ( $ repository , $ issue[ ' number ' ], <<<TXT
55- Hey,
58+ $ comment = $ this ->commentGenerator -> getComment ( $ this -> extractType ( $ issue));
59+ //$this->issueApi->commentOnIssue($repository, $issue['number'], $comment);
5660
57- Is this issue still relevant? It has not been any activity in a while. I will close this if nobody makes a comment soon.
61+ // add a scheduled task to process this issue again after 2 weeks
62+ //$this->scheduler->runLater($repository, $issue['number'], Task::ACTION_CLOSE_STALE, new \DateTimeImmutable('+2weeks'));
63+ }
5864
59- Cheers!
65+ return 0 ;
66+ }
6067
61- Carsonbot
62- TXT
63- );
68+ /**
69+ * Extract type form issue array. Make sure we priorities labels if there are
70+ * more than one type defined.
71+ */
72+ private function extractType (array $ issue )
73+ {
74+ $ types = [
75+ IssueType::FEATURE => false ,
76+ IssueType::BUG => false ,
77+ IssueType::RFC => false ,
78+ ];
6479
65- // add a scheduled task to process this issue again after 2 weeks
66- $ this ->scheduler ->runLater ($ repository , $ issue ['number ' ], Task::ACTION_CLOSE_STALE , new \DateTimeImmutable ('+2weeks ' ));
80+ foreach ($ issue ['labels ' ] as $ label ) {
81+ if (isset ($ types [$ label ['name ' ]])) {
82+ $ types [$ label ['name ' ]] = true ;
83+ }
6784 }
6885
69- return 0 ;
86+ foreach ($ types as $ type => $ exists ) {
87+ if ($ exists ) {
88+ return $ type ;
89+ }
90+ }
91+
92+ return IssueType::UNKNOWN ;
7093 }
7194}
0 commit comments