diff options
author | JakobDev <jakobdev@gmx.de> | 2023-09-15 08:13:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-15 06:13:19 +0000 |
commit | c548dde205244a39a26ba98377c0f5cc11da7041 (patch) | |
tree | f9d9e1185609703e320ed07fd2ff3f95dbdcc230 /services/org | |
parent | f8a109440655b77e8554e1744e31bf52a7c63df7 (diff) | |
download | gitea-c548dde205244a39a26ba98377c0f5cc11da7041.tar.gz gitea-c548dde205244a39a26ba98377c0f5cc11da7041.zip |
More refactoring of `db.DefaultContext` (#27083)
Next step of #27065
Diffstat (limited to 'services/org')
-rw-r--r-- | services/org/repo.go | 6 | ||||
-rw-r--r-- | services/org/repo_test.go | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/services/org/repo.go b/services/org/repo.go index 0edbf2d464..78a829ef25 100644 --- a/services/org/repo.go +++ b/services/org/repo.go @@ -14,14 +14,14 @@ import ( ) // TeamAddRepository adds new repository to team of organization. -func TeamAddRepository(t *organization.Team, repo *repo_model.Repository) (err error) { +func TeamAddRepository(ctx context.Context, 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 organization.HasTeamRepo(db.DefaultContext, t.OrgID, t.ID, repo.ID) { + } else if organization.HasTeamRepo(ctx, t.OrgID, t.ID, repo.ID) { return nil } - return db.WithTx(db.DefaultContext, func(ctx context.Context) error { + return db.WithTx(ctx, func(ctx context.Context) error { return models.AddRepository(ctx, t, repo) }) } diff --git a/services/org/repo_test.go b/services/org/repo_test.go index 40b0d17077..68c64a01ab 100644 --- a/services/org/repo_test.go +++ b/services/org/repo_test.go @@ -6,6 +6,7 @@ package org import ( "testing" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" @@ -19,7 +20,7 @@ func TestTeam_AddRepository(t *testing.T) { testSuccess := func(teamID, repoID int64) { team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}) - assert.NoError(t, TeamAddRepository(team, repo)) + assert.NoError(t, TeamAddRepository(db.DefaultContext, team, repo)) unittest.AssertExistsAndLoadBean(t, &organization.TeamRepo{TeamID: teamID, RepoID: repoID}) unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID}, &repo_model.Repository{ID: repoID}) } @@ -28,6 +29,6 @@ func TestTeam_AddRepository(t *testing.T) { team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) - assert.Error(t, TeamAddRepository(team, repo)) + assert.Error(t, TeamAddRepository(db.DefaultContext, team, repo)) unittest.CheckConsistencyFor(t, &organization.Team{ID: 1}, &repo_model.Repository{ID: 1}) } |