2023-12-30 11:59:45 +00:00
# GitHub Webhook Handler
2023-12-30 12:06:34 +00:00
## Simple C++ WebAPI to work with GitHub Webhooks
2024-07-19 14:48:14 +00:00
This application is a simple C++ WebAPI that listens for GitHub Webhooks and performs actions based on the received data and configuration.
2023-12-30 12:06:34 +00:00
2024-07-19 14:48:14 +00:00
## Installation
2023-12-30 12:06:34 +00:00
2024-07-19 14:27:39 +00:00
### Use installation script (recommended)
Run the installation script to install the application:
```console
curl -fsSL https://cdn.tiagorg.pt/gh-wh-handler/install.sh | sudo sh
```
2024-07-19 14:54:12 +00:00
You can uninstall the application using the following command:
```console
curl -fsSL https://cdn.tiagorg.pt/gh-wh-handler/uninstall.sh | sudo sh
```
2024-07-14 21:32:17 +00:00
### Run prebuilt binary
Head over to the [Releases Page ](https://github.com/TiagoRG/gh-wh-handler/releases ) and download the desired binary.
Run the application using your configuration file:
```console
2024-07-19 14:48:14 +00:00
/path/to/gh-wh-handler.< arch > /path/to/config.json /path/to/logs_dir
2024-07-14 21:32:17 +00:00
```
You can see the config file format below.
2024-07-18 00:43:54 +00:00
### Install from source
2024-07-14 21:32:17 +00:00
2024-07-18 00:43:54 +00:00
#### Install the dependencies:
2023-12-30 16:19:05 +00:00
- [CrowCpp ](https://crowcpp.org/master/ )
- [nlohmann::json ](https://github.com/nlohmann/json )
2024-07-19 14:48:14 +00:00
#### Build and install the application:
2024-07-18 00:43:54 +00:00
1. Clone the repository:
2023-12-30 12:06:34 +00:00
```console
2024-07-18 00:43:54 +00:00
git clone https://github.com/TiagoRG/gh-wh-handler.git
2023-12-30 12:06:34 +00:00
```
2024-07-19 10:59:01 +00:00
2. Move to the build directory:
2024-07-18 00:43:54 +00:00
```console
2024-07-19 10:59:01 +00:00
cd gh-wh-handler/build
2024-07-18 00:43:54 +00:00
```
3. Run CMake:
```console
cmake ..
```
4. Build and install the application:
```console
sudo make install
```
2024-07-19 14:54:12 +00:00
If you want to uninstall the application, you can run the following command:
```console
sudo make uninstall
```
2024-07-19 14:48:14 +00:00
## Usage
2024-07-18 00:43:54 +00:00
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:
2023-12-30 12:06:34 +00:00
```console
2024-07-18 00:43:54 +00:00
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
2023-12-30 12:06:34 +00:00
```
2024-07-18 00:43:54 +00:00
You can also check the logs of the service using the following command:
```console
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.
2024-02-21 12:09:59 +00:00
2024-07-18 00:43:54 +00:00
### Config File
2023-12-30 12:06:34 +00:00
2024-07-19 14:48:14 +00:00
The configuration file can be found in `/services/gh-wh-handler/config.json` and has the following base format:
2023-12-30 12:06:34 +00:00
```json
{
2024-07-18 00:43:54 +00:00
"port": 65001,
"tokens": {
"owner/repo-name": "token"
}
2023-12-30 12:06:34 +00:00
}
```
2023-12-30 21:01:25 +00:00
2024-07-19 14:48:14 +00:00
This configuration will then have more fields for each endpoint that you want to configure.
Note: Tokens are only required for private repositories.
2024-07-18 00:43:54 +00:00
## Endpoints
2024-07-19 20:46:06 +00:00
### `/run-actions`
2024-07-19 14:48:14 +00:00
#### Webhook event: `push`
2024-07-19 20:46:06 +00:00
This endpoint allows the application to run specific actions when a push to a specific branch is made. This way, there's no need to manually run the actions on the server.
2024-07-19 14:48:14 +00:00
2024-07-19 20:46:06 +00:00
The configuration file must contain the `run-actions` field, which is an object with the following format:
2024-07-19 14:48:14 +00:00
```json
2024-07-19 20:46:06 +00:00
"run-actions": {
2024-07-19 14:48:14 +00:00
"owner/repo-name": {
"branch": "main",
2024-07-19 20:46:06 +00:00
"actions": [
{
"name": "action-name",
"command": "command-to-run"
}
2024-07-19 14:48:14 +00:00
]
}
}
```
2024-07-18 00:43:54 +00:00
2024-07-19 20:46:06 +00:00
### `/update-files`
2024-07-19 15:51:53 +00:00
#### Webhook event: `push`
2024-07-19 20:46:06 +00:00
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.
2024-07-19 15:51:53 +00:00
2024-07-19 20:46:06 +00:00
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:
2024-07-19 15:51:53 +00:00
```json
2024-07-19 20:46:06 +00:00
"update-files": {
2024-07-19 15:51:53 +00:00
"owner/repo-name": {
"branch": "main",
2024-07-19 20:46:06 +00:00
"files": {
"path/to/remote/file": "/path/to/local/file",
"...": "..."
},
"post-update": [
2024-07-19 15:51:53 +00:00
{
2024-07-19 20:46:06 +00:00
"name": "post-update-action-name",
"command": "command-to-run"
2024-07-19 15:51:53 +00:00
}
]
}
}
```
2024-07-19 18:56:51 +00:00
## Nginx Configuration
If you want to use Nginx as a reverse proxy for the application, you can use the following example configuration:
```nginx
server {
listen 80;
server_name services.example.com;
location /gh-wh-handler {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Front-End-Https on;
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 64;
proxy_buffering off;
proxy_redirect off;
proxy_max_temp_file_size 0;
rewrite /gh-wh-handler/(.*) /$1 break;
proxy_pass http://127.0.0.1:65001;
}
}
```
This way, you will be able to access the application using the URL `http://services.example.com/gh-wh-handler/end-point` .
2024-07-18 00:43:54 +00:00
## License
This project is licensed under the GNU General Public License v3.0 - see the [LICENSE ](LICENSE ) file for details.
2023-12-30 21:01:25 +00:00