Skip to content

Commit 217e066

Browse files
committed
added stripping images for vulnerability notifications ,.. they never lookedf right and toook up too much space.
1 parent 9ddd08c commit 217e066

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.opencode
12
.logs
23
.env
34
vendor/

src/GithubMessageBuilder.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ private function buildIssuesText(array $Message, string $RepositoryName, string
141141
}
142142

143143
if (!empty($Issue['body'])) {
144-
$ChatMsg .= "\n\n> " . substr($Issue['body'], 0, 500) . (strlen($Issue['body']) > 500 ? "" : "");
144+
$body = self::stripImages($Issue['body']);
145+
$ChatMsg .= "\n\n> " . substr($body, 0, 500) . (strlen($body) > 500 ? "" : "");
145146
}
146147

147148
return $ChatMsg;
@@ -190,7 +191,8 @@ private function buildPullRequestText(array $Message, string $RepositoryName, st
190191
}
191192

192193
if (!empty($PR['body'])) {
193-
$ChatMsg .= "\n\n> " . substr($PR['body'], 0, 500) . (strlen($PR['body']) > 500 ? "" : "");
194+
$body = self::stripImages($PR['body']);
195+
$ChatMsg .= "\n\n> " . substr($body, 0, 500) . (strlen($body) > 500 ? "" : "");
194196
}
195197

196198
return $ChatMsg;
@@ -326,4 +328,14 @@ private function buildDefaultText(string $EventType, array $Message, string $Rep
326328
. (isset($Message['action']) ? "({$Message['action']}) " : "")
327329
. "on [{$RepositoryName}](https://github.com/{$RepositoryName}).";
328330
}
331+
332+
private static function stripImages(string $text): string
333+
{
334+
// Remove markdown images: ![alt](url)
335+
$text = preg_replace('/!\[.*?\]\(.*?\)/', '', $text);
336+
// Remove HTML <img> tags and their contents
337+
$text = preg_replace('/<img[^>]*>.*?<\/img>/', '', $text);
338+
$text = preg_replace('/<img[^>]*\/>/', '', $text);
339+
return trim($text);
340+
}
329341
}

0 commit comments

Comments
 (0)