Handler for GitHub Webhooks
Go to file
Tiago Garcia 52ea711718
Add uninstaller
Signed-off-by: Tiago Garcia <tiago.rgarcia@ua.pt>
2024-07-19 15:54:12 +01:00
build Fix logging 2024-07-19 12:52:41 +01:00
include Fix logging 2024-07-19 12:52:41 +01:00
installer Add uninstaller 2024-07-19 15:54:12 +01:00
src Update Config 2024-07-19 15:48:14 +01:00
.gitignore Add installer 2024-07-19 15:29:19 +01:00
CMakeLists.txt Add installer 2024-07-19 15:29:19 +01:00
LICENSE Create LICENSE 2024-07-18 01:38:29 +01:00
README.md Add uninstaller 2024-07-19 15:54:12 +01:00

README.md

GitHub Webhook Handler

Simple C++ WebAPI to work with GitHub Webhooks

This application is a simple C++ WebAPI that listens for GitHub Webhooks and performs actions based on the received data and configuration.

Installation

Run the installation script to install the application:

curl -fsSL https://cdn.tiagorg.pt/gh-wh-handler/install.sh | sudo sh

You can uninstall the application using the following command:

curl -fsSL https://cdn.tiagorg.pt/gh-wh-handler/uninstall.sh | sudo sh

Run prebuilt binary

Head over to the Releases Page and download the desired binary.

Run the application using your configuration file:

/path/to/gh-wh-handler.<arch> /path/to/config.json /path/to/logs_dir

You can see the config file format below.

Install from source

Install the dependencies:

Build and install the application:

  1. Clone the repository:
git clone https://github.com/TiagoRG/gh-wh-handler.git
  1. Move to the build directory:
cd gh-wh-handler/build
  1. Run CMake:
cmake ..
  1. Build and install the application:
sudo make install

If you want to uninstall the application, you can run the following command:

sudo make uninstall

Usage

The application is running on a systemd service, which is both enabled and started after installation.

You can start, stop, restart, and check the status of the service using the following commands:

sudo systemctl start gh-wh-handler      # Start the service
sudo systemctl stop gh-wh-handler       # Stop the service
sudo systemctl restart gh-wh-handler    # Restart the service
sudo systemctl status gh-wh-handler     # Check the status of the service

You can also check the logs of the service using the following command:

journalctl -u gh-wh-handler

Configuration

As of now, the configuration menu is not yet implemented so you have to create the configuration file manually.

Config File

The configuration file can be found in /services/gh-wh-handler/config.json and has the following base format:

{
  "port": 65001,
  "tokens": {
    "owner/repo-name": "token"
  }
}

This configuration will then have more fields for each endpoint that you want to configure.

Note: Tokens are only required for private repositories.

Endpoints

Currently, the only endpoint for the application is /update-files, which is used to update the local files on every push as well as run post-update scripts.

/update-files

Webhook event: push

This endpoint allows the application to update specific files on the server when a push to a specific branch is made. This way, there's no need to manually update the files on the server or to pull the entire repository.

It also allows the application to run post-update scripts after the files are updated.

The configuration file must contain the update-files field, which is an object with the following format:

"update-files": {
  "owner/repo-name": {
    "branch": "main",
    "files": {
      "path/to/remote/file": "/path/to/local/file",
      "...": "..."
    },
    "post-update": [
      "post-update-command",
      "post-update-script",
      "..."
    ]
  }
}

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.