1
1
mirror of https://github.com/go-gitea/gitea synced 2025-10-29 10:28:24 +00:00

Delete repos of org when purge delete user (#27273) (#27728)

Fixes https://codeberg.org/forgejo/forgejo/issues/1514

Backports #27273

---------

Co-authored-by: JakobDev <jakobdev@gmx.de>
This commit is contained in:
6543
2023-11-01 03:03:12 +01:00
committed by GitHub
parent 6ac2ade97d
commit 6637bbf510
14 changed files with 79 additions and 51 deletions

View File

@@ -425,3 +425,30 @@ func RemoveRepositoryFromTeam(ctx context.Context, t *organization.Team, repoID
return committer.Commit()
}
// DeleteOwnerRepositoriesDirectly calls DeleteRepositoryDirectly for all repos of the given owner
func DeleteOwnerRepositoriesDirectly(ctx context.Context, owner *user_model.User) error {
for {
repos, _, err := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
PageSize: repo_model.RepositoryListDefaultPageSize,
Page: 1,
},
Private: true,
OwnerID: owner.ID,
Actor: owner,
})
if err != nil {
return fmt.Errorf("GetUserRepositories: %w", err)
}
if len(repos) == 0 {
break
}
for _, repo := range repos {
if err := DeleteRepositoryDirectly(ctx, owner, owner.ID, repo.ID); err != nil {
return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %w", repo.Name, owner.Name, owner.ID, err)
}
}
}
return nil
}