- Ref: forgejo/forgejo#6203 & forgejo/forgejo#5703 - Moved code around to be reusable, otherwise an straightforward implementation. - Added unit test. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6800 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>