2.3 KiB
Forgejo/Gitea Moderation Script
Currently Forgejo/Gitea does not offer the ability for users or organizations protect their repositories from unwanted interactions from other users (while leaving repos open for other contributions) other then manually deleting issues/PRs and comments.
This script allows you to automate what you can do by defining a list of organizations and repositories to protect, and a list of users to block. It will then delete any issues/PRs created or comments made by a block user on a protected repository.
Quick start
This is a Proof of Concept. Some testing has been done, but it may not be fit for a production environment.
-
Generate an Access Token for a user account that has admin access to the repositories that will be watched.
-
Clone or download/extract repository and cd into the directory.
-
Copy
config.yml.example
toconfig.yml
All variables in the
config.yml
file can be overwritten with environmental variables. (Examples are given in theconfig.yml.example
file) -
Edit
config.yml
and make sure to set at leastbase_url
,api_token
, and add at least one entry toorgs
orrepos
, and at least one user toblock_users
If
base_url
orapi_token
are left unset the script will exit with an error.
If there are no repos to watch or users to block the script will exit without an error. -
Set
history
to a time interval greater then your anticipated cron schedule. -
Run
pip3 install -r requirements.txt
-
Run
python3 moderate.py
Limitation
This script is limited by what is possible with the API.
- Can not stop a blocked user from following.
- Can not stop a blocked user from watching a repository.
- Can not remove a star given by a blocked user.
- Can not remove a reaction to issue/PR or comment from blocked user.
Possible Improvements
The script is mostly designed to be run by a cron job. Changes could be made to have it watch for notifications. This might reduce API calls, and allow it to be run as more of a service.
- Reject repository transfers from blocked users
- Remove API token owner as collaborator of blocked users repository.