Skip to content

Commit

Permalink
(#33) update template message for some events
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Jun 27, 2023
1 parent a20bd39 commit 9368aa1
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 75 deletions.
16 changes: 16 additions & 0 deletions resources/events/issues/action/closed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* @var $payload mixed
*/

$message = "🚫 <b>Issue Closed </b> to <a href=\"{$payload->issue->html_url}\">{$payload->repository->full_name}#{$payload->issue->number}</a>\n\n";

if (isset($payload->issue->assignee)) {
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n";
}

$message .= "🔔 <a href=\"{$payload->issue->html_url}\">{$payload->issue->title}</a> by <a href=\"{$payload->issue->user->html_url}\">@{$payload->issue->user->login}</a>\n\n";

$message .= " {$payload->issue->body}";

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

$message = "⚠️ <b>Issue has been edited</b> to <a href=\"{$payload->issue->html_url}\">{$payload->repository->full_name}#{$payload->issue->number}</a>\n\n";

if (isset($payload->issue->assignee)) {
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n";
}

$message .= "🔔 <a href=\"{$payload->issue->html_url}\">{$payload->issue->title}</a> by <a href=\"{$payload->issue->user->html_url}\">@{$payload->issue->user->login}</a>\n\n";

$message .= " {$payload->issue->body}";

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

$message = "⚠️ <b>New Issue</b> to <a href=\"{$payload->issue->html_url}\">{$payload->repository->full_name}#{$payload->issue->number}</a>\n\n";

if (isset($payload->issue->assignee)) {
$message .= "🙋 Assignee: <a href=\"{$payload->issue->assignee->html_url}\">@{$payload->issue->assignee->login}</a>\n";
}

$message .= "🔔 <a href=\"{$payload->issue->html_url}\">{$payload->issue->title}</a> by <a href=\"{$payload->issue->user->html_url}\">@{$payload->issue->user->login}</a>\n\n";

$message .= " {$payload->issue->body}";

echo $message;
Empty file removed resources/events/issues/closed.php
Empty file.
Empty file removed resources/events/issues/edited.php
Empty file.
Empty file removed resources/events/issues/opened.php
Empty file.
20 changes: 20 additions & 0 deletions resources/events/ping/default.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* @var $payload mixed
*/

$message = "♻️ <b>Connection Successful</b>\n\n";

if (isset($payload->organization)) {
$message .= "Organization: <b>{$payload->organization->login}</b>\n";
}

if (isset($payload->repository)) {
$message .= "Repository: <b>{$payload->repository->full_name}</b>\n";
}

if (isset($payload->sender)) {
$message .= "Sender (triggered the event): <b>{$payload->sender->login}</b>\n";
}

echo $message;
6 changes: 3 additions & 3 deletions resources/events/push/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
$message = "⚙️ <b>{$count}</b> new {$noun} to <b>{$payload->repository->name}:{$payload->repository->default_branch}</b>\n\n";

foreach ($payload->commits as $commit) {
$commitId = substr($commit->id, -7);
$this->message .= "<a href=\"{$commit->url}\">{$commitId}</a>: {$commit->message} by <i>{$commit->author->name}</i>\n";
$commitId = substr($commit->id, -7);
$message .= "<a href=\"{$commit->url}\">{$commitId}</a>: {$commit->message} - by <i>{$commit->author->name}</i>\n";
}

$this->message .= "\nPushed by : <b>{$payload->pusher->name}</b>\n";
$message .= "\nPushed by : <b>{$payload->pusher->name}</b>\n";
76 changes: 4 additions & 72 deletions src/Services/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,88 +48,20 @@ public function setPayload(Request $request): void
}

/**
* Set message from payload
*
* @param string $typeEvent
* @return void
*/
public function setMessage(string $typeEvent): void
{
if (isset($this->payload->action)) {
$this->message = get_event_template($typeEvent . '.' . $this->payload->action, ['payload' => $this->payload]);
if (isset($this->payload->action) && !empty($this->payload->action)) {
$this->message = get_event_template($typeEvent . '.action.' . $this->payload->action, ['payload' => $this->payload]);
} else {
$this->message = get_event_template($typeEvent . '.default', ['payload' => $this->payload]);
}
}

/**
* Set message from payload
*
* @param string $typeEvent
* @return void
*/
/*private function setMessageBK(string $typeEvent): void
{
switch ($typeEvent) {
case 'push':
$count = count($this->payload->commits);
$noun = ($count > 1) ? "commits" : "commit";
$this->message .= "⚙️ <b>{$count}</b> new {$noun} to <b>{$this->payload->repository->name}:{$this->payload->repository->default_branch}</b>\n\n";
foreach ($this->payload->commits as $commit) {
$commitId = substr($commit->id, -7);
$this->message .= "<a href=\"{$commit->url}\">{$commitId}</a>: {$commit->message} by <i>{$commit->author->name}</i>\n";
}
$this->message .= "\nPushed by : <b>{$this->payload->pusher->name}</b>\n";
break;
case 'ping':
$this->message .= "♻️ <b>Connection Successful</b>\n\n Repository: <b>{$this->payload->repository->full_name}</b>\n";
break;
case 'issues':
if ($this->payload->action == "opened") {
$this->message .= "⚠️ <b>New Issue</b> - <a href=\"{$this->payload->issue->html_url}\">{$this->payload->repository->full_name}#{$this->payload->issue->number}</a>\n\n";
$this->message .= "<a href=\"{$this->payload->issue->html_url}\">{$this->payload->issue->title}</a> by <a href=\"{$this->payload->issue->user->html_url}\">@{$this->payload->issue->user->login}</a>\n\n";
$this->message .= " {$this->payload->issue->body}";
} elseif ($this->payload->action == "closed") {
$this->message .= "🚫 <b>Issue Closed </b> - <a href=\"{$this->payload->issue->html_url}\">{$this->payload->repository->full_name}#{$this->payload->issue->number}</a>\n\n";
$this->message .= "<a href=\"{$this->payload->issue->html_url}\">{$this->payload->issue->title}</a> by <a href=\"{$this->payload->issue->user->html_url}\">@{$this->payload->issue->user->login}</a>\n\n";
$this->message .= " {$this->payload->issue->body}";
}
break;
case 'pull_request':
if ($this->payload->action == "opened") {
$this->message .= "👷‍♂️🛠️ <b>New Pull Request</b> - <a href=\"{$this->payload->pull_request->html_url}\">{$this->payload->repository->full_name}#{$this->payload->pull_request->number}</a>\n\n";
$this->message .= "<a href=\"{$this->payload->pull_request->url}\">{$this->payload->pull_request->title}</a> by <a href=\"{$this->payload->pull_request->user->html_url}\">@{$this->payload->pull_request->user->login}</a>\n\n";
$this->message .= " {$this->payload->pull_request->body}";
} elseif ($this->payload->action == "closed") {
$this->message .= "✅ <b>Pull Request Merged </b> - <a href=\"{$this->payload->pull_request->html_url}\">{$this->payload->repository->full_name}#{$this->payload->pull_request->number}</a>\n\n";
$this->message .= "<a href=\"{$this->payload->pull_request->html_url}\">{$this->payload->pull_request->title}</a> by <a href=\"{$this->payload->pull_request->user->html_url}\">@{$this->payload->pull_request->user->login}</a>\n\n";
$this->message .= " {$this->payload->pull_request->body}";
} elseif ($this->payload->action == "reopened") {
$this->message .= "🔓 <b>Pull Request Reopened </b> - <a href=\"{$this->payload->pull_request->html_url}\">{$this->payload->repository->full_name}#{$this->payload->pull_request->number}</a>\n\n";
$this->message .= "<a href=\"{$this->payload->pull_request->html_url}\">{$this->payload->pull_request->title}</a> by <a href=\"{$this->payload->pull_request->user->html_url}\">@{$this->payload->pull_request->user->login}</a>\n\n";
$this->message .= " {$this->payload->pull_request->body}";
} elseif ($this->payload->action == "assigned") {
$this->message .= "👨‍💻 <b>Pull Request Assigned </b> - <a href=\"{$this->payload->pull_request->html_url}\">{$this->payload->repository->full_name}#{$this->payload->pull_request->number}</a>\n\n";
$this->message .= "<a href=\"{$this->payload->pull_request->html_url}\">{$this->payload->pull_request->title}</a> by <a href=\"{$this->payload->pull_request->user->html_url}\">@{$this->payload->pull_request->user->login}</a>\n\n";
$this->message .= " {$this->payload->pull_request->body}";
} elseif ($this->payload->action == "review_requested") {
$this->message .= "👨‍💻 <b>Pull Request Review Requested </b> - <a href=\"{$this->payload->pull_request->html_url}\">{$this->payload->repository->full_name}#{$this->payload->pull_request->number}</a>\n\n";
$this->message .= "<a href=\"{$this->payload->pull_request->html_url}\">{$this->payload->pull_request->title}</a> by <a href=\"{$this->payload->pull_request->user->html_url}\">@{$this->payload->pull_request->user->login}</a>\n\n";
$this->message .= " {$this->payload->pull_request->body}";
}
break;
case 'issue_comment':
$this->message .= "📬 <b>New comment </b> on <a href=\"{$this->payload->comment->html_url}\">{$this->payload->repository->full_name}#{$this->payload->issue->number}</a>\n\n";
$this->message .= "<a href=\"{$this->payload->comment->html_url}\">comment</a> by <a href=\"{$this->payload->comment->user->html_url}\">@{$this->payload->comment->user->login}</a>\n\n";
$this->message .= " {$this->payload->comment->body}";
break;
}
}*/

/**
* Send notify to telegram
*
Expand Down

0 comments on commit 9368aa1

Please sign in to comment.