-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathOpenIssueCommand.php
62 lines (51 loc) · 1.87 KB
/
OpenIssueCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace App\Command;
use App\Api\Issue\IssueApi;
use App\Service\RepositoryProvider;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Open or update issues.
*
* @author Tobias Nyholm <[email protected]>
*/
class OpenIssueCommand extends Command
{
protected static $defaultName = 'app:issue:open';
private $issueApi;
private $repositoryProvider;
public function __construct(RepositoryProvider $repositoryProvider, IssueApi $issueApi)
{
parent::__construct();
$this->issueApi = $issueApi;
$this->repositoryProvider = $repositoryProvider;
}
protected function configure()
{
$this->addArgument('repository', InputArgument::REQUIRED, 'The full name to the repository, eg symfony/symfony-docs');
$this->addArgument('title', InputArgument::REQUIRED, 'The title of the issue');
$this->addArgument('file', InputArgument::REQUIRED, 'The path to the issue body text file');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var string $repositoryName */
$repositoryName = $input->getArgument('repository');
$repository = $this->repositoryProvider->getRepository($repositoryName);
if (null === $repository) {
$output->writeln('Repository not configured');
return 1;
}
/** @var string $title */
$title = $input->getArgument('title');
/** @var string $filePath */
$filePath = $input->getArgument('file');
$body = file_get_contents($filePath);
if (false === $body) {
return 1;
}
$this->issueApi->open($repository, $title, $body, ['help wanted']);
return 0;
}
}