Skip to content

Commit ce41040

Browse files
committed
Clean up and upgrade to PHP 8
1 parent b8f5b6f commit ce41040

17 files changed

+179
-319
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @sidler @marcreichel

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Mantis 2 Github Connector
1+
# Mantis 2 GitHub Connector
22

33
[![Packagist Version](https://img.shields.io/packagist/v/artemeon/mantis2github)](https://packagist.org/packages/artemeon/mantis2github)
44
[![Packagist Downloads](https://img.shields.io/packagist/dt/artemeon/mantis2github)](https://packagist.org/packages/artemeon/mantis2github)
@@ -78,25 +78,25 @@ mantis2github sync 123 456 789
7878
Read details of a GitHub issue.
7979

8080
```shell
81-
mantis2github read:github [id]
81+
mantis2github read:github <id>
8282
```
8383

8484
##### Arguments
8585

8686
| Argument | required | Description |
8787
|----------|----------|-----------------|
88-
| `id` | `false` | GitHub issue id |
88+
| `id` | `true` | GitHub issue id |
8989

9090
#### `read:mantis`
9191

9292
Read details of a Mantis issue.
9393

9494
```shell
95-
mantis2github read:mantis [id]
95+
mantis2github read:mantis <id>
9696
```
9797

9898
##### Arguments
9999

100100
| Argument | required | Description |
101101
|----------|----------|-----------------|
102-
| `id` | `false` | Mantis issue id |
102+
| `id` | `true` | Mantis issue id |

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
},
2020
"require": {
21-
"php": ">=7.4",
21+
"php": ">=8.0",
2222
"ext-json": "*",
2323
"guzzlehttp/guzzle": "^7.3.0",
2424
"symfony/console": "^5.0",

composer.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mantis2github

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env php
22
<?php
3-
/*
4-
* This file is part of the Artemeon Core - Web Application Framework.
5-
*
6-
* (c) Artemeon <www.artemeon.de>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
3+
4+
use Artemeon\M2G\Command\ConfigurationCommand;
5+
use Artemeon\M2G\Command\CreateGithubIssueFromMantisIssue;
6+
use Artemeon\M2G\Command\ReadGithubIssueCommand;
7+
use Artemeon\M2G\Command\ReadMantisIssueCommand;
8+
use Artemeon\M2G\Config\ConfigReader;
9+
use Artemeon\M2G\Service\GithubConnector;
10+
use Artemeon\M2G\Service\MantisConnector;
11+
use Symfony\Component\Console\Application;
1112

1213
(new class() {
1314
protected string $name;
@@ -18,15 +19,15 @@
1819
$this->autoload();
1920
$this->fetchVersion();
2021

21-
$configValues = (new \Artemeon\M2G\Config\ConfigReader())->read();
22-
$githubConnector = new \Artemeon\M2G\Service\GithubConnector($configValues);
23-
$mantisConnector = new \Artemeon\M2G\Service\MantisConnector($configValues);
22+
$configValues = (new ConfigReader())->read();
23+
$githubConnector = new GithubConnector($configValues);
24+
$mantisConnector = new MantisConnector($configValues);
2425

25-
$app = new \Symfony\Component\Console\Application($this->name, $this->version);
26-
$app->add(new \Artemeon\M2G\Command\ConfigurationCommand($githubConnector));
27-
$app->add(new \Artemeon\M2G\Command\ReadMantisIssueCommand($mantisConnector));
28-
$app->add(new \Artemeon\M2G\Command\ReadGithubIssueCommand($githubConnector));
29-
$app->add(new \Artemeon\M2G\Command\CreateGithubIssueFromMantisIssue($mantisConnector, $githubConnector));
26+
$app = new Application($this->name, $this->version);
27+
$app->add(new ConfigurationCommand());
28+
$app->add(new ReadMantisIssueCommand($mantisConnector));
29+
$app->add(new ReadGithubIssueCommand($githubConnector));
30+
$app->add(new CreateGithubIssueFromMantisIssue($mantisConnector, $githubConnector));
3031
$app->run();
3132
}
3233

src/Command/ConfigurationCommand.php

-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Artemeon\M2G\Command;
44

55
use Artemeon\M2G\Config\ConfigReader;
6-
use Artemeon\M2G\Service\GithubConnector;
76
use Symfony\Component\Console\Input\InputArgument;
87
use Symfony\Component\Yaml\Yaml;
98

@@ -14,17 +13,6 @@ class ConfigurationCommand extends Command
1413
protected string $configPath = __DIR__ . '/../../../config.yaml';
1514
protected array $config = [];
1615

17-
private GithubConnector $githubConnector;
18-
19-
/**
20-
* @param GithubConnector $mantisConnector
21-
*/
22-
public function __construct(GithubConnector $mantisConnector)
23-
{
24-
parent::__construct();
25-
$this->githubConnector = $mantisConnector;
26-
}
27-
2816
protected function configure()
2917
{
3018
$this->setName('configure')

src/Command/CreateGithubIssueFromMantisIssue.php

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
<?php
2-
/*
3-
* This file is part of the Artemeon Core - Web Application Framework.
4-
*
5-
* (c) Artemeon <www.artemeon.de>
6-
*
7-
* For the full copyright and license information, please view the LICENSE
8-
* file that was distributed with this source code.
9-
*/
102

113
namespace Artemeon\M2G\Command;
124

135
use Artemeon\M2G\Dto\GithubIssue;
14-
use Artemeon\M2G\Dto\MantisIssue;
156
use Artemeon\M2G\Service\GithubConnector;
167
use Artemeon\M2G\Service\MantisConnector;
17-
use GuzzleHttp\Exception\GuzzleException;
188
use Symfony\Component\Console\Helper\ProgressBar;
199
use Symfony\Component\Console\Helper\Table;
2010
use Symfony\Component\Console\Input\InputArgument;
21-
use Symfony\Component\Console\Input\InputOption;
2211

2312
use function Termwind\render;
2413

@@ -34,7 +23,6 @@ public function __construct(MantisConnector $mantisConnector, GithubConnector $g
3423
$this->githubConnector = $githubConnector;
3524
}
3625

37-
3826
protected function configure()
3927
{
4028
$this->setName('sync')
@@ -99,15 +87,14 @@ protected function handle(): int
9987

10088
$newGithubIssue = GithubIssue::fromMantisIssue($mantisIssue);
10189

102-
$filteredLabels = array_filter($labels, function ($label) use ($mantisIssue) {
90+
$filteredLabels = array_values(array_filter($labels, function ($label) use ($mantisIssue) {
10391
return strtolower($label) === strtolower($mantisIssue->getProject());
104-
});
92+
}));
10593

10694
$newGithubIssue->setLabels($filteredLabels);
95+
$newGithubIssue = $this->githubConnector->createIssue($newGithubIssue);
10796

108-
try {
109-
$newGithubIssue = $this->githubConnector->createIssue($newGithubIssue);
110-
} catch (GuzzleException | \Exception $e) {
97+
if ($newGithubIssue === null) {
11198
$issues[] = [
11299
'id' => $id,
113100
'icon' => '<error>✕</error>',
@@ -118,7 +105,17 @@ protected function handle(): int
118105
}
119106

120107
$mantisIssue->setUpstreamTicket($newGithubIssue->getIssueUrl());
121-
$this->mantisConnector->patchUpstreamField($mantisIssue);
108+
$patched = $this->mantisConnector->patchUpstreamField($mantisIssue);
109+
110+
if ($patched === false) {
111+
$issues[] = [
112+
'id' => $id,
113+
'icon' => '<error>✕</error>',
114+
'message' => '<error>Upstream ticket URL could not be updated.</error>',
115+
'issue' => '',
116+
];
117+
continue;
118+
}
122119

123120
$issues[] = [
124121
'id' => $id,

src/Command/ReadGithubIssueCommand.php

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
<?php
2-
/*
3-
* This file is part of the Artemeon Core - Web Application Framework.
4-
*
5-
* (c) Artemeon <www.artemeon.de>
6-
*
7-
* For the full copyright and license information, please view the LICENSE
8-
* file that was distributed with this source code.
9-
*/
102

113
namespace Artemeon\M2G\Command;
124

@@ -32,7 +24,7 @@ public function __construct(GithubConnector $mantisConnector)
3224
protected function configure()
3325
{
3426
$this->setName('read:github')
35-
->addArgument('id', InputArgument::OPTIONAL, 'GitHub issue id')
27+
->addArgument('id', InputArgument::REQUIRED, 'GitHub issue id')
3628
->setDescription('Read details of a GitHub issue');
3729
}
3830

@@ -49,7 +41,7 @@ protected function handle(): int
4941
{
5042
$this->header();
5143

52-
$issue = $this->askForIssue();
44+
$issue = $this->fetchIssueDetails();
5345

5446
terminal()->clear();
5547

@@ -112,17 +104,13 @@ protected function handle(): int
112104
return 0;
113105
}
114106

115-
protected function askForIssue(): GithubIssue
107+
protected function fetchIssueDetails(): GithubIssue
116108
{
117-
$id = $this->argument('id') ?? $this->ask(' GitHub Issue ID:');
109+
$id = $this->argument('id');
118110

119111
if (!is_numeric($id)) {
120112
$this->error('Please provide a valid issue id.');
121113

122-
if (empty($this->argument('id'))) {
123-
$this->askForIssue();
124-
}
125-
126114
exit(1);
127115
}
128116

@@ -134,7 +122,7 @@ protected function askForIssue(): GithubIssue
134122
$this->error('Issue not found.');
135123

136124
if (empty($this->argument('id'))) {
137-
$this->askForIssue();
125+
$this->fetchIssueDetails();
138126
}
139127

140128
exit(1);

src/Command/ReadMantisIssueCommand.php

+8-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
<?php
2-
/*
3-
* This file is part of the Artemeon Core - Web Application Framework.
4-
*
5-
* (c) Artemeon <www.artemeon.de>
6-
*
7-
* For the full copyright and license information, please view the LICENSE
8-
* file that was distributed with this source code.
9-
*/
102

113
namespace Artemeon\M2G\Command;
124

@@ -30,7 +22,7 @@ protected function configure()
3022
{
3123
$this->setName('read:mantis')
3224
->setDescription('Read details of a Mantis issue')
33-
->addArgument('id', InputArgument::OPTIONAL, 'The issue id');
25+
->addArgument('id', InputArgument::REQUIRED, 'The issue id');
3426
}
3527

3628
protected function header(): void
@@ -46,21 +38,21 @@ protected function handle(): int
4638
{
4739
$this->header();
4840

49-
$issue = $this->askForIssue();
41+
$issue = $this->fetchIssueDetails();
5042

5143
terminal()->clear();
5244

53-
if ($issue->getResolution() === 'open') {
45+
if (in_array($issue->getResolution(), ['open', 'reopened'])) {
5446
render(<<<HTML
5547
<div class="my-1 mx-1 px-1 bg-green-500 text-gray-900">
56-
Issue is open
48+
Issue is {$issue->getResolution()}
5749
</div>
5850
HTML);
59-
} else if ($issue->getResolution() === 'fixed') {
51+
} else {
6052
render(
6153
<<<HTML
6254
<div class="my-1 mx-1 px-1 bg-purple-500 text-gray-900">
63-
Issue is fixed
55+
Issue is {$issue->getResolution()}
6456
</div>
6557
HTML
6658
);
@@ -88,17 +80,13 @@ protected function handle(): int
8880
return 0;
8981
}
9082

91-
protected function askForIssue(): ?MantisIssue
83+
protected function fetchIssueDetails(): ?MantisIssue
9284
{
93-
$id = $this->argument('id') ?? $this->ask(' Mantis Issue ID:');
85+
$id = $this->argument('id');
9486

9587
if (!is_numeric($id)) {
9688
$this->error('Please provide a valid issue id.');
9789

98-
if (empty($this->argument('id'))) {
99-
$this->askForIssue();
100-
}
101-
10290
exit(1);
10391
}
10492

@@ -109,10 +97,6 @@ protected function askForIssue(): ?MantisIssue
10997
if (!$issue) {
11098
$this->error('Issue not found.');
11199

112-
if (empty($this->argument('id'))) {
113-
$this->askForIssue();
114-
}
115-
116100
exit(1);
117101
}
118102

src/Config/ConfigReader.php

-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
<?php
2-
/*
3-
* This file is part of the Artemeon Core - Web Application Framework.
4-
*
5-
* (c) Artemeon <www.artemeon.de>
6-
*
7-
* For the full copyright and license information, please view the LICENSE
8-
* file that was distributed with this source code.
9-
*/
102

113
namespace Artemeon\M2G\Config;
124

src/Config/ConfigValues.php

-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
<?php
2-
/*
3-
* This file is part of the Artemeon Core - Web Application Framework.
4-
*
5-
* (c) Artemeon <www.artemeon.de>
6-
*
7-
* For the full copyright and license information, please view the LICENSE
8-
* file that was distributed with this source code.
9-
*/
102

113
namespace Artemeon\M2G\Config;
124

0 commit comments

Comments
 (0)