44
55namespace App \Command ;
66
7+ use App \Api \Issue \IssueApi ;
8+ use App \Service \RepositoryProvider ;
79use Symfony \Component \Console \Command \Command ;
810use Symfony \Component \Console \Input \InputArgument ;
911use Symfony \Component \Console \Input \InputInterface ;
1719class OpenIssueCommand extends Command
1820{
1921 protected static $ defaultName = 'app:issue:open ' ;
22+ private $ issueApi ;
23+ private $ repositoryProvider ;
2024
21- public function __construct ()
25+ public function __construct (RepositoryProvider $ repositoryProvider , IssueApi $ issueApi )
2226 {
2327 parent ::__construct ();
28+ $ this ->issueApi = $ issueApi ;
29+ $ this ->repositoryProvider = $ repositoryProvider ;
2430 }
2531
2632 protected function configure ()
@@ -34,23 +40,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
3440 {
3541 /** @var string $repositoryName */
3642 $ repositoryName = $ input ->getArgument ('repository ' );
43+ $ repository = $ this ->repositoryProvider ->getRepository ($ repositoryName );
44+ if (null === $ repository ) {
45+ $ output ->writeln ('Repository not configured ' );
46+ return 1 ;
47+ }
48+
3749 /** @var string $title */
3850 $ title = $ input ->getArgument ('title ' );
3951 /** @var string $filePath */
4052 $ filePath = $ input ->getArgument ('file ' );
53+
4154 $ body = file_get_contents ($ filePath );
4255 if (false === $ body ) {
4356 return 1 ;
4457 }
4558
46- // These outputs are just debug code
47- $ output ->writeln ('Will create an issue on ' .$ repositoryName .' with the following: ' );
48- $ output ->writeln ('------ ' );
49- $ output ->writeln ($ title );
50- $ output ->writeln ($ body );
51- $ output ->writeln ('------ ' );
52-
53- // TODO actually open or update an issue
59+ $ this ->issueApi ->open ($ repository , $ title , $ body , ['help wanted ' ]);
5460
5561 return 0 ;
5662 }
0 commit comments