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
Owner
ilu_vatar_
Computer Science student living in Europe
ilu_vatar_
Official code repository for A Simple Long-Tailed Rocognition Baseline via Vision-Language Model.

BALLAD This is the official code repository for A Simple Long-Tailed Rocognition Baseline via Vision-Language Model. Requirements Python3 Pytorch(1.7.

peng gao 42 Nov 26, 2022
Public repository created to store my custom-made tools for Just Dance (UbiArt Engine)

Woody's Just Dance Tools Public repository created to store my custom-made tools for Just Dance (UbiArt Engine) Development and updates Almost all of

Wodson de Andrade 8 Dec 24, 2022
Table-Extractor 表格抽取

(t)able-(ex)tractor 本项目旨在实现pdf表格抽取。 Models 版面分析模块(Yolo) 表格结构抽取(ResNet + Transformer) 文字识别模块(CRNN + CTC Loss) Acknowledgements TableMaster attention-i

2 Jan 15, 2022
wlad 2 Dec 19, 2022
A toolkit for document-level event extraction, containing some SOTA model implementations

❤️ A Toolkit for Document-level Event Extraction with & without Triggers Hi, there 👋 . Thanks for your stay in this repo. This project aims at buildi

Tong Zhu(朱桐) 159 Dec 22, 2022
TopFormer: Token Pyramid Transformer for Mobile Semantic Segmentation, CVPR2022

TopFormer: Token Pyramid Transformer for Mobile Semantic Segmentation Paper Links: TopFormer: Token Pyramid Transformer for Mobile Semantic Segmentati

Hust Visual Learning Team 253 Dec 21, 2022
The description of FMFCC-A (audio track of FMFCC) dataset and Challenge resluts.

FMFCC-A This project is the description of FMFCC-A (audio track of FMFCC) dataset and Challenge resluts. The FMFCC-A dataset is shared through BaiduCl

18 Dec 24, 2022
Code for "FPS-Net: A convolutional fusion network for large-scale LiDAR point cloud segmentation".

FPS-Net Code for "FPS-Net: A convolutional fusion network for large-scale LiDAR point cloud segmentation", accepted by ISPRS journal of Photogrammetry

15 Nov 30, 2022
Orchestrating Distributed Materials Acceleration Platform Tutorial

Orchestrating Distributed Materials Acceleration Platform Tutorial This tutorial for orchestrating distributed materials acceleration platform was pre

BIG-MAP 1 Jan 25, 2022
A PyTorch Toolbox for Face Recognition

FaceX-Zoo FaceX-Zoo is a PyTorch toolbox for face recognition. It provides a training module with various supervisory heads and backbones towards stat

JDAI-CV 1.6k Jan 06, 2023
Implementation of "Distribution Alignment: A Unified Framework for Long-tail Visual Recognition"(CVPR 2021)

Implementation of "Distribution Alignment: A Unified Framework for Long-tail Visual Recognition"(CVPR 2021)

105 Nov 07, 2022
Clairvoyance: a Unified, End-to-End AutoML Pipeline for Medical Time Series

Clairvoyance: A Pipeline Toolkit for Medical Time Series Authors: van der Schaar Lab This repository contains implementations of Clairvoyance: A Pipel

van_der_Schaar \LAB 89 Dec 07, 2022
Multi-Objective Loss Balancing for Physics-Informed Deep Learning

Multi-Objective Loss Balancing for Physics-Informed Deep Learning Code for ReLoBRaLo. Abstract Physics Informed Neural Networks (PINN) are algorithms

Rafael Bischof 16 Dec 12, 2022
Code for the tech report Toward Training at ImageNet Scale with Differential Privacy

Differentially private Imagenet training Code for the tech report Toward Training at ImageNet Scale with Differential Privacy by Alexey Kurakin, Steve

Google Research 29 Nov 03, 2022
Membership Inference Attack against Graph Neural Networks

MIA GNN Project Starter If you meet the version mismatch error for Lasagne library, please use following command to upgrade Lasagne library. pip insta

6 Nov 09, 2022
Official implementation for paper: A Latent Transformer for Disentangled Face Editing in Images and Videos.

A Latent Transformer for Disentangled Face Editing in Images and Videos Official implementation for paper: A Latent Transformer for Disentangled Face

InterDigital 108 Dec 09, 2022
PED: DETR for Crowd Pedestrian Detection

PED: DETR for Crowd Pedestrian Detection Code for PED: DETR For (Crowd) Pedestrian Detection Paper PED: DETR for Crowd Pedestrian Detection Installati

36 Sep 13, 2022
Unified learning approach for egocentric hand gesture recognition and fingertip detection

Unified Gesture Recognition and Fingertip Detection A unified convolutional neural network (CNN) algorithm for both hand gesture recognition and finge

Mohammad 227 Dec 25, 2022
Robotics with GPU computing

Robotics with GPU computing Cupoch is a library that implements rapid 3D data processing for robotics using CUDA. The goal of this library is to imple

Shirokuma 625 Jan 07, 2023
A python toolbox for predictive uncertainty quantification, calibration, metrics, and visualization

Website, Tutorials, and Docs    Uncertainty Toolbox A python toolbox for predictive uncertainty quantification, calibration, metrics, and visualizatio

Uncertainty Toolbox 1.4k Dec 28, 2022