Skip to content

Commit 16940a9

Browse files
committed
Create "release" command
1 parent 7d6cdd3 commit 16940a9

File tree

4 files changed

+247
-3
lines changed

4 files changed

+247
-3
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"symfony/dom-crawler": "^4.1",
2020
"symfony/css-selector": "^4.1",
2121
"symfony/console": "^4.1",
22-
"twig/twig": "^2.7.3"
22+
"twig/twig": "^2.7.3",
23+
"symfony/http-client": "^4.3"
2324
},
2425
"require-dev": {
2526
"gajus/dindent": "^2.0",

composer.lock

Lines changed: 168 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Input\InputOption;
88
use SymfonyDocsBuilder\Command\BuildDocsCommand;
99
use SymfonyDocsBuilder\Command\CheckUrlsCommand;
10+
use SymfonyDocsBuilder\Command\GithubReleaseCommand;
1011

1112
class Application
1213
{
@@ -41,6 +42,7 @@ public function run(InputInterface $input): int
4142
);
4243
$this->application->getDefinition()->addOption($inputOption);
4344
$this->application->add(new BuildDocsCommand($this->buildContext));
45+
$this->application->add(new GithubReleaseCommand());
4446

4547
return $this->application->run($input);
4648
}

src/Command/GithubReleaseCommand.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace SymfonyDocsBuilder\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputArgument;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Style\SymfonyStyle;
10+
use Symfony\Component\HttpClient\Exception\ClientException;
11+
use Symfony\Component\HttpClient\HttpClient;
12+
use Symfony\Component\Process\Process;
13+
14+
class GithubReleaseCommand extends Command
15+
{
16+
protected static $defaultName = 'github:release';
17+
18+
/** @var SymfonyStyle */
19+
private $io;
20+
21+
public function __construct()
22+
{
23+
parent::__construct(self::$defaultName);
24+
}
25+
26+
protected function configure()
27+
{
28+
$this->setDescription('Create a release on github with a .phar as attachment.');
29+
// todo valid with regex
30+
$this->addArgument('tag', InputArgument::REQUIRED, 'Release\'s tag.');
31+
$this->addArgument('name', InputArgument::REQUIRED, 'Release name');
32+
$this->addArgument('description', InputArgument::REQUIRED, 'Release description');
33+
}
34+
35+
protected function initialize(InputInterface $input, OutputInterface $output)
36+
{
37+
$this->io = new SymfonyStyle($input, $output);
38+
}
39+
40+
protected function execute(InputInterface $input, OutputInterface $output)
41+
{
42+
$process = Process::fromShellCommandline('./bin/compile', __DIR__.'/../..');
43+
$process->mustRun();
44+
45+
// TODO token form .env
46+
$client = HttpClient::create(
47+
[
48+
'headers' => [
49+
'Authorization' => 'token 52a83ae437c06017d72fc9461392f02b39dc8c0f',
50+
],
51+
]
52+
);
53+
54+
try {
55+
$client->request(
56+
'POST',
57+
'https://api.github.com/repos/nikophil/test/releases',
58+
[
59+
'json' => [
60+
'tag_name' => $input->getArgument('tag'),
61+
'target_commitish' => 'master',
62+
'name' => $input->getArgument('name'),
63+
'body' => $input->getArgument('description'),
64+
'draft' => false,
65+
'prerelease' => false
66+
]
67+
]
68+
);
69+
} catch (ClientException $exception) {
70+
$this->io->error('Error while trying to create release. Maybe the tag name already exists?');
71+
72+
return;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)