feat: configurable default units for mirrors (#7902)

Partial implementation of b1f42a0cdd

Docs update: https://codeberg.org/forgejo/docs/pulls/1197

Closes #6561
* issue author only provided a reason for the option for mirrors, and there's no known reason for implementing the same option for templates yet, but this change will not make it harder to add that separately.

Pull requests and Actions do not make sense for mirrors to have them, at least by default. Pull requests because changes will get overridden by upstream, Actions get triggered and are failing, filling the actions table in the DB with unwanted content, and there's a security concern, too.

## Testing

* log in to https://v12.next.forgejo.org
* migrate repository
    * example lightweight repo: https://codeberg.org/forgejo-contrib/delightful-forgejo
    * tick "This repository will be a mirror"
* verify that the repo doesn't have these tabs: Pull requests, Actions

Testing note: there's `models/unit/unit_test.go`, but I don't completely get how it works and was not able to append it with the new setting while keeping it working.

Co-authored-by: Zettat123 <zettat123@gmail.com>
Idea-by: lng2020

<!--start release-notes-assistant-->

## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- Features
  - [PR](https://codeberg.org/forgejo/forgejo/pulls/7902): <!--number 7902 --><!--line 0 --><!--description Y29uZmlndXJhYmxlIGRlZmF1bHQgdW5pdHMgZm9yIG1pcnJvcnM=-->configurable default units for mirrors<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7902
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: 0ko <0ko@noreply.codeberg.org>
Co-committed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
0ko 2025-06-03 08:12:29 +02:00 committed by Earl Warren
parent 374def9922
commit 9ecef99ab9
4 changed files with 37 additions and 4 deletions

View file

@ -69,8 +69,11 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
// insert units for repo
defaultUnits := unit.DefaultRepoUnits
if isFork {
switch {
case isFork:
defaultUnits = unit.DefaultForkRepoUnits
case repo.IsMirror:
defaultUnits = unit.DefaultMirrorRepoUnits
}
units := make([]repo_model.RepoUnit, 0, len(defaultUnits))
for _, tp := range defaultUnits {