| 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\Traits; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Slack\DataObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use T3Bot\Slack\Message\Attachment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Trait SlackTrait | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | trait SlackTrait | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * make text bold. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @param $string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 22 |  |     protected function bold($string) : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 22 |  |         return '*' . $string . '*'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * make text italic. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param $string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 7 |  |     protected function italic($string) : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 7 |  |         return '_' . $string . '_'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * build a review line. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @param \stdClass $item the review item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 3 |  |     protected function buildReviewLine($item) : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 3 |  |         return $this->bold($item->subject) . ' <https://review.typo3.org/' . $item->_number | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 3 |  |         . '|Review #' . $item->_number . ' now>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param $item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 6 |  |     protected function buildIssueMessage($item) : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 6 |  |         $created = substr($item->created_on, 0, 19); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 6 |  |         $updated = substr($item->updated_on, 0, 19); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 6 |  |         $text = $this->bold('[' . $item->tracker->name . '] ' . $item->subject) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 6 |  |             . ' by ' . $this->italic($item->author->name) . chr(10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 6 |  |         $text .= 'Project: ' . $this->bold($item->project->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 6 |  |         if (!empty($item->category->name)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             $text .= ' | Category: ' . $this->bold($item->category->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 6 |  |         $text .= ' | Status: ' . $this->bold($item->status->name) . chr(10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 6 |  |         $text .= ':calendar: Created: ' . $this->bold($created) . ' | Last update: ' . $this->bold($updated) . chr(10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 6 |  |         $text .= '<https://forge.typo3.org/issues/' . $item->id . '|:arrow_right: View on Forge>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 6 |  |         return $text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @param string $text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @param string $channel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 84 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 85 | 5 |  |     protected function getBaseDataArray(string $text, string $channel) : array | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 | 5 |  |         $data = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 88 | 5 |  |         $data['unfurl_links'] = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 89 | 5 |  |         $data['unfurl_media'] = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 90 | 5 |  |         $data['parse'] = 'none'; | 
            
                                                                        
                            
            
                                    
            
            
                | 91 | 5 |  |         $data['text'] = $text; | 
            
                                                                        
                            
            
                                    
            
            
                | 92 | 5 |  |         $data['channel'] = $channel; | 
            
                                                                        
                            
            
                                    
            
            
                | 93 | 5 |  |         return $data; | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @param Attachment $attachment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @return DataObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 4 |  |     protected function buildAttachment(Attachment $attachment) : DataObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 4 |  |         return \Slack\Message\Attachment::fromData([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 4 |  |             'title' => $attachment->getTitle(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 4 |  |             'title_link' => $attachment->getTitleLink(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 4 |  |             'text' => $attachment->getText(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 4 |  |             'fallback' => $attachment->getFallback(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 4 |  |             'color' => $attachment->getColor(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 4 |  |             'pretext' => $attachment->getPretext(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 4 |  |             'author_name' => $attachment->getAuthorName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 4 |  |             'author_icon' => $attachment->getAuthorIcon(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 4 |  |             'author_link' => $attachment->getAuthorLink(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 4 |  |             'image_url' => $attachment->getImageUrl(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 4 |  |             'thumb_url' => $attachment->getThumbUrl(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 117 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |  |