Discord bot for notifying on github events

Overview

Git-Observer

Discord bot for notifying on github events

⚠️ This bot is meant to write messages to only one channel (implementing this for multiple projects/channels is a mess so...) ⚠️

⚠️ Even bigger warning: Sometime, I will do a nice installation script, but until then you'll have to follow the long installation process ⚠️

⚠️ I published this project because some friends wanted to use my bot for themselves, but I did not intend to do something generic. A lot of paths and other stuff were hard-coded (bad habit, I know...). So you'll have to change them yourselves, although I'll guide you through this process, don't worry. ⚠️

This project is meant to be installed on a linux server.

How does it work ?

Like this :

Loop #1
Event on your github repository >--git event-- ...
... ----> Github Hook Server >--webhook------- ...
... ----> nginx server >---local proxy pass--- ...
... ----> hook listener >-------write json on disk

Loop #2
discord bot script listener >--file content--- ...
... ----> webhook formatter >----printable---- ...
... ----> writing the pretty-msg to discord server

Installation

Since this project is split into two distinct parts (discord bot and webhook listener), the installation process is a bit long. But everything is pretty straightforward. First, please clone the repository :

git clone https://github.com/Nicolas-Reyland/Git-Observer
cd Git-Observer

Setting up the github webhooks listener

Setting up github webhooks in github

Setting up webhooks on your github repos is very simple! Please refer to one of these guides :

When adding your webhook, please select the following Content Type: application/json ⚠️ The webhook secret should be remembered; we will need it later. You can use something like "https://your-domain-or-ip-address/github-webhooks" for the payload url.

Installing the dependencies for the webhooks listener

The gh webhook listener runs on ruby, using a library called Sinatra :

sudo apt update
sudo apt-get install ruby-dev build-essential -y
sudo gem install sinatra --no-document # the '--no-document' is optional

Setting up the listener

Here, you have to make some choices.

# you should be in the Git-Observer repo dir
cp -r ./webhook-listener path-to-the-listenenr-repo # (you have to create it)
cd path-to-the-listenenr-repo # you can also stay inside the github repo and not create a new dir

You should see myapp.rb when typing ls -l. Now, please enter the following commands :

mkdir hook-dumps # this is your hook-dump directory (please remember this)
./update-gh-hook-ip-list # if this fails, it should not be fatal

Changing the contents of the ruby script

Please open the script myapp.rb in you favorite text editor (e.g. vim myapp.rb). Now, on line 17, you can change the GH_WH_LISTENER to the absolute path of the current directory. The result yould look like so: /home/nicolas/gh-wh-listener. The whole line should look like this:

file = File.open("/home/nicolas/gh-wh-listener/hook-dumps/#{date.to_i.to_s}.json", "w") {

Setting up the discord bot

Setting up the bot dir

Create the discord bot directory like this :

cp -r discord-bot your-discord-bot-dir # you can also stay inside the github repo

Creating a discord bot

Creating a discord bot is very straightforward. Please follow one of the following tutorials:

For the permissions, please refer to the content of this file (although selecting "administrator rights" is quicker).

Then, you should copy the discord bot token to the your-discord-bot-dir/discord-bot-token.txt (in this repo).

Installing the dependencies for the discord bot

You need python3.9 (or a higher version) and the discord.py dependecy.

sudo apt update
sudo apt install python3-dev
sudo apt install python3.9
pip install discord.py

Changing the bot scripts

In the your-discord-bot-dir/cogs/git-notifier.py file, change the following :

  • on line 11, add path to the hook-dumps directory, which was setup in the ruby listener installation step
  • on line 12, add the id of the discord channel which you want the bot to write messages in (as an int, not a str)

Creating the appropriate linux services

Fist of all, please copy the service files to the correct location :

# inside the repo dir
cp -i services/*.service /etc/systemd/system/

Changing the content of the ruby listener service file

Edit /etc/systemd/system/github-webhooks-sudoku-sinatra.service like so :

  • on line 8, edit the string and replace it by your github webhook secret (you chose this during the webhook creation in github)
  • on line 11, add your user name
  • on line 12, change the working directory to the github webhook listener
  • on line 13, add the full path to the myapp.rb script

Changing the content of the discord bot service file

Edit /etc/systemd/system/git-observer-bot.service like so :

  • on line 10, add your user name
  • on line 11, add the discord bot directory path
  • on line 12, add the full path to the bot.py script

Optional steps

If you wish these services to be started system boot time, you can enter these commands :

sudo systemctl enable github-webhook-listener.service
sudo systemctl enable git-observer-bot.service

Redirecting your requests to the ruby server

I will assume that you are using nginx on your linux server. The steps are not that different when using a different web server service. In you default web site script (/etc/nginx/sites-available/default.00 or something), add these line in the main server block :

location /github-webhooks {
  # you could restrict the ip addresses that access this to the github hooks url list
  # see webhook-listener/update-gh-hook-ip-list and webhook-listener/github-hooks-ip-list
  proxy_pass http://localhost:4567;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
}

Think to verify that your file valid :

sudo nginx -t

And reload the nginx service :

sudo systemctl reload nginx

Post-installation & Usage

To start the application, you can enter these commands :

sudo systemctl start github-webhook-listener.service
sudo systemctl start git-observer-bot.service

To modify the output of the bot, you can modify the your-discord-bot-dir/cogs/webhook_formatter.py file.

Todo:

  • local socket communication instead of new-file-detection method (makes it one-loop arch instead of 2-loop)
  • propoer, generic values instead of hard-coded ones
  • can write to multiple channels, one per repository
  • installation script
  • remove the nginx redirection -> directly listen to webhooks in the ruby script
You might also like...
Forecasting for knowable future events using Bayesian informative priors (forecasting with judgmental-adjustment).
Forecasting for knowable future events using Bayesian informative priors (forecasting with judgmental-adjustment).

What is judgyprophet? judgyprophet is a Bayesian forecasting algorithm based on Prophet, that enables forecasting while using information known by the

Web-interface + rest API for classification and regression (https://jeff1evesque.github.io/machine-learning.docs)
Web-interface + rest API for classification and regression (https://jeff1evesque.github.io/machine-learning.docs)

Machine Learning This project provides a web-interface, as well as a programmatic-api for various machine learning algorithms. Supported algorithms: S

Code for: https://berkeleyautomation.github.io/bags/

DeformableRavens Code for the paper Learning to Rearrange Deformable Cables, Fabrics, and Bags with Goal-Conditioned Transporter Networks. Here is the

git《Beta R-CNN: Looking into Pedestrian Detection from Another Perspective》(NeurIPS 2020) GitHub:[fig3]
git《Beta R-CNN: Looking into Pedestrian Detection from Another Perspective》(NeurIPS 2020) GitHub:[fig3]

Beta R-CNN: Looking into Pedestrian Detection from Another Perspective This is the pytorch implementation of our paper "[Beta R-CNN: Looking into Pede

git《Learning Pairwise Inter-Plane Relations for Piecewise Planar Reconstruction》(ECCV 2020) GitHub:

Learning Pairwise Inter-Plane Relations for Piecewise Planar Reconstruction Code for the ECCV 2020 paper by Yiming Qian and Yasutaka Furukawa Getting

git《Commonsense Knowledge Base Completion with Structural and Semantic Context》(AAAI 2020) GitHub: [fig1]
git《Commonsense Knowledge Base Completion with Structural and Semantic Context》(AAAI 2020) GitHub: [fig1]

Commonsense Knowledge Base Completion with Structural and Semantic Context Code for the paper Commonsense Knowledge Base Completion with Structural an

git《Tangent Space Backpropogation for 3D Transformation Groups》(CVPR 2021) GitHub:1]
git《Tangent Space Backpropogation for 3D Transformation Groups》(CVPR 2021) GitHub:1]

LieTorch: Tangent Space Backpropagation Introduction The LieTorch library generalizes PyTorch to 3D transformation groups. Just as torch.Tensor is a m

git《Self-Attention Attribution: Interpreting Information Interactions Inside Transformer》(AAAI 2021) GitHub:

Self-Attention Attribution This repository contains the implementation for AAAI-2021 paper Self-Attention Attribution: Interpreting Information Intera

git《Investigating Loss Functions for Extreme Super-Resolution》(CVPR 2020) GitHub:

Investigating Loss Functions for Extreme Super-Resolution NTIRE 2020 Perceptual Extreme Super-Resolution Submission. Our method ranked first and secon

Owner
ilu_vatar_
Computer Science student living in Europe
ilu_vatar_
Discord bot-CTFD-Thread-Parser - Discord bot CTFD-Thread-Parser

Discord bot CTFD-Thread-Parser Description: This tools is used to create automat

null 15 Mar 22, 2022
git git《Transformer Meets Tracker: Exploiting Temporal Context for Robust Visual Tracking》(CVPR 2021) GitHub:git2] 《Masksembles for Uncertainty Estimation》(CVPR 2021) GitHub:git3]

Transformer Meets Tracker: Exploiting Temporal Context for Robust Visual Tracking Ning Wang, Wengang Zhou, Jie Wang, and Houqiang Li Accepted by CVPR

NingWang 236 Dec 22, 2022
Code and datasets for the paper "Combining Events and Frames using Recurrent Asynchronous Multimodal Networks for Monocular Depth Prediction" (RA-L, 2021)

Combining Events and Frames using Recurrent Asynchronous Multimodal Networks for Monocular Depth Prediction This is the code for the paper Combining E

Robotics and Perception Group 69 Dec 26, 2022
CAUSE: Causality from AttribUtions on Sequence of Events

CAUSE: Causality from AttribUtions on Sequence of Events

Wei Zhang 21 Dec 1, 2022
HeatNet is a python package that provides tools to build, train and evaluate neural networks designed to predict extreme heat wave events globally on daily to subseasonal timescales.

HeatNet HeatNet is a python package that provides tools to build, train and evaluate neural networks designed to predict extreme heat wave events glob

Google Research 6 Jul 7, 2022
Reporting and Visualization for Hazardous Events

Reporting and Visualization for Hazardous Events

Jv Kyle Eclarin 2 Oct 3, 2021
NeoPlay is the project dedicated to ESport events.

NeoPlay is the project dedicated to ESport events. On this platform users can participate in tournaments with prize pools as well as create their own tournaments.

null 3 Dec 18, 2021
Space-event-trace - Tracing service for spaceteam events

space-event-trace Tracing service for TU Wien Spaceteam events. This service is

TU Wien Space Team 2 Jan 4, 2022
Python library to receive live stream events like comments and gifts in realtime from TikTok LIVE.

TikTokLive A python library to connect to and read events from TikTok's LIVE service A python library to receive and decode livestream events such as

Isaac Kogan 277 Dec 23, 2022
Face and Pose detector that emits MQTT events when a face or human body is detected and not detected.

Face Detect MQTT Face or Pose detector that emits MQTT events when a face or human body is detected and not detected. I built this as an alternative t

Jacob Morris 38 Oct 21, 2022