Python script to remove issues/PRs and comments in Forgejo/Gitea from users defined in config file.
Go to file
Eric Geldmacher 83d34e4e09
Add ref to PR in README.md
2023-03-14 09:10:29 -05:00
.gitignore Initial commit 2023-03-01 15:57:18 +00:00
LICENSE Start building out moderate.py and supporting files. 2023-03-02 09:07:42 -06:00
README.md Add ref to PR in README.md 2023-03-14 09:10:29 -05:00
config.yml.example Cleanup config, fix user endtime when time is set. 2023-03-03 09:40:33 -06:00
moderate.py Cleanup config, fix user endtime when time is set. 2023-03-03 09:40:33 -06:00
requirements.txt Add pip requirments.txt 2023-03-03 09:52:56 -06:00

README.md

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.

Forgejo Issue | Forgejo PR

Quick start

This is a Proof of Concept. Some testing has been done, but it may not be fit for a production environment.

  1. Generate an Access Token for a user account that has admin access to the repositories that will be watched.

  2. Clone or download/extract repository and cd into the directory.

  3. Copy config.yml.example to config.yml

    All variables in the config.yml file can be overwritten with environmental variables. (Examples are given in the config.yml.example file)

  4. Edit config.yml and make sure to set at least base_url, api_token, and add at least one entry to orgs or repos, and at least one user to block_users

    If base_url or api_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.

  5. Set history to a time interval greater then your anticipated cron schedule.

  6. Run pip3 install -r requirements.txt

  7. 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.