The git events notifiers, you can implement it to handle all of your Git events happening at any time.
We use the Git webhook technology to handle all of the Git events, so we need some things for the implementation.
- Ngrok: to expose your HTTP over HTTPS to get access for the Get Webhooks as a payload URL.
- Composer: to manage the packages of our PHP project.
- PHP: to locally develop your own project in handling the Git event process.
First of all, open the terminal at the location of your project folder, and clone the repository.
git clone https://github.com/SaiZawMyint/git-notifier.gitAnd install the necessary packages, by running
cd git-notifier
composer installNow, we are ready to start our local development server.
php -S localhost:8080To test the notification, open your browser, and on the URL bar, enter the following URL and press enter
http://localhost:8080/test-notiYou will get the test notification message.(NOTE: You must enable system notification on your device. If you have blocked the notifications, the notification will not send to your device!)
We have done our local development, and now let's continue to configure the Git webhook.
As Git webhook payload URL, allows only HTTPS so we need to expose our local server to HTTPS. To do it we will use the Ngrok. If you have not installed the Ngrok on your device go to the download page here and install it.
Open the terminal and enter the following
ngrok http 8080You will get the log on the command like this
Session Status online
Account {{your ngrok account email}} (Plan: Free)
Version 3.3.1
Region Asia Pacific (ap)
Latency 45ms
Web Interface http://127.0.0.1:4040
Forwarding https://{{your-ngrok-custom-ips}}.ngrok-free.app -> http://localhost:8080
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00At the Forwarding sentence, copy the URL exposed by Ngrok. Now we get the exposed URL for our local development.
Let's start to configure our git webhook.
-
Go to your Git profile.
-
Choose the repository you want to implement the Git event.
-
Go to the settings page.
-
Click on Webhooks at the sidebar.
-
Add new Webhook.
-
At the payload URL, paste your ngrok URL that is exposed from your local server. (Don't forget to add the '/git' at the ent of the URL)
-
Scroll down and at the Which events would you like to trigger this webhook?, choose the Send me everything.
-
Click on Add webhooks button (You can skip other input after you have completed the above options)
Congratulations, we have done all of the implementation.
Make some event to the repository you have configured the webhook, like push, fork, giving stars, issues, pull request, etc... You will Get a notification every time an event happened on your repository.
As the project is to handle the Git event, you can use it when you want to notify the event of your Git repository. It's very useful when you have a development team and you want to know who has pushed to the repository or who has PR to the repository or other actions happening between your team development.
Hope this help you in your improvement or development with Git. :D



