Skip to content

Commit

Permalink
Merge pull request #45 from tanhongit/refactor-events
Browse files Browse the repository at this point in the history
(#33) update some global functions
  • Loading branch information
tanhongit authored Jun 28, 2023
2 parents 5d7b49e + 47b4771 commit 145dc3a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## Requirement

- PHP ^7.2|^8.0
- PHP ^8.0
- Composer
- Telegram Bot

Expand Down
20 changes: 18 additions & 2 deletions common/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,31 @@ function urlencoded_message(string $message): array|string
}
}

if (!function_exists('get_template')) {
/**
* Get template
*
* @param string $partialPath
* @param array $data
* @return bool|string
*/
function get_template(string $partialPath, array $data = []): bool|string
{
return (new ConfigHelper())->getTemplateData($partialPath, $data);
}
}

if (!function_exists('get_event_template')) {
/**
* Get event template
*
* @param string $partialPath
* @param array $data
* @return bool|string
*/
function get_event_template(string $partialPath, array $data = []): bool|string
{
return (new ConfigHelper())->getEventTemplate('events/' . $partialPath, $data);
return (new ConfigHelper())->getTemplateData('events/' . $partialPath, $data);
}
}

Expand All @@ -69,6 +85,6 @@ function get_event_template(string $partialPath, array $data = []): bool|string
*/
function get_tool_template(string $partialPath, array $data = []): bool|string
{
return (new ConfigHelper())->getEventTemplate('tools/' . $partialPath, $data);
return (new ConfigHelper())->getTemplateData('tools/' . $partialPath, $data);
}
}
8 changes: 4 additions & 4 deletions resources/events/pull_request/partials/_reviewers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* @var $payload mixed
*/

$message = '';
if (count($payload->pull_request->requested_reviewers) > 0) {
$textReviewers = '';
if (isset($payload->pull_request->requested_reviewers) && count($payload->pull_request->requested_reviewers) > 0) {
$reviewers = [];
foreach ($payload->pull_request->requested_reviewers as $reviewer) {
$reviewers[] = $reviewer->login;
}

$message .= "👥 Reviewers: " . implode(', ', $reviewers) . "\n";
$textReviewers .= "👥 Reviewers: " . implode(', ', $reviewers) . "\n";
}

return $message;
return $textReviewers;
2 changes: 1 addition & 1 deletion src/Helpers/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function execConfig(string $string): mixed
* @param array $data
* @return bool|string
*/
public function getEventTemplate($partialPath, array $data = []): bool|string
public function getTemplateData($partialPath, array $data = []): bool|string
{
$viewPathFile = self::VIEW_PATH . '/' . str_replace('.', '/', $partialPath) . '.php';

Expand Down

0 comments on commit 145dc3a

Please sign in to comment.