1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* T3Bot. |
4
|
|
|
* |
5
|
|
|
* @author Frank Nägler <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @link http://www.t3bot.de |
8
|
|
|
* @link http://wiki.typo3.org/T3Bot |
9
|
|
|
*/ |
10
|
|
|
namespace T3Bot\Commands; |
11
|
|
|
|
12
|
|
|
use Slack\Payload; |
13
|
|
|
use Slack\RealTimeClient; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ForgeCommand. |
17
|
|
|
* |
18
|
|
|
* @property string commandName |
19
|
|
|
* @property array helpCommands |
20
|
|
|
*/ |
21
|
|
|
class ForgeCommand extends AbstractCommand |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* AbstractCommand constructor. |
25
|
|
|
* |
26
|
|
|
* @param Payload $payload |
27
|
|
|
* @param RealTimeClient $client |
28
|
|
|
* @param array|null $configuration |
29
|
|
|
*/ |
30
|
10 |
View Code Duplication |
public function __construct(Payload $payload, RealTimeClient $client, array $configuration = null) |
31
|
|
|
{ |
32
|
10 |
|
$this->commandName = 'forge'; |
33
|
10 |
|
$this->helpCommands = [ |
34
|
|
|
'help' => 'shows this help', |
35
|
|
|
'show [Issue-ID]' => 'shows the issue by given [Issue-ID]', |
36
|
|
|
]; |
37
|
10 |
|
parent::__construct($payload, $client, $configuration); |
38
|
10 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* process show. |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
9 |
|
protected function processShow() : string |
46
|
|
|
{ |
47
|
9 |
|
$urlPattern = '/http[s]*:\/\/forge.typo3.org\/issues\/([\d]*)(?:.*)/i'; |
48
|
9 |
|
$value = $this->params[1] ?? 0; |
49
|
9 |
|
if (preg_match_all($urlPattern, $value, $matches) > 0) { |
50
|
4 |
|
$issueNumber = (int) $matches[1][0]; |
51
|
|
|
} |
52
|
9 |
|
$issueNumber = $issueNumber ?? $value; |
53
|
9 |
|
if ((int)$issueNumber === 0) { |
54
|
2 |
|
return 'hey, I need an issue number!'; |
55
|
|
|
} |
56
|
7 |
|
$result = $this->queryForge("issues/{$issueNumber}"); |
57
|
7 |
|
if ($result) { |
58
|
6 |
|
return $this->buildIssueMessage($result->issue); |
59
|
|
|
} |
60
|
1 |
|
return 'Sorry not found!'; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|