1
0
Fork 0
mirror of https://codeberg.org/Mo8it/git-webhook-client synced 2024-11-23 11:11:36 +00:00
No description
Find a file
2022-12-06 00:28:02 +01:00
migrations Run the command in an attached thread 2022-10-23 00:08:28 +02:00
src Add sending emails 2022-12-06 00:28:02 +01:00
templates Rename template 2022-11-12 16:16:33 +01:00
.gitignore Port to Axum 2022-12-05 22:28:43 +01:00
Cargo.toml Add sending emails 2022-12-06 00:28:02 +01:00
diesel.toml Added logs in a database 2022-10-11 20:39:10 +02:00
LICENSE.txt FromData 2022-10-10 13:52:42 +02:00
README.md Port to Axum 2022-12-05 22:28:43 +01:00
Rocket.toml Use template and replace expect with match 2022-10-21 04:54:57 +02:00

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:

  1. secret: The secret of the webhook.
  2. base_url: The base_url of the webhook client.
  3. hooks: List of webhooks.
  4. repo_url: Repository url.
  5. current_dir: The directory to run the command in.
  6. command: The command without any arguments.
  7. args: List of arguments separated by a comma.

Example configuration file:

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

  • Clone the repository.
  • Create the configuration file.
  • Run the following to initialize the database:
    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:

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!