|
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
|
23 |
|
protected function bold($string) : string |
|
28
|
|
|
{ |
|
29
|
23 |
|
return '*' . $string . '*'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* make text italic. |
|
34
|
|
|
* |
|
35
|
|
|
* @param $string |
|
36
|
|
|
* |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
8 |
|
protected function italic($string) : string |
|
40
|
|
|
{ |
|
41
|
8 |
|
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
|
7 |
|
protected function buildIssueMessage($item) : string |
|
63
|
|
|
{ |
|
64
|
7 |
|
$created = substr($item->created_on, 0, 19); |
|
65
|
7 |
|
$updated = substr($item->updated_on, 0, 19); |
|
66
|
7 |
|
$text = $this->bold('[' . $item->tracker->name . '] ' . $item->subject) |
|
67
|
7 |
|
. ' by ' . $this->italic($item->author->name) . chr(10); |
|
68
|
7 |
|
$text .= 'Project: ' . $this->bold($item->project->name); |
|
69
|
7 |
|
if (!empty($item->category->name)) { |
|
70
|
1 |
|
$text .= ' | Category: ' . $this->bold($item->category->name); |
|
71
|
|
|
} |
|
72
|
7 |
|
$text .= ' | Status: ' . $this->bold($item->status->name) . chr(10); |
|
73
|
7 |
|
$text .= ':calendar: Created: ' . $this->bold($created) . ' | Last update: ' . $this->bold($updated) . chr(10); |
|
74
|
7 |
|
$text .= '<https://forge.typo3.org/issues/' . $item->id . '|:arrow_right: View on Forge>'; |
|
75
|
|
|
|
|
76
|
7 |
|
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
|
|
|
|