2020-07-17 13:26:35 +00:00
|
|
|
# Kibicara Contribution HowTo
|
|
|
|
|
2020-07-05 16:54:50 +00:00
|
|
|
|
|
|
|
## Setup Development Environment
|
|
|
|
|
2023-03-18 11:52:52 +00:00
|
|
|
### General
|
|
|
|
|
|
|
|
1. Install `python>=3.10` and development packages
|
|
|
|
(`apt install python3-dev g++` on Ubuntu)
|
|
|
|
2. Run `./setup.sh`
|
|
|
|
|
2020-09-05 23:48:58 +00:00
|
|
|
### Backend
|
|
|
|
|
2023-03-18 11:52:52 +00:00
|
|
|
0. `cd backend`
|
|
|
|
1. Activate your dev environment with `source .venv/bin/activate`
|
|
|
|
2. Install with `pip install .`
|
2023-03-18 17:16:57 +00:00
|
|
|
3. Create a config file: `echo "production = 0" > kibicara.conf`
|
2020-07-05 16:54:50 +00:00
|
|
|
|
2020-09-11 17:45:44 +00:00
|
|
|
#### Cheatsheet
|
2020-09-06 18:40:57 +00:00
|
|
|
|
2020-09-11 17:45:44 +00:00
|
|
|
- Install Kibicara with `pip install .`
|
2023-03-18 17:16:57 +00:00
|
|
|
- Execute Kibicara with `kibicara -f kibicara.conf`
|
|
|
|
(verbose: `kibicara -vvv -f kibicara.conf`)
|
2020-09-11 17:45:44 +00:00
|
|
|
- Interact with Swagger REST-API Documentation: `http://localhost:8000/api/docs`
|
2020-09-06 18:40:57 +00:00
|
|
|
- Test and stylecheck with `tox`
|
2023-03-18 11:52:52 +00:00
|
|
|
- Fix style issues with `black -S src tests`
|
2020-09-06 18:40:57 +00:00
|
|
|
|
2020-09-05 23:48:58 +00:00
|
|
|
### Frontend
|
|
|
|
|
|
|
|
1. Install node.js (e.g. via
|
|
|
|
[nvm](https://github.com/nvm-sh/nvm#installation-and-update))
|
|
|
|
2. `cd kibicara-frontend`
|
|
|
|
3. Install the dependencies with `npm i`
|
|
|
|
4. Install Angular with `npm i -g @angular/cli`
|
2020-09-11 17:45:44 +00:00
|
|
|
5. Turn off production mode if you have not already (see above in backend).
|
2020-09-05 23:48:58 +00:00
|
|
|
6. Start the backend in a different terminal
|
2020-09-11 17:45:44 +00:00
|
|
|
7. To serve and open the application, run `ng s -o`. The application will open
|
2020-09-05 23:48:58 +00:00
|
|
|
under [http://127.0.0.1:4200](http://127.0.0.1:4200).
|
|
|
|
|
2020-09-11 17:45:44 +00:00
|
|
|
### Creating an account
|
|
|
|
|
|
|
|
#### Without local mailserver setup
|
|
|
|
|
|
|
|
1. Start the server with `kibicara -vvv`.
|
|
|
|
2. Got to `http://localhost:8000/api/docs`. Use the `POST /api/admin/register` endpoint to create an account (minimal password size is 8).
|
|
|
|
3. Check the log output for a line that contains a link with the token:
|
|
|
|
```
|
|
|
|
<sometimestamp> kibicara.webapi.admin http://127.0.0.1:4200/confirm?token=<copythistoken>
|
|
|
|
```
|
|
|
|
4. Paste the token into the `POST /api/admin/confirm/{register_token}` endpoint at `http://localhost:8000/api/docs`.
|
|
|
|
5. Done! Try to log in with the `Authorize` button on the page or use the frontend
|
|
|
|
|
|
|
|
#### With local mailserver (e.g. openSMTPd)
|
|
|
|
|
|
|
|
1. Install the opensmtpd package and start it.
|
|
|
|
2. The mails should be usually delivered in `~/Maildir`. Use your unix username as
|
|
|
|
email address and register via frontend or manually at `http://localhost:8000/api/docs`.
|
|
|
|
|
|
|
|
|
2020-07-17 13:26:35 +00:00
|
|
|
## Contribution Guidelines
|
|
|
|
### Branches
|
2020-07-05 16:54:50 +00:00
|
|
|
|
|
|
|
- **Development:** The development branch is used to add new features.
|
|
|
|
- Only rebase of feature branches is allowed.
|
2023-03-18 13:50:15 +00:00
|
|
|
- On Release a release tag will be created
|
2020-07-05 16:54:50 +00:00
|
|
|
- **Feature-Branches:**
|
2020-07-05 17:55:33 +00:00
|
|
|
- A feature branch will be used to develop a feature.
|
2020-07-05 16:54:50 +00:00
|
|
|
- It belongs to one developer only and force push is allowed.
|
|
|
|
- A rebase onto development is necessary to merge the feature. Code reviews
|
|
|
|
are encouraged.
|
|
|
|
|
2020-07-17 13:26:35 +00:00
|
|
|
### Write Tests
|
2020-07-05 16:54:50 +00:00
|
|
|
|
2020-07-05 17:55:33 +00:00
|
|
|
We use [pytest](https://docs.pytest.org/en/stable/) as a test engine. It is
|
2020-07-05 16:54:50 +00:00
|
|
|
executed by `tox`, so you need to run `tox` on the command line to run the tests.
|
|
|
|
|
2020-07-17 13:26:35 +00:00
|
|
|
### Commit Messages
|
2020-07-05 16:54:50 +00:00
|
|
|
|
|
|
|
Commits should define small components. Please write your commits with the
|
2020-07-05 17:55:33 +00:00
|
|
|
following pattern:
|
2020-07-05 16:54:50 +00:00
|
|
|
|
|
|
|
`[core] Add censor for filtering messages #1312`
|
|
|
|
|
2020-07-06 20:31:32 +00:00
|
|
|
You can use these tags:
|
|
|
|
|
2020-07-05 16:54:50 +00:00
|
|
|
- [core] Feature for Kibicara core
|
|
|
|
- [frontend] Feature for Kibicara frontend
|
2020-07-06 20:31:32 +00:00
|
|
|
- [$platform] Feature for platforms, e.g.
|
2020-07-06 20:25:17 +00:00
|
|
|
- [twitter]
|
|
|
|
- [telegram]
|
|
|
|
- [email]
|
|
|
|
- ...
|
2020-07-05 16:54:50 +00:00
|
|
|
- [tests] Tests
|
2020-07-07 09:43:07 +00:00
|
|
|
- [doc] Documentation
|
2020-07-05 16:54:50 +00:00
|
|
|
- [misc] e.g. github action files
|
|
|
|
- #\d+ if commit is related to specific issues or merge requests
|
|
|
|
|
2020-07-06 20:31:32 +00:00
|
|
|
Don't use tags which are not listed here. Don't start your commit message with
|
|
|
|
lower case. Commit messages which do not fulfill these guidelines will not be
|
|
|
|
merged into the `development` branch.
|
|
|
|
|
2020-07-17 13:26:35 +00:00
|
|
|
### Comments
|
2020-07-05 16:54:50 +00:00
|
|
|
|
2020-07-17 13:26:35 +00:00
|
|
|
#### Python
|
2020-07-05 16:54:50 +00:00
|
|
|
|
|
|
|
We use pdoc3, which takes prose and comments automatically from the docstrings
|
|
|
|
in the repository.
|
|
|
|
|
2020-07-17 13:26:35 +00:00
|
|
|
Use [google style](https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings)
|
2020-07-05 16:54:50 +00:00
|
|
|
comments to secure correct display of your docstrings.
|
|
|
|
|
2020-07-05 17:55:33 +00:00
|
|
|
Please don't leave trailing whitespace or empty lines at the end of your files.
|
2020-07-05 17:01:37 +00:00
|
|
|
|
2020-07-17 13:26:35 +00:00
|
|
|
### Merge Requests
|
2020-07-05 16:54:50 +00:00
|
|
|
|
|
|
|
The main development team does not need to make merge requests.
|
|
|
|
|
|
|
|
If you open a merge request, please include a description which explains the
|
|
|
|
improvement.
|
|
|
|
|
2020-07-17 13:26:35 +00:00
|
|
|
#### Code reviews
|
2020-07-05 16:54:50 +00:00
|
|
|
|
2020-07-05 17:55:33 +00:00
|
|
|
Before a merge request gets rebased onto and merged into `development`, at
|
|
|
|
least one person has to approve it; this also increases the number of people
|
|
|
|
who know the code. So please request a review from someone from the core
|
|
|
|
development team.
|
2020-07-05 16:54:50 +00:00
|
|
|
|
2020-07-17 13:26:35 +00:00
|
|
|
|
|
|
|
## How to implement a new Platform/Social Network
|
2020-07-05 16:54:50 +00:00
|
|
|
|
|
|
|
### tl;dr
|
|
|
|
|
|
|
|
1. Implement the following modules in `platforms/<your-platform>/`:
|
|
|
|
- `bot.py`
|
|
|
|
- `model.py`
|
|
|
|
- `webapi.py`
|
|
|
|
2. Import your bot in `kibicara/webapi/__init__.py`.
|
2023-03-18 12:49:04 +00:00
|
|
|
3. Generate the FastAPI stuff
|
|
|
|
4. Generate the angular components for the kibicara-frontend from the FastAPI stuff
|
2020-07-05 16:54:50 +00:00
|
|
|
|
|
|
|
### Explanation
|
|
|
|
|
2020-07-05 17:55:33 +00:00
|
|
|
In `kibicara/platforms/<your-platform>/bot.py`, you write the functions through
|
|
|
|
which the platform asks the social network for new messages, and publishes
|
|
|
|
messages to the social network. You need to inherit the bot from the `Censor`
|
2020-07-05 16:54:50 +00:00
|
|
|
class at `kibicara/platformapi.py`.
|
|
|
|
|
2020-07-05 17:55:33 +00:00
|
|
|
In `kibicara/platforms/<your-platform>/model.py`, you define a database layout.
|
2020-07-05 16:54:50 +00:00
|
|
|
You will probably need to store the following things:
|
|
|
|
|
|
|
|
* authentication credentials,
|
|
|
|
* timestamps/IDs of the last seen message,
|
2020-07-05 17:23:43 +00:00
|
|
|
* recipients if the social network doesn't post publicly,
|
2020-07-05 16:54:50 +00:00
|
|
|
* platform-specific settings
|
|
|
|
* anything else your platform needs
|
|
|
|
|
2020-07-05 17:55:33 +00:00
|
|
|
In `kibicara/platforms/<your-platform>/webapi.py`, you can define HTTP routes.
|
2020-07-05 16:54:50 +00:00
|
|
|
You will need them to:
|
|
|
|
|
|
|
|
* let admins authenticate to the social network in the kibicara web interface
|
2020-07-05 17:55:33 +00:00
|
|
|
* update platform-specific settings
|
2020-07-05 16:54:50 +00:00
|
|
|
|
|
|
|
To run the platform, you need to import the bot in
|
|
|
|
`kibicara/webapi/__init__.py`.
|
2020-07-17 13:26:35 +00:00
|
|
|
|
|
|
|
### Acceptance criteria for bots (Checklist)
|
|
|
|
|
|
|
|
A bot should have at least this functionality:
|
|
|
|
|
|
|
|
- Kibicara REST API (hood admins):
|
|
|
|
- Endpoint for creating a bot associated with a hood
|
|
|
|
- Endpoint for deleting a bot associated with a hood
|
|
|
|
- Endpoint for updating a bot associated with a hood by id
|
|
|
|
(_The update endpoint may be optional if it does not provide any
|
|
|
|
additional benefit to delete and create.
|
|
|
|
An example where it does provide additional benefit is when there is
|
|
|
|
a database which holds state like user ids in telegram. Then deleting the bot
|
|
|
|
would also delete the user ids which would stop the bot from working._)
|
|
|
|
- Endpoint for getting the bot configuration by id
|
|
|
|
- Endpoint for starting and enabling a created bot by id
|
|
|
|
- Endpoint for stopping and disabling a created bot by id
|
|
|
|
- Endpoint for getting the status of a bot (INSTANTIATED, RUNNING, STOPPED)
|
|
|
|
- Endpoint for getting all bots of a hood
|
|
|
|
|
|
|
|
- Bot functionality (user):
|
|
|
|
- Possibility for a user to subscribe to the bot on their platform
|
|
|
|
- e.g. Twitter itself already covers this by their follow/unfollow button
|
|
|
|
- e.g. Telegram /start command
|
|
|
|
- e.g. E-Mail REST Endpoint for entering and confirming an email
|
|
|
|
- Possibility for a user to unsubscribe to the bot on their platform
|
|
|
|
- e.g. Twitter itself already covers this by their follow/unfollow button
|
|
|
|
- e.g. Telegram /stop command
|
|
|
|
- e.g. E-Mail REST Endpoint for removing an email by token
|
|
|
|
- Possibility for a user to send a message to the bot that gets broadcasted
|
|
|
|
- e.g. Twitter via mentions or direct message
|
|
|
|
- e.g. Telegram via direct message to the bot
|
|
|
|
- e.g. E-Mail via e-mail to a specified address
|
|
|
|
- Possibility for a user to get bot messages
|
|
|
|
- e.g. Twitter via posts or retweets
|
|
|
|
- e.g. Telegram via direct message from the bot
|
|
|
|
- e.g. E-Mail via e-mail to the user's address
|
2023-03-18 12:49:04 +00:00
|
|
|
|
|
|
|
- Web Interface (hood admins)
|