code.gitea.io/gitea@v1.21.7/services/org/repo.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package org 5 6 import ( 7 "context" 8 "errors" 9 10 "code.gitea.io/gitea/models" 11 "code.gitea.io/gitea/models/db" 12 "code.gitea.io/gitea/models/organization" 13 repo_model "code.gitea.io/gitea/models/repo" 14 ) 15 16 // TeamAddRepository adds new repository to team of organization. 17 func TeamAddRepository(ctx context.Context, t *organization.Team, repo *repo_model.Repository) (err error) { 18 if repo.OwnerID != t.OrgID { 19 return errors.New("repository does not belong to organization") 20 } else if organization.HasTeamRepo(ctx, t.OrgID, t.ID, repo.ID) { 21 return nil 22 } 23 24 return db.WithTx(ctx, func(ctx context.Context) error { 25 return models.AddRepository(ctx, t, repo) 26 }) 27 }