diff --git a/resources/events/pull_request/closed.php b/resources/events/pull_request/closed.php index e69de29..824b2cb 100644 --- a/resources/events/pull_request/closed.php +++ b/resources/events/pull_request/closed.php @@ -0,0 +1,23 @@ +Pull Request Merged'; +if (!isset($payload->pull_request->merged) || $payload->pull_request->merged !== true) { + $message = '❌ Pull Request Closed'; +} + +$message = $message . " - pull_request->html_url}\">{$payload->repository->full_name}#{$payload->pull_request->number} by pull_request->user->html_url}\">@{$payload->pull_request->user->login}\n\n"; + +$message .= "🛠 {$payload->pull_request->title} \n\n"; + +if (isset($payload->pull_request->assignee)) { + $message .= "🙋 Assignee: pull_request->assignee->html_url}\">@{$payload->pull_request->assignee->login}\n"; +} + +$message .= require __DIR__ . '/partials/_reviewers.php'; + +$message .= require __DIR__ . '/partials/_body.php'; + +echo $message; diff --git a/resources/events/pull_request/opened.php b/resources/events/pull_request/opened.php index a960def..eab3e7b 100644 --- a/resources/events/pull_request/opened.php +++ b/resources/events/pull_request/opened.php @@ -2,3 +2,17 @@ /** * @var $payload mixed */ + +$message = "👷‍♂️🛠️ New Pull Request - pull_request->html_url}\">{$payload->repository->full_name}#{$payload->pull_request->number} create by pull_request->user->html_url}\">@{$payload->pull_request->user->login}\n\n"; + +$message .= "🛠 {$payload->pull_request->title} \n\n"; + +if (isset($payload->pull_request->assignee)) { + $message .= "🙋 Assignee: pull_request->assignee->html_url}\">@{$payload->pull_request->assignee->login}\n"; +} + +$message .= require __DIR__ . '/partials/_reviewers.php'; + +$message .= require __DIR__ . '/partials/_body.php'; + +echo $message; diff --git a/resources/events/pull_request/partials/_body.php b/resources/events/pull_request/partials/_body.php new file mode 100644 index 0000000..8dc5506 --- /dev/null +++ b/resources/events/pull_request/partials/_body.php @@ -0,0 +1,14 @@ +pull_request->body)) { + $body = $payload->pull_request->body; + if (strlen($body) > 50) { + $body = substr($body, 0, 50) . '...'; + } + return "📖 Body:\n{$body}"; +} + +return ""; diff --git a/resources/events/pull_request/partials/_reviewers.php b/resources/events/pull_request/partials/_reviewers.php new file mode 100644 index 0000000..fe94aee --- /dev/null +++ b/resources/events/pull_request/partials/_reviewers.php @@ -0,0 +1,16 @@ +pull_request->requested_reviewers) > 0) { + $reviewers = []; + foreach ($payload->pull_request->requested_reviewers as $reviewer) { + $reviewers[] = $reviewer->login; + } + + $message .= "👥 Reviewers: " . implode(', ', $reviewers) . "\n"; +} + +return $message; diff --git a/resources/events/pull_request/reopened.php b/resources/events/pull_request/reopened.php index e69de29..1041189 100644 --- a/resources/events/pull_request/reopened.php +++ b/resources/events/pull_request/reopened.php @@ -0,0 +1,18 @@ +Reopened Pull Request - pull_request->html_url}\">{$payload->repository->full_name}#{$payload->pull_request->number} by pull_request->user->html_url}\">@{$payload->pull_request->user->login}\n\n"; + +$message .= "🛠 {$payload->pull_request->title} \n\n"; + +if (isset($payload->pull_request->assignee)) { + $message .= "🙋 Assignee: pull_request->assignee->html_url}\">@{$payload->pull_request->assignee->login}\n"; +} + +$message .= require __DIR__ . '/partials/_reviewers.php'; + +$message .= require __DIR__ . '/partials/_body.php'; + +echo $message; diff --git a/resources/events/workflow_run/completed.php b/resources/events/workflow_run/completed.php index 0fd4744..f9b63a4 100644 --- a/resources/events/workflow_run/completed.php +++ b/resources/events/workflow_run/completed.php @@ -7,8 +7,8 @@ $message .= "Done workflow: 🎉 {$payload->workflow_run->name} ✨ \n\n"; -$message .= "📤 Commit: {$payload->workflow_run->head_commit->message}\n"; +$message .= "📤 Commit: {$payload->workflow_run->head_commit->message}\n\n"; -$message .= "🔗 Link: workflow_run->html_url}\">{$payload->workflow_run->runner_id}\n\n"; +$message .= "🔗 Link: workflow_run->html_url}\">{$payload->workflow_run->html_url}\n\n"; echo $message; diff --git a/resources/events/workflow_run/requested.php b/resources/events/workflow_run/requested.php index 06d40c9..908c51c 100644 --- a/resources/events/workflow_run/requested.php +++ b/resources/events/workflow_run/requested.php @@ -7,8 +7,8 @@ $message .= "Running workflow: 💥 {$payload->workflow_run->name} ⏳\n\n"; -$message .= "📤 Commit: {$payload->workflow_run->head_commit->message}\n"; +$message .= "📤 Commit: {$payload->workflow_run->head_commit->message}\n\n"; -$message .= "🔗 Link: workflow_run->html_url}\">{$payload->workflow_run->runner_id}\n\n"; +$message .= "🔗 Link: workflow_run->html_url}\">{$payload->workflow_run->html_url}\n\n"; echo $message; diff --git a/resources/tools/about.php b/resources/tools/about.php new file mode 100644 index 0000000..617dfe0 --- /dev/null +++ b/resources/tools/about.php @@ -0,0 +1,3 @@ +Thanks for using our bot. + +The bot is designed to send notifications based on GitHub events from your github repo instantly to your Telegram account. diff --git a/resources/tools/help.php b/resources/tools/help.php new file mode 100644 index 0000000..3b7d665 --- /dev/null +++ b/resources/tools/help.php @@ -0,0 +1,8 @@ +Available Commands + +/id - To get chat id. +/host - To get Host Address. +/help - To show this Message. +/usage - How to use me. + +Select a command : diff --git a/resources/tools/host.php b/resources/tools/host.php new file mode 100644 index 0000000..8feb335 --- /dev/null +++ b/resources/tools/host.php @@ -0,0 +1 @@ +Server Address : diff --git a/resources/tools/start.php b/resources/tools/start.php new file mode 100644 index 0000000..724e13e --- /dev/null +++ b/resources/tools/start.php @@ -0,0 +1,11 @@ + +🙋🏻 🤓 + +Hey , + +I can send you notifications from your GitHub Repository instantly to your Telegram. use /help for more information about me. diff --git a/resources/tools/usage.php b/resources/tools/usage.php new file mode 100644 index 0000000..f5e6e34 --- /dev/null +++ b/resources/tools/usage.php @@ -0,0 +1,8 @@ +Adding webhook (Website Address) to your GitHub repository + +1) Redirect to Repository Settings->Webhook->Add Webhook. +2) Set your Payload URL. +3) Set content type to "application/x-www-form-urlencoded" +4) Choose events would you like to trigger in this webhook. + +That it. you will receive all notifications through me 🤗 diff --git a/src/Services/TelegramService.php b/src/Services/TelegramService.php index c2789d5..47a1a68 100644 --- a/src/Services/TelegramService.php +++ b/src/Services/TelegramService.php @@ -64,9 +64,9 @@ public function telegramToolHandler(string $text = null): void { switch ($text) { case '/start': - ; - $reply = "🙋🏻 " . config('app.name') - . " 🤓\n\nHey {$this->telegram->FirstName()},\n\nI can send you notifications from your GitHub Repository instantly to your Telegram. use /help for more information about me."; + $reply = get_tool_template('start', [ + 'first_name' => $this->telegram->FirstName() + ]); $content = array( 'chat_id' => $this->chatId, 'photo' => curl_file_create('public/images/github.jpeg', 'image/png'), @@ -90,7 +90,7 @@ public function telegramToolHandler(string $text = null): void ), ] ]; - $reply = "Available Commands \n\n/id - To get chat id.\n/host - To get Host Address.\n/help - To show this Message.\n/usage - How to use me.\n\nSelect a command :"; + $reply = get_tool_template('help'); $content = array( 'chat_id' => $this->chatId, 'reply_markup' => $this->telegram->buildInlineKeyBoard($option), @@ -113,7 +113,7 @@ public function telegramToolHandler(string $text = null): void break; case '/host': - $reply = "Server Address : {$_SERVER['REMOTE_ADDR']}"; + $reply = get_tool_template('host'); $content = array( 'chat_id' => $this->chatId, 'text' => $reply, @@ -124,7 +124,7 @@ public function telegramToolHandler(string $text = null): void break; case '/usage': - $reply = "Adding webhook (Website Address) to your GitHub repository\n\n 1) Redirect to Repository Settings->Webhook->Add Webhook. \n 2) Set your Payload URL.\n 3) Set content type to \"application/x-www-form-urlencoded\"\n 4) Choose events would you like to trigger in this webhook.\n\n That it. you will receive all notifications through me 🤗"; + $reply = get_tool_template('usage'); $content = array( 'chat_id' => $this->chatId, 'text' => $reply, @@ -151,7 +151,7 @@ public function telegramToolHandler(string $text = null): void protected function sendCallbackResponse(string $callback = null): void { if (!empty($callback) && $callback == 'about') { - $reply = "Thanks for using our bot.\n\nThe bot is designed to send notifications based on GitHub events from your github repo instantly to your Telegram account."; + $reply = get_tool_template('about'); $content = array( 'callback_query_id' => $this->telegram->Callback_ID(), 'text' => $reply,