1 | <?php |
||
18 | class GerritHookController extends AbstractHookController |
||
19 | { |
||
20 | use GerritTrait; |
||
21 | |||
22 | /** |
||
23 | * public method to start processing the request. |
||
24 | * |
||
25 | * @param string $hook |
||
26 | * @param string $input |
||
27 | * |
||
28 | * @throws \Doctrine\DBAL\DBALException |
||
29 | */ |
||
30 | 11 | public function process($hook, $input = 'php://input') |
|
42 | |||
43 | /** |
||
44 | * @param string $hook |
||
45 | * @param \stdClass $json |
||
46 | * |
||
47 | * @throws \Doctrine\DBAL\DBALException |
||
48 | */ |
||
49 | 8 | protected function processHook(string $hook, \stdClass $json) |
|
67 | |||
68 | /** |
||
69 | * @param string $title |
||
70 | * @param string $text |
||
71 | * @param string $color |
||
72 | * |
||
73 | * @return Message |
||
74 | */ |
||
75 | 7 | protected function buildMessage(string $title, string $text, string $color = Message\Attachment::COLOR_NOTICE) : Message |
|
89 | |||
90 | /** |
||
91 | * @param int $patchId |
||
92 | * @param int $commit |
||
93 | * |
||
94 | * @throws \Doctrine\DBAL\DBALException |
||
95 | */ |
||
96 | 5 | protected function checkFiles($patchId, $commit) |
|
97 | { |
||
98 | 5 | $files = $this->getFilesForPatch($patchId, $commit); |
|
99 | 5 | $rstFiles = []; |
|
100 | 5 | if (!empty($files)) { |
|
101 | 5 | foreach ($files as $fileName => $changeInfo) { |
|
102 | 5 | if ($this->endsWith(strtolower($fileName), '.rst')) { |
|
103 | 5 | $rstFiles[$fileName] = $changeInfo; |
|
104 | } |
||
105 | } |
||
106 | 5 | if (!empty($rstFiles)) { |
|
107 | 3 | $message = new Message(); |
|
108 | 3 | $message->setText(' '); |
|
109 | 3 | foreach ($rstFiles as $fileName => $changeInfo) { |
|
110 | 3 | $message->addAttachment($this->buildFileAttachment($fileName, $changeInfo)); |
|
111 | } |
||
112 | 3 | $this->sendMessageToChannel('rst-merged', $message); |
|
113 | } |
||
114 | } |
||
115 | 5 | } |
|
116 | |||
117 | /** |
||
118 | * @param string $fileName |
||
119 | * @param \stdClass $changeInfo |
||
120 | * |
||
121 | * @return Message\Attachment |
||
122 | */ |
||
123 | 3 | protected function buildFileAttachment(string $fileName, \stdClass $changeInfo) : Message\Attachment |
|
124 | { |
||
125 | 3 | $attachment = new Message\Attachment(); |
|
126 | 3 | $status = $changeInfo->status ?? 'default'; |
|
127 | $color = [ |
||
128 | 3 | 'A' => Message\Attachment::COLOR_GOOD, |
|
129 | 'D' => Message\Attachment::COLOR_WARNING, |
||
130 | 'default' => Message\Attachment::COLOR_WARNING, |
||
131 | ]; |
||
132 | $text = [ |
||
133 | 3 | 'A' => 'A new documentation file has been added', |
|
134 | 'D' => 'A documentation file has been removed', |
||
135 | 'default' => 'A documentation file has been updated', |
||
136 | ]; |
||
137 | 3 | $attachment->setColor($color[$status]); |
|
138 | 3 | $attachment->setTitle($text[$status]); |
|
139 | |||
140 | 3 | $text = ':link: <https://git.typo3.org/Packages/TYPO3.CMS.git/blob/HEAD:/' . $fileName . '|' . $fileName . '>'; |
|
141 | 3 | $attachment->setText($text); |
|
142 | 3 | $attachment->setFallback($text); |
|
143 | 3 | return $attachment; |
|
144 | } |
||
145 | |||
146 | /** |
||
147 | * @param string $hook |
||
148 | * @param Message $message |
||
149 | * |
||
150 | * @throws \Doctrine\DBAL\DBALException |
||
151 | */ |
||
152 | 7 | protected function sendMessageToChannel(string $hook, Message $message) |
|
160 | } |
||
161 |