Skip to content

Commit

Permalink
Merge branch 'cslant:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit authored Jan 25, 2024
2 parents e07b896 + e4e5241 commit 53cdd78
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 31 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

Here you can see the full list of changes between each Telegram Git Notifier release.

## v1.3.6 - 2024-01-25

### What's Changed

* feat: add request_verify fro `Client Request` to work correctly on window and linux by @LuongTienThinh in https://github.com/cslant/telegram-git-notifier/pull/38

### New Contributors

* @LuongTienThinh made their first contribution in https://github.com/cslant/telegram-git-notifier/pull/38

**Full Changelog**: https://github.com/cslant/telegram-git-notifier/compare/v1.3.5...v1.3.6

## v1.3.5 - 2023-12-03

### ✨ New Features:
Expand Down
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Telegram Git Notifier
# Telegram Git Notifier Core Package

This package provides the ability to integrate the Telegram messaging service and GitHub and GitLab.
With this package,
Expand All @@ -9,20 +9,21 @@ and manage customization through messages and buttons on Telegram.
<img alt="Telegram git notifier core" src="https://github.com/cslant/telegram-git-notifier/assets/35853002/d731d731-3c32-40a7-80d2-b079d7f1de6c" />
</p>

![License](https://img.shields.io/github/license/cslant/telegram-git-notifier.svg?style=flat-square)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/cslant/telegram-git-notifier.svg?style=flat-square)](https://packagist.org/cslant/telegram-git-notifier)
[![Total Downloads](https://img.shields.io/packagist/dt/cslant/telegram-git-notifier.svg?style=flat-square)](https://packagist.org/packages/cslant/telegram-git-notifier)
![Test Status](https://img.shields.io/github/actions/workflow/status/cslant/telegram-git-notifier/setup_test.yml?label=tests&branch=main)
![Code Style Status](https://img.shields.io/github/actions/workflow/status/cslant/telegram-git-notifier/php-cs-fixer.yml?label=code%20style&branch=main)
[![StyleCI](https://styleci.io/repos/683908657/shield)](https://styleci.io/repos/683908657)
[![Quality Score](https://img.shields.io/scrutinizer/g/cslant/telegram-git-notifier.svg?style=flat-square)](https://scrutinizer-ci.com/g/cslant/telegram-git-notifier)
[![Maintainability](https://api.codeclimate.com/v1/badges/b6f16164d55809d0918e/maintainability)](https://codeclimate.com/github/cslant/telegram-git-notifier/maintainability)
<p align="center">
<a href="#"><img src="https://img.shields.io/github/license/cslant/telegram-git-notifier.svg?style=flat-square" alt="License"></a>
<a href="https://packagist.org/cslant/telegram-git-notifier"><img src="https://img.shields.io/packagist/v/cslant/telegram-git-notifier.svg?style=flat-square" alt="Latest Version on Packagist"></a>
<a href="https://packagist.org/packages/cslant/telegram-git-notifier"><img src="https://img.shields.io/packagist/dt/cslant/telegram-git-notifier.svg?style=flat-square" alt="Total Downloads"></a>
<a href="https://github.com/cslant/telegram-git-notifier/actions/workflows/setup_test.yml"><img src="https://img.shields.io/github/actions/workflow/status/cslant/telegram-git-notifier/setup_test.yml?label=tests&branch=main" alt="Test Status"></a>
<a href="https://github.com/cslant/telegram-git-notifier/actions/workflows/php-cs-fixer.yml"><img src="https://img.shields.io/github/actions/workflow/status/cslant/telegram-git-notifier/php-cs-fixer.yml?label=code%20style&branch=main" alt="Code Style Status"></a>
<a href="https://scrutinizer-ci.com/g/cslant/telegram-git-notifier"><img src="https://img.shields.io/scrutinizer/g/cslant/telegram-git-notifier.svg?style=flat-square" alt="Quality Score"></a>
<a href="https://codeclimate.com/github/cslant/telegram-git-notifier/maintainability"><img src="https://api.codeclimate.com/v1/badges/b6f16164d55809d0918e/maintainability" alt="Maintainability"></a>
</p>

## 📋 Requirements

- PHP ^8.1
- Composer
- Telegram Bot
- [Composer](https://getcomposer.org/)
- [Telegram Bot](https://core.telegram.org/api)

## 🔧 Installation

Expand All @@ -37,3 +38,11 @@ composer require cslant/telegram-git-notifier
```bash
composer test
```

## 📖 Official Documentation

Please see the [Telegram Git Notifier Documentation](https://docs.cslant.com/telegram-git-notifier/) for more information.

## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.
2 changes: 2 additions & 0 deletions config/tg-notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
'url' => $_ENV['TGN_APP_URL'] ?? 'http://localhost:3000',

'timezone' => $_ENV['TIMEZONE'] ?? 'Asia/Ho_Chi_Minh',

'request_verify' => $_ENV['TGN_REQUEST_VERIFY'] ?? false,
],

'bot' => [
Expand Down
7 changes: 5 additions & 2 deletions src/Structures/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ public function sendNotify(string $message = null, array $options = []): bool
$url = 'https://api.telegram.org/bot' . config('telegram-git-notifier.bot.token') . '/sendMessage';

try {
$response = $this->client->request('POST', $url, [
$options = [
'form_params' => $queryParams,
]);
'verify' => config('telegram-git-notifier.app.request_verify'),
];

$response = $this->client->request('POST', $url, $options);

if ($response->getStatusCode() === 200) {
return true;
Expand Down
20 changes: 16 additions & 4 deletions src/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ public function setUrl(string $url): void
public function setWebhook(): string
{
$url = "https://api.telegram.org/bot{$this->token}/setWebhook?url={$this->url}";
$options = [
'verify' => config('telegram-git-notifier.app.request_verify'),
];

try {
$response = $this->client->request('GET', $url);
$response = $this->client->request('GET', $url, $options);

return $response->getBody()->getContents();
} catch (GuzzleException) {
Expand All @@ -46,9 +49,12 @@ public function setWebhook(): string
public function deleteWebHook(): string
{
$url = "https://api.telegram.org/bot{$this->token}/deleteWebhook";
$options = [
'verify' => config('telegram-git-notifier.app.request_verify'),
];

try {
$response = $this->client->request('GET', $url);
$response = $this->client->request('GET', $url, $options);

return $response->getBody()->getContents();
} catch (GuzzleException) {
Expand All @@ -59,9 +65,12 @@ public function deleteWebHook(): string
public function getWebHookInfo(): string
{
$url = "https://api.telegram.org/bot{$this->token}/getWebhookInfo";
$options = [
'verify' => config('telegram-git-notifier.app.request_verify'),
];

try {
$response = $this->client->request('GET', $url);
$response = $this->client->request('GET', $url, $options);

return $response->getBody()->getContents();
} catch (GuzzleException) {
Expand All @@ -72,9 +81,12 @@ public function getWebHookInfo(): string
public function getUpdates(): string
{
$url = "https://api.telegram.org/bot{$this->token}/getUpdates";
$options = [
'verify' => config('telegram-git-notifier.app.request_verify'),
];

try {
$response = $this->client->request('GET', $url);
$response = $this->client->request('GET', $url, $options);

return $response->getBody()->getContents();
} catch (GuzzleException) {
Expand Down
13 changes: 7 additions & 6 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@

it('platform can be set for event with platform file', function () {
$this->bot->setPlatFormForEvent('gitlab', 'storage/json/tgn/gitlab-events.json');
expect($this->bot->event->platform)->toBe('gitlab');
expect($this->bot->event->getPlatformFile())->toBe('storage/json/tgn/gitlab-events.json');
expect($this->bot->event->platform)->toBe('gitlab')
->and($this->bot->event->getPlatformFile())
->toBe('storage/json/tgn/gitlab-events.json');
});

it('can get json config for event - github', function () {
$this->bot->setPlatFormForEvent();
expect($this->bot->event->getEventConfig())->toBeArray();
expect($this->bot->event->getEventConfig())->toHaveKey('issue_comment');
expect($this->bot->event->getEventConfig())->toBeArray()
->and($this->bot->event->getEventConfig())->toHaveKey('issue_comment');
});

it('can get json config for event - gitlab', function () {
$this->bot->setPlatFormForEvent('gitlab', 'storage/json/tgn/gitlab-events.json');
expect($this->bot->event->getEventConfig())->toBeArray();
expect($this->bot->event->getEventConfig())->toHaveKey('tag_push');
expect($this->bot->event->getEventConfig())->toBeArray()
->and($this->bot->event->getEventConfig())->toHaveKey('tag_push');
});

it('setting file is valid', function () {
Expand Down
19 changes: 11 additions & 8 deletions tests/NotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@

it('validates that the event files exist', function () {
$this->nofitier->setPlatFormForEvent('gitlab', 'storage/json/tgn/gitlab-events.json');
expect($this->nofitier->event->getEventConfig())->toBeArray();
expect($this->nofitier->event->getEventConfig())->toHaveKey('tag_push');
expect($this->nofitier->event->getEventConfig())->toBeArray()
->and($this->nofitier->event->getEventConfig())->toHaveKey('tag_push');

$this->nofitier->setPlatFormForEvent('github', 'storage/json/tgn/github-events.json');
expect($this->nofitier->event->getEventConfig())->toBeArray();
expect($this->nofitier->event->getEventConfig())->toHaveKey('issue_comment');
expect($this->nofitier->event->getEventConfig())->toBeArray()
->and($this->nofitier->event->getEventConfig())
->toHaveKey('issue_comment');
});

it('can parse notification chat IDs', function () {
$chatThreadMapping = $this->nofitier->parseNotifyChatIds('-1201937489183;-1008168942527:46,2');
expect($chatThreadMapping)->toBeArray();
expect($chatThreadMapping)->toHaveKey('-1008168942527');
expect($chatThreadMapping['-1008168942527'])->toBeArray();
expect($chatThreadMapping['-1008168942527'])->toBe([0 => '46', 1 => '2']);
expect($chatThreadMapping)->toBeArray()
->and($chatThreadMapping)->toHaveKey('-1008168942527')
->and($chatThreadMapping['-1008168942527'])->toBeArray()
->and($chatThreadMapping['-1008168942527'])->toBe([
0 => '46', 1 => '2',
]);
});

0 comments on commit 53cdd78

Please sign in to comment.