mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 10:18:38 +00:00
Move some files into models' sub packages (#20262)
* Move some files into models' sub packages * Move functions * merge main branch * Fix check * fix check * Fix some tests * Fix lint * Fix lint * Revert lint changes * Fix error comments * Fix lint Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
@@ -25,12 +25,12 @@ import (
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func addRepository(ctx context.Context, t *organization.Team, repo *repo_model.Repository) (err error) {
|
||||
func AddRepository(ctx context.Context, t *organization.Team, repo *repo_model.Repository) (err error) {
|
||||
if err = organization.AddTeamRepo(ctx, t.OrgID, t.ID, repo.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = db.GetEngine(ctx).Incr("num_repos").ID(t.ID).Update(new(organization.Team)); err != nil {
|
||||
if err = organization.IncrTeamRepoNum(ctx, t.ID); err != nil {
|
||||
return fmt.Errorf("update team: %v", err)
|
||||
}
|
||||
|
||||
@@ -58,16 +58,15 @@ func addRepository(ctx context.Context, t *organization.Team, repo *repo_model.R
|
||||
// addAllRepositories adds all repositories to the team.
|
||||
// If the team already has some repositories they will be left unchanged.
|
||||
func addAllRepositories(ctx context.Context, t *organization.Team) error {
|
||||
var orgRepos []repo_model.Repository
|
||||
e := db.GetEngine(ctx)
|
||||
if err := e.Where("owner_id = ?", t.OrgID).Find(&orgRepos); err != nil {
|
||||
orgRepos, err := organization.GetOrgRepositories(ctx, t.OrgID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get org repos: %v", err)
|
||||
}
|
||||
|
||||
for _, repo := range orgRepos {
|
||||
if !organization.HasTeamRepo(ctx, t.OrgID, t.ID, repo.ID) {
|
||||
if err := addRepository(ctx, t, &repo); err != nil {
|
||||
return fmt.Errorf("addRepository: %v", err)
|
||||
if err := AddRepository(ctx, t, repo); err != nil {
|
||||
return fmt.Errorf("AddRepository: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,27 +89,6 @@ func AddAllRepositories(t *organization.Team) (err error) {
|
||||
return committer.Commit()
|
||||
}
|
||||
|
||||
// AddRepository adds new repository to team of organization.
|
||||
func AddRepository(t *organization.Team, repo *repo_model.Repository) (err error) {
|
||||
if repo.OwnerID != t.OrgID {
|
||||
return errors.New("Repository does not belong to organization")
|
||||
} else if HasRepository(t, repo.ID) {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx, committer, err := db.TxContext()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer committer.Close()
|
||||
|
||||
if err = addRepository(ctx, t, repo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
}
|
||||
|
||||
// RemoveAllRepositories removes all repositories from team and recalculates access
|
||||
func RemoveAllRepositories(t *organization.Team) (err error) {
|
||||
if t.IncludesAllRepositories {
|
||||
|
Reference in New Issue
Block a user