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_
RobustART: Benchmarking Robustness on Architecture Design and Training Techniques

The first comprehensive Robustness investigation benchmark on large-scale dataset ImageNet regarding ARchitecture design and Training techniques towards diverse noises.

132 Dec 23, 2022
Official Pytorch implementation of paper "Reverse Engineering of Generative Models: Inferring Model Hyperparameters from Generated Images"

Reverse_Engineering_GMs Official Pytorch implementation of paper "Reverse Engineering of Generative Models: Inferring Model Hyperparameters from Gener

100 Dec 18, 2022
PPO Lagrangian in JAX

PPO Lagrangian in JAX This repository implements PPO in JAX. Implementation is tested on the safety-gym benchmark. Usage Install dependencies using th

Karush Suri 2 Sep 14, 2022
This repository contains the code for the CVPR 2021 paper "GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields"

GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields Project Page | Paper | Supplementary | Video | Slides | Blog | Talk If

1.1k Dec 30, 2022
Make Watson Assistant send messages to your Discord Server

Make Watson Assistant send messages to your Discord Server Prerequisites Sign up for an IBM Cloud account. Fill in the required information and press

1 Jan 10, 2022
This thesis is mainly concerned with state-space methods for a class of deep Gaussian process (DGP) regression problems

Doctoral dissertation of Zheng Zhao This thesis is mainly concerned with state-space methods for a class of deep Gaussian process (DGP) regression pro

Zheng Zhao 21 Nov 14, 2022
Numenta Platform for Intelligent Computing is an implementation of Hierarchical Temporal Memory (HTM), a theory of intelligence based strictly on the neuroscience of the neocortex.

NuPIC Numenta Platform for Intelligent Computing The Numenta Platform for Intelligent Computing (NuPIC) is a machine intelligence platform that implem

Numenta 6.3k Dec 30, 2022
The official code of "SCROLLS: Standardized CompaRison Over Long Language Sequences".

SCROLLS This repository contains the official code of the paper: "SCROLLS: Standardized CompaRison Over Long Language Sequences". Links Official Websi

TAU NLP Group 39 Dec 23, 2022
Matthew Colbrook 1 Apr 08, 2022
This example implements the end-to-end MLOps process using Vertex AI platform and Smart Analytics technology capabilities

MLOps with Vertex AI This example implements the end-to-end MLOps process using Vertex AI platform and Smart Analytics technology capabilities. The ex

Google Cloud Platform 238 Dec 21, 2022
Code for the paper "Offline Reinforcement Learning as One Big Sequence Modeling Problem"

Trajectory Transformer Code release for Offline Reinforcement Learning as One Big Sequence Modeling Problem. Installation All python dependencies are

Michael Janner 266 Dec 27, 2022
Implementation for Shape from Polarization for Complex Scenes in the Wild

sfp-wild Implementation for Shape from Polarization for Complex Scenes in the Wild project website | paper Code and dataset will be released soon. Int

Chenyang LEI 41 Dec 23, 2022
Model-based Reinforcement Learning Improves Autonomous Racing Performance

Racing Dreamer: Model-based versus Model-free Deep Reinforcement Learning for Autonomous Racing Cars In this work, we propose to learn a racing contro

Cyber Physical Systems - TU Wien 38 Dec 06, 2022
TensorFlow implementation for Bayesian Modeling and Uncertainty Quantification for Learning to Optimize: What, Why, and How

Bayesian Modeling and Uncertainty Quantification for Learning to Optimize: What, Why, and How TensorFlow implementation for Bayesian Modeling and Unce

Shen Lab at Texas A&M University 8 Sep 02, 2022
Automatically Build Multiple ML Models with a Single Line of Code. Created by Ram Seshadri. Collaborators Welcome. Permission Granted upon Request.

Auto-ViML Automatically Build Variant Interpretable ML models fast! Auto_ViML is pronounced "auto vimal" (autovimal logo created by Sanket Ghanmare) N

AutoViz and Auto_ViML 397 Dec 30, 2022
EfficientNetV2-with-TPU - Cifar-10 case study

EfficientNetV2-with-TPU EfficientNet EfficientNetV2 adalah jenis jaringan saraf convolutional yang memiliki kecepatan pelatihan lebih cepat dan efisie

Sultan syach 1 Dec 28, 2021
Public Code for NIPS submission SimiGrad: Fine-Grained Adaptive Batching for Large ScaleTraining using Gradient Similarity Measurement

Public code for NIPS submission "SimiGrad: Fine-Grained Adaptive Batching for Large Scale Training using Gradient Similarity Measurement" This repo co

Heyang Qin 0 Oct 13, 2021
The CLRS Algorithmic Reasoning Benchmark

Learning representations of algorithms is an emerging area of machine learning, seeking to bridge concepts from neural networks with classical algorithms.

DeepMind 251 Jan 05, 2023
Understanding and Improving Encoder Layer Fusion in Sequence-to-Sequence Learning (ICLR 2021)

Understanding and Improving Encoder Layer Fusion in Sequence-to-Sequence Learning (ICLR 2021) Citation Please cite as: @inproceedings{liu2020understan

Sunbow Liu 22 Nov 25, 2022
Simple and ready-to-use tutorials for TensorFlow

TensorFlow World To support maintaining and upgrading this project, please kindly consider Sponsoring the project developer. Any level of support is a

Amirsina Torfi 4.5k Dec 23, 2022