mirror of
https://codeberg.org/Mo8it/git-webhook-client
synced 2024-10-18 07:22:39 +00:00
90 lines
2.7 KiB
Markdown
90 lines
2.7 KiB
Markdown
|
# Git Webhook Client
|
||
|
|
||
|
Git webhook client that runs commands after a webhook event and shows their output.
|
||
|
|
||
|
Currently, only Gitea is supported. If you want support for Gitlab or Github, then please open an issue.
|
||
|
|
||
|
## Features
|
||
|
|
||
|
- Verify the webhook event with a secret.
|
||
|
- Run a configured command to a specific repository on a webhook event.
|
||
|
- Save the output of the command.
|
||
|
- Show an output by visiting the url of the client.
|
||
|
- Supported configuration for multiple repositories.
|
||
|
- Written in Rust :D
|
||
|
|
||
|
## Getting started
|
||
|
|
||
|
### Requirements
|
||
|
|
||
|
- `cargo` to compile the source code.
|
||
|
- Development package for SQLite (`sqlite-devel` on Fedora)
|
||
|
|
||
|
### Configuration
|
||
|
|
||
|
The program looks for the configuration file configured with the environment variable `GWC_CONFIG_FILE` that contains the following:
|
||
|
|
||
|
<!-- TODO: Adjust to new config -->
|
||
|
|
||
|
1. `secret`: The secret of the webhook.
|
||
|
1. `base_url`: The base_url of the webhook client.
|
||
|
1. `hooks`: List of webhooks.
|
||
|
1. `repo_url`: Repository url.
|
||
|
1. `current_dir`: The directory to run the command in.
|
||
|
1. `command`: The command without any arguments.
|
||
|
1. `args`: List of arguments separated by a comma.
|
||
|
|
||
|
#### Example configuration file:
|
||
|
|
||
|
<!-- TODO: Adjust to new config -->
|
||
|
|
||
|
```yaml
|
||
|
secret: CHANGE_ME!
|
||
|
base_url: https://webhook.mo8it.com
|
||
|
|
||
|
hooks:
|
||
|
repo_url: https://codeberg.org/Mo8it/git-webhook-client
|
||
|
current_dir: .
|
||
|
command: ls
|
||
|
args: ["-l", "-a", "test_directory"]
|
||
|
```
|
||
|
|
||
|
#### First setup
|
||
|
|
||
|
<!-- TODO: Auto migration -->
|
||
|
|
||
|
- Clone the repository.
|
||
|
- Create the configuration file.
|
||
|
- Run the following to initialize the database:
|
||
|
```bash
|
||
|
cargo install diesel_cli --no-default-features --features sqlite
|
||
|
DATABASE_URL=PATH/TO/DATABASE/DIRECTORY/db.sqlite diesel_cli migration run
|
||
|
cargo build --release
|
||
|
```
|
||
|
|
||
|
#### Run
|
||
|
|
||
|
After running `cargo build --release`, the binary can be found in the directory `target/release/git-webhook-client`. To run it, you have to specify the environment variable `DATABASE_URL`:
|
||
|
|
||
|
```bash
|
||
|
DATABASE_URL=PATH/TO/DATABASE/DIRECTORY/db.sqlite target/release/git-webhook-client
|
||
|
```
|
||
|
|
||
|
#### Setup on the git server
|
||
|
|
||
|
Setup the webhook for the configured repositories on the git server. Don't forget to enter the same secret that you did specify in the configuration file.
|
||
|
|
||
|
#### Show output
|
||
|
|
||
|
After an event, the client responds with a URL that shows the log. The id in that URL is important and specific to this event.
|
||
|
|
||
|
If you want to see the last log, just visit the `base_url` from the configuration.
|
||
|
|
||
|
To see a specific log with an id, visit the URL: `base_url/?id=THE_ID_OF_AN_EVENT`.
|
||
|
|
||
|
You can specify a negative ID to see the last events. `id=-1` corresponds to the last log, `id=-2` corresponds to the log before it and so on.
|
||
|
|
||
|
## Note
|
||
|
|
||
|
This is my first Rust project and I am still learning. If you have any suggestions, just open an issue!
|