|
2 | 2 | > v0.1 |
3 | 3 |
|
4 | 4 | ## Introduction |
5 | | -_TBD_ |
| 5 | +Welcome to this mini-project repository! |
| 6 | +The aim of this project is to provide **extensible**, **lightweight** and **easy to configure** webhook processor. |
| 7 | +This implementation allows extremely simple webhook event binding and their processing. |
| 8 | +Automate anything you want with a _single configuration file_. |
| 9 | + |
| 10 | +The implementation is highly modular and also allows straightforward implementation of custom Python handler scripts. |
6 | 11 |
|
7 | 12 | ## Downloading |
8 | | -_TBD_ |
| 13 | +The easiest way to start is to clone the repository locally and then run it using `pipenv`. |
| 14 | +```shell |
| 15 | +# clone the repository |
| 16 | +git clone https://github.com/dolejska-daniel/lightweight-git-deployment.git |
| 17 | +cd lightweight-git-deployment |
| 18 | + |
| 19 | +# create local configuration |
| 20 | +cp config/app.dist.yaml config/app.yaml |
| 21 | +cp config/logging.dist.yaml config/logging.yaml |
| 22 | + |
| 23 | +# install dependencies |
| 24 | +pipenv install |
| 25 | +``` |
| 26 | + |
| 27 | +After you have configured all the bindings in the `config/app.yaml` configuration file, start the application by: |
| 28 | +```shell |
| 29 | +./scripts/start.sh |
| 30 | +``` |
| 31 | + |
| 32 | +### Requirements |
| 33 | +This project requires [`Python >= 3.9`](https://www.python.org/downloads/). |
| 34 | +With [`pipenv`](https://pypi.org/project/pipenv/), the project should be working out-of-the-box. |
9 | 35 |
|
10 | 36 | ## Usage |
11 | | -_TBD_ |
| 37 | +The `bindings` key in `config/app.yaml` is of `list[Binding]` type. |
| 38 | + |
| 39 | +**`Binding`**<br> |
| 40 | +The `Binding`s are configured by providing corresponding **conditions** and **actions**. |
| 41 | +The structure is as follows: |
| 42 | + |
| 43 | +| Key | Type | Description | |
| 44 | +|--------------|-------------------|--------------------------------------------------------------------------| |
| 45 | +| `conditions` | `list[Condition]` | Binding conditions determining whether the actions should be run or not. | |
| 46 | +| `actions` | `list[Action]` | Binding actions to be run if conditions are met. | |
| 47 | + |
| 48 | +**`Condition`**<br> |
| 49 | +The `Condition` definition is of `dict[str, Any]` type. |
| 50 | +Its keys refer to fields of the received webhook event. |
| 51 | +Its values refer to the required values of the corresponding event field. |
| 52 | + |
| 53 | +```yaml |
| 54 | +- created: false |
| 55 | + ref: refs/heads/master |
| 56 | + repository.full_name: dolejska-daniel/lightweight-git-deployment |
| 57 | +- sender.id: 10078080 |
| 58 | + repository.full_name: dolejska-daniel/lightweight-git-deployment |
| 59 | +``` |
| 60 | +
|
| 61 | +This example defines two `Condition`s. |
| 62 | +If any one of the two is met, the actions are run. |
| 63 | +For the `Condition` to be met all its rules must evaluate to `true`. |
| 64 | +The example will run the binding's action iff: |
| 65 | + - the event is a commit push to repository `dolejska-daniel/lightweight-git-deployment` |
| 66 | + - the event is sent by user with id `10078080` to repository `dolejska-daniel/lightweight-git-deployment` |
| 67 | + |
| 68 | +**`Action`**<br> |
| 69 | +The `Action` object defines which actions are to be run iff the conditions were a match. |
| 70 | +The structure is as follows: |
| 71 | + |
| 72 | +| Key | Typ | Description | |
| 73 | +|----------|------------------|-------------------------------------------------------------------| |
| 74 | +| `call` | `str` | Defines which method from which module should be called. | |
| 75 | +| `args` | `list[Any]` | Defines positional arguments to be supplied to the called method. | |
| 76 | +| `kwargs` | `dict[str, Any]` | Defines keyword arguments to be supplied to the called method. | |
| 77 | + |
| 78 | +```yaml |
| 79 | +- call: plugin.git.pull |
| 80 | + args: |
| 81 | + - /opt/torscraper |
| 82 | + - origin |
| 83 | +- call: plugin.shell.command |
| 84 | + args: |
| 85 | + - make image |
| 86 | +``` |
| 87 | + |
| 88 | +This example defines two `Action`s. |
| 89 | +First action will run method `pull` in the `plugin.git` module. |
| 90 | +This method will perform a `git pull` from provided origin in the given repository. |
| 91 | +Then, the second action is run the same way. |
| 92 | +The method `plugin.shell.command` simply runs the provided command in a shell. |
| 93 | + |
| 94 | +### Supported Events |
| 95 | + |
| 96 | +#### GitHub Webhooks |
| 97 | +| Name | Description | |
| 98 | +|-----------|-------------| |
| 99 | +| `create` | [API Docs](https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#create) |
| 100 | +| `delete` | [API Docs](https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#delete) |
| 101 | +| `ping` | [API Docs](https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#ping) |
| 102 | +| `push` | [API Docs](https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#push) |
| 103 | +| `release` | [API Docs](https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#release) |
| 104 | + |
0 commit comments