Skip to content

Commit

Permalink
(#33) update template message for some events v5
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Jun 28, 2023
1 parent 5371f5a commit d7b4f03
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n\n";
}

$message .= require __DIR__ . '/../partials/_body.php';
$message .= require __DIR__ . '/partials/_body.php';

echo $message;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n\n";
}

$message .= require __DIR__ . '/../partials/_body.php';
$message .= require __DIR__ . '/partials/_body.php';

echo $message;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n\n";
}

$message .= require __DIR__ . '/../partials/_body.php';
$message .= require __DIR__ . '/partials/_body.php';

echo $message;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n\n";
}

$message .= require __DIR__ . '/../partials/_body.php';
$message .= require __DIR__ . '/partials/_body.php';

echo $message;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n\n";
}

$message .= require __DIR__ . '/../partials/_body.php';
$message .= require __DIR__ . '/partials/_body.php';

echo $message;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n\n";
}

$message .= require __DIR__ . '/../partials/_body.php';
$message .= require __DIR__ . '/partials/_body.php';

echo $message;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n\n";
}

$message .= require __DIR__ . '/../partials/_body.php';
$message .= require __DIR__ . '/partials/_body.php';

echo $message;
4 changes: 3 additions & 1 deletion resources/events/push/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
$message .= "<a href=\"{$commit->url}\">{$commitId}</a>: {$commit->message} - by <i>{$commit->author->name}</i>\n";
}

$message .= "\n 👤 Pushed by : <b>{$payload->pusher->name}</b>\n";
$message .= "\n👤 Pushed by : <b>{$payload->pusher->name}</b>\n";

echo $message;
12 changes: 12 additions & 0 deletions resources/events/workflow_job/completed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* @var $payload mixed
*/

$message = "🎉 <b>Action Completed</b> from <a href=\"{$payload->repository->html_url}\">{$payload->repository->full_name} </a>\n\n";

$message .= "Done action: 🎉 <b>{$payload->workflow_job->runner_name}</b> ✨ \n\n";

$message .= "🔗 Link: <a href=\"{$payload->workflow_job->html_url}\">{$payload->workflow_job->html_url}</a>\n\n";

echo $message;
12 changes: 12 additions & 0 deletions resources/events/workflow_job/in_progress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* @var $payload mixed
*/

$message = "🔧 <b>Action in progress</b> from <a href=\"{$payload->repository->html_url}\">{$payload->repository->full_name} </a>\n\n";

$message .= "Running action: 💥 <b>{$payload->workflow_job->runner_name}</b> ⏳\n\n";

$message .= "🔗 Link: <a href=\"{$payload->workflow_job->html_url}\">{$payload->workflow_job->html_url}</a>\n\n";

echo $message;
14 changes: 14 additions & 0 deletions resources/events/workflow_run/completed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @var $payload mixed
*/

$message = "🎉 <b>Workflow Completed</b> from <a href=\"{$payload->repository->html_url}\">{$payload->repository->full_name} </a>\n\n";

$message .= "Done workflow: 🎉 <b>{$payload->workflow_run->name}</b> ✨ \n\n";

$message .= "📤 Commit: <b>{$payload->workflow_run->head_commit->message}</b>\n";

$message .= "🔗 Link: <a href=\"{$payload->workflow_run->html_url}\">{$payload->workflow_run->runner_id}</a>\n\n";

echo $message;
14 changes: 14 additions & 0 deletions resources/events/workflow_run/requested.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @var $payload mixed
*/

$message = "🔧 <b>Workflow Requested</b> from <a href=\"{$payload->repository->html_url}\">{$payload->repository->full_name} </a>\n\n";

$message .= "Running workflow: 💥 <b>{$payload->workflow_run->name}</b> ⏳\n\n";

$message .= "📤 Commit: <b>{$payload->workflow_run->head_commit->message}</b>\n";

$message .= "🔗 Link: <a href=\"{$payload->workflow_run->html_url}\">{$payload->workflow_run->runner_id}</a>\n\n";

echo $message;
8 changes: 6 additions & 2 deletions src/Services/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function setPayload(Request $request): void
public function setMessage(string $typeEvent): void
{
if (isset($this->payload->action) && !empty($this->payload->action)) {
$this->message = get_event_template($typeEvent . '.action.' . $this->payload->action, ['payload' => $this->payload]);
$this->message = get_event_template(
$typeEvent . '.' . $this->payload->action,
['payload' => $this->payload]
);
} else {
$this->message = get_event_template($typeEvent . '.default', ['payload' => $this->payload]);
}
Expand All @@ -77,7 +80,8 @@ public function sendNotify(string $chatId, string $message = null): bool
}

$method_url = 'https://api.telegram.org/bot' . config('telegram-bot.token') . '/sendMessage';
$url = $method_url . '?chat_id=' . $chatId . '&disable_web_page_preview=1&parse_mode=html&text=' . urlencoded_message($this->message);
$url = $method_url . '?chat_id=' . $chatId . '&disable_web_page_preview=1&parse_mode=html&text='
. urlencoded_message($this->message);

$client = new Client();
$response = $client->request('GET', $url);
Expand Down

0 comments on commit d7b4f03

Please sign in to comment.