From 532ad160fab74afe0a78d364f52811511647d96c Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Sat, 18 Feb 2023 18:56:17 +0900 Subject: [PATCH 1/3] change GetOwner to LoadOwner --- models/activities/action.go | 2 +- models/git/protected_branch.go | 4 ++-- models/issues/comment.go | 4 ++-- models/issues/issue.go | 2 +- models/issues/pull.go | 2 +- models/perm/access/access.go | 8 ++++---- models/perm/access/access_test.go | 4 ++-- models/perm/access/repo_permission.go | 8 ++++---- models/repo/repo.go | 8 ++++---- models/repo/update.go | 2 +- models/repo/user_repo.go | 4 ++-- models/repo_collaboration_test.go | 2 +- modules/context/repo.go | 12 ++++++------ modules/doctor/misc.go | 2 +- modules/repository/collaborator_test.go | 2 +- modules/repository/create.go | 4 ++-- modules/repository/delete.go | 2 +- modules/test/context_tests.go | 2 +- routers/api/v1/repo/repo.go | 2 +- routers/api/v1/user/repo.go | 4 ++-- routers/web/repo/compare.go | 2 +- routers/web/repo/http.go | 4 ++-- routers/web/repo/issue.go | 4 ++-- routers/web/repo/pull.go | 8 ++++---- routers/web/repo/setting.go | 2 +- routers/web/repo/view.go | 4 ++-- services/convert/issue.go | 2 +- services/convert/repository.go | 2 +- services/pull/check.go | 4 ++-- services/pull/merge.go | 6 +++--- services/pull/temp_repo.go | 12 ++++++------ services/repository/review.go | 2 +- services/repository/transfer.go | 2 +- 33 files changed, 67 insertions(+), 67 deletions(-) diff --git a/models/activities/action.go b/models/activities/action.go index 8e7492c008f76..2e845bf89e660 100644 --- a/models/activities/action.go +++ b/models/activities/action.go @@ -534,7 +534,7 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error { repo = act.Repo // check repo owner exist. - if err := act.Repo.GetOwner(ctx); err != nil { + if err := act.Repo.LoadOwner(ctx); err != nil { return fmt.Errorf("can't get repo owner: %w", err) } } else if act.Repo == nil { diff --git a/models/git/protected_branch.go b/models/git/protected_branch.go index 355a7464c1fcc..eef7e3935af87 100644 --- a/models/git/protected_branch.go +++ b/models/git/protected_branch.go @@ -314,8 +314,8 @@ type WhitelistOptions struct { // This function also performs check if whitelist user and team's IDs have been changed // to avoid unnecessary whitelist delete and regenerate. func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) { - if err = repo.GetOwner(ctx); err != nil { - return fmt.Errorf("GetOwner: %v", err) + if err = repo.LoadOwner(ctx); err != nil { + return fmt.Errorf("LoadOwner: %v", err) } whitelist, err := updateUserWhitelist(ctx, repo, protectBranch.WhitelistUserIDs, opts.UserIDs) diff --git a/models/issues/comment.go b/models/issues/comment.go index 36e7b8e785e30..a47dc7c151340 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -620,7 +620,7 @@ func (c *Comment) LoadAssigneeUserAndTeam() error { return err } - if err = c.Issue.Repo.GetOwner(db.DefaultContext); err != nil { + if err = c.Issue.Repo.LoadOwner(db.DefaultContext); err != nil { return err } @@ -824,7 +824,7 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, return nil, err } - if err = opts.Repo.GetOwner(ctx); err != nil { + if err = opts.Repo.LoadOwner(ctx); err != nil { return nil, err } diff --git a/models/issues/issue.go b/models/issues/issue.go index e0dcf3d269ee0..b1c7fdbf7ed27 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -2099,7 +2099,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u resolved := make(map[string]bool, 10) var mentionTeams []string - if err := issue.Repo.GetOwner(ctx); err != nil { + if err := issue.Repo.LoadOwner(ctx); err != nil { return nil, err } diff --git a/models/issues/pull.go b/models/issues/pull.go index 3f8b0bc7acb6c..6a1dc31556247 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -498,7 +498,7 @@ func (pr *PullRequest) SetMerged(ctx context.Context) (bool, error) { return false, err } - if err := pr.Issue.Repo.GetOwner(ctx); err != nil { + if err := pr.Issue.Repo.LoadOwner(ctx); err != nil { return false, err } diff --git a/models/perm/access/access.go b/models/perm/access/access.go index 48ecf78a8c891..2d1b2daa62011 100644 --- a/models/perm/access/access.go +++ b/models/perm/access/access.go @@ -85,8 +85,8 @@ func updateUserAccess(accessMap map[int64]*userAccess, user *user_model.User, mo // FIXME: do cross-comparison so reduce deletions and additions to the minimum? func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap map[int64]*userAccess) (err error) { minMode := perm.AccessModeRead - if err := repo.GetOwner(ctx); err != nil { - return fmt.Errorf("GetOwner: %w", err) + if err := repo.LoadOwner(ctx); err != nil { + return fmt.Errorf("LoadOwner: %w", err) } // If the repo isn't private and isn't owned by a organization, @@ -143,7 +143,7 @@ func refreshCollaboratorAccesses(ctx context.Context, repoID int64, accessMap ma func RecalculateTeamAccesses(ctx context.Context, repo *repo_model.Repository, ignTeamID int64) (err error) { accessMap := make(map[int64]*userAccess, 20) - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return err } else if !repo.Owner.IsOrganization() { return fmt.Errorf("owner is not an organization: %d", repo.OwnerID) @@ -199,7 +199,7 @@ func RecalculateUserAccess(ctx context.Context, repo *repo_model.Repository, uid accessMode = collaborator.Mode } - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return err } else if repo.Owner.IsOrganization() { var teams []organization.Team diff --git a/models/perm/access/access_test.go b/models/perm/access/access_test.go index bd828a1e9d4e0..79b131fe89643 100644 --- a/models/perm/access/access_test.go +++ b/models/perm/access/access_test.go @@ -97,7 +97,7 @@ func TestRepository_RecalculateAccesses(t *testing.T) { // test with organization repo assert.NoError(t, unittest.PrepareTestDatabase()) repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}) - assert.NoError(t, repo1.GetOwner(db.DefaultContext)) + assert.NoError(t, repo1.LoadOwner(db.DefaultContext)) _, err := db.GetEngine(db.DefaultContext).Delete(&repo_model.Collaboration{UserID: 2, RepoID: 3}) assert.NoError(t, err) @@ -114,7 +114,7 @@ func TestRepository_RecalculateAccesses2(t *testing.T) { // test with non-organization repo assert.NoError(t, unittest.PrepareTestDatabase()) repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) - assert.NoError(t, repo1.GetOwner(db.DefaultContext)) + assert.NoError(t, repo1.LoadOwner(db.DefaultContext)) _, err := db.GetEngine(db.DefaultContext).Delete(&repo_model.Collaboration{UserID: 4, RepoID: 4}) assert.NoError(t, err) diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index a6bf9b6744a52..ee76e482001a1 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -175,7 +175,7 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use } } - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return } @@ -210,7 +210,7 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use return } - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return } if !repo.Owner.IsOrganization() { @@ -281,7 +281,7 @@ func IsUserRealRepoAdmin(repo *repo_model.Repository, user *user_model.User) (bo return true, nil } - if err := repo.GetOwner(db.DefaultContext); err != nil { + if err := repo.LoadOwner(db.DefaultContext); err != nil { return false, err } @@ -378,7 +378,7 @@ func HasAccess(ctx context.Context, userID int64, repo *repo_model.Repository) ( // getUsersWithAccessMode returns users that have at least given access mode to the repository. func getUsersWithAccessMode(ctx context.Context, repo *repo_model.Repository, mode perm_model.AccessMode) (_ []*user_model.User, err error) { - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return nil, err } diff --git a/models/repo/repo.go b/models/repo/repo.go index e7ec93a22a416..74df46e605472 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -237,7 +237,7 @@ func (repo *Repository) AfterLoad() { // LoadAttributes loads attributes of the repository. func (repo *Repository) LoadAttributes(ctx context.Context) error { // Load owner - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return fmt.Errorf("load owner: %w", err) } @@ -373,8 +373,8 @@ func (repo *Repository) GetUnit(ctx context.Context, tp unit.Type) (*RepoUnit, e return nil, ErrUnitTypeNotExist{tp} } -// GetOwner returns the repository owner -func (repo *Repository) GetOwner(ctx context.Context) (err error) { +// LoadOwner returns the repository owner +func (repo *Repository) LoadOwner(ctx context.Context) (err error) { if repo.Owner != nil { return nil } @@ -388,7 +388,7 @@ func (repo *Repository) GetOwner(ctx context.Context) (err error) { // It creates a fake object that contains error details // when error occurs. func (repo *Repository) MustOwner(ctx context.Context) *user_model.User { - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return &user_model.User{ Name: "error", FullName: err.Error(), diff --git a/models/repo/update.go b/models/repo/update.go index 8dd1097450e4a..f4cb67bb8f0e5 100644 --- a/models/repo/update.go +++ b/models/repo/update.go @@ -143,7 +143,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s return err } - if err := repo.GetOwner(db.DefaultContext); err != nil { + if err := repo.LoadOwner(db.DefaultContext); err != nil { return err } diff --git a/models/repo/user_repo.go b/models/repo/user_repo.go index 0d5b8579e01c1..cdb266e014a96 100644 --- a/models/repo/user_repo.go +++ b/models/repo/user_repo.go @@ -61,7 +61,7 @@ func GetWatchedRepos(ctx context.Context, userID int64, private bool, listOption // GetRepoAssignees returns all users that have write access and can be assigned to issues // of the repository, func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.User, err error) { - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return nil, err } @@ -111,7 +111,7 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us // TODO: may be we should have a busy choice for users to block review request to them. func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64) ([]*user_model.User, error) { // Get the owner of the repository - this often already pre-cached and if so saves complexity for the following queries - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return nil, err } diff --git a/models/repo_collaboration_test.go b/models/repo_collaboration_test.go index 94c5ab5291550..95fb35fe6d950 100644 --- a/models/repo_collaboration_test.go +++ b/models/repo_collaboration_test.go @@ -17,7 +17,7 @@ func TestRepository_DeleteCollaboration(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) - assert.NoError(t, repo.GetOwner(db.DefaultContext)) + assert.NoError(t, repo.LoadOwner(db.DefaultContext)) assert.NoError(t, DeleteCollaboration(repo, 4)) unittest.AssertNotExistsBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: 4}) diff --git a/modules/context/repo.go b/modules/context/repo.go index a38376ff460f1..e4ac65e9618c4 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -273,8 +273,8 @@ func RetrieveBaseRepo(ctx *Context, repo *repo_model.Repository) { } ctx.ServerError("GetBaseRepo", err) return - } else if err = repo.BaseRepo.GetOwner(ctx); err != nil { - ctx.ServerError("BaseRepo.GetOwner", err) + } else if err = repo.BaseRepo.LoadOwner(ctx); err != nil { + ctx.ServerError("BaseRepo.LoadOwner", err) return } } @@ -290,8 +290,8 @@ func RetrieveTemplateRepo(ctx *Context, repo *repo_model.Repository) { } ctx.ServerError("GetTemplateRepo", err) return - } else if err = templateRepo.GetOwner(ctx); err != nil { - ctx.ServerError("TemplateRepo.GetOwner", err) + } else if err = templateRepo.LoadOwner(ctx); err != nil { + ctx.ServerError("TemplateRepo.LoadOwner", err) return } @@ -356,8 +356,8 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) { func repoAssignment(ctx *Context, repo *repo_model.Repository) { var err error - if err = repo.GetOwner(ctx); err != nil { - ctx.ServerError("GetOwner", err) + if err = repo.LoadOwner(ctx); err != nil { + ctx.ServerError("LoadOwner", err) return } diff --git a/modules/doctor/misc.go b/modules/doctor/misc.go index 73df51390102a..f20b5b26d5484 100644 --- a/modules/doctor/misc.go +++ b/modules/doctor/misc.go @@ -141,7 +141,7 @@ func checkDaemonExport(ctx context.Context, logger log.Logger, autofix bool) err if owner, has := cache.Get(repo.OwnerID); has { repo.Owner = owner.(*user_model.User) } else { - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return err } cache.Add(repo.OwnerID, repo.Owner) diff --git a/modules/repository/collaborator_test.go b/modules/repository/collaborator_test.go index 6cf239d0eadae..c772806819329 100644 --- a/modules/repository/collaborator_test.go +++ b/modules/repository/collaborator_test.go @@ -23,7 +23,7 @@ func TestRepository_AddCollaborator(t *testing.T) { testSuccess := func(repoID, userID int64) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}) - assert.NoError(t, repo.GetOwner(db.DefaultContext)) + assert.NoError(t, repo.LoadOwner(db.DefaultContext)) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}) assert.NoError(t, AddCollaborator(db.DefaultContext, repo, user)) unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID}, &user_model.User{ID: userID}) diff --git a/modules/repository/create.go b/modules/repository/create.go index b9a72ad573743..7851ba0db92e8 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -335,7 +335,7 @@ func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error { // CheckDaemonExportOK creates/removes git-daemon-export-ok for git-daemon... func CheckDaemonExportOK(ctx context.Context, repo *repo_model.Repository) error { - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return err } @@ -379,7 +379,7 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili } if visibilityChanged { - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return fmt.Errorf("getOwner: %w", err) } if repo.Owner.IsOrganization() { diff --git a/modules/repository/delete.go b/modules/repository/delete.go index c7e05e666967d..01674db4a105a 100644 --- a/modules/repository/delete.go +++ b/modules/repository/delete.go @@ -16,7 +16,7 @@ func CanUserDelete(repo *repo_model.Repository, user *user_model.User) (bool, er return true, nil } - if err := repo.GetOwner(db.DefaultContext); err != nil { + if err := repo.LoadOwner(db.DefaultContext); err != nil { return false, err } diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go index d50f8efc755f9..6c434c201b53e 100644 --- a/modules/test/context_tests.go +++ b/modules/test/context_tests.go @@ -86,7 +86,7 @@ func LoadUser(t *testing.T, ctx *context.Context, userID int64) { // LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has // already been populated. func LoadGitRepo(t *testing.T, ctx *context.Context) { - assert.NoError(t, ctx.Repo.Repository.GetOwner(ctx)) + assert.NoError(t, ctx.Repo.Repository.LoadOwner(ctx)) var err error ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) assert.NoError(t, err) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index f5db45ffea06b..0395198e209a3 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -201,7 +201,7 @@ func Search(ctx *context.APIContext) { results := make([]*api.Repository, len(repos)) for i, repo := range repos { - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { ctx.JSON(http.StatusInternalServerError, api.SearchError{ OK: false, Error: err.Error(), diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index d566c072fba77..dcb14780a7291 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -119,8 +119,8 @@ func ListMyRepos(ctx *context.APIContext) { results := make([]*api.Repository, len(repos)) for i, repo := range repos { - if err = repo.GetOwner(ctx); err != nil { - ctx.Error(http.StatusInternalServerError, "GetOwner", err) + if err = repo.LoadOwner(ctx); err != nil { + ctx.Error(http.StatusInternalServerError, "LoadOwner", err) return } accessMode, err := access_model.AccessLevel(ctx, ctx.Doer, repo) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 5b6faf4d83bc5..4e40867de204c 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -279,7 +279,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { } return nil } - if err := ci.HeadRepo.GetOwner(ctx); err != nil { + if err := ci.HeadRepo.LoadOwner(ctx); err != nil { if user_model.IsErrUserNotExist(err) { ctx.NotFound("GetUserByName", nil) } else { diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index e82b94b9e847e..9d4ffccc6de56 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -146,8 +146,8 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { // don't allow anonymous pulls if organization is not public if isPublicPull { - if err := repo.GetOwner(ctx); err != nil { - ctx.ServerError("GetOwner", err) + if err := repo.LoadOwner(ctx); err != nil { + ctx.ServerError("LoadOwner", err) return } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 42dcfb382d8de..62565af50f35f 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -2157,8 +2157,8 @@ func UpdatePullReviewRequest(ctx *context.Context) { } if reviewID < 0 { // negative reviewIDs represent team requests - if err := issue.Repo.GetOwner(ctx); err != nil { - ctx.ServerError("issue.Repo.GetOwner", err) + if err := issue.Repo.LoadOwner(ctx); err != nil { + ctx.ServerError("issue.Repo.LoadOwner", err) return } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index ad17005d9049b..c7a59da8a8b15 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -119,8 +119,8 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository { return nil } - if err := forkRepo.GetOwner(ctx); err != nil { - ctx.ServerError("GetOwner", err) + if err := forkRepo.LoadOwner(ctx); err != nil { + ctx.ServerError("LoadOwner", err) return nil } @@ -1315,8 +1315,8 @@ func CleanUpPullRequest(ctx *context.Context) { } else if err = pr.LoadBaseRepo(ctx); err != nil { ctx.ServerError("LoadBaseRepo", err) return - } else if err = pr.HeadRepo.GetOwner(ctx); err != nil { - ctx.ServerError("HeadRepo.GetOwner", err) + } else if err = pr.HeadRepo.LoadOwner(ctx); err != nil { + ctx.ServerError("HeadRepo.LoadOwner", err) return } diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 436438c4366f0..387a917412f1e 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -650,7 +650,7 @@ func SettingsPost(ctx *context.Context) { ctx.Error(http.StatusNotFound) return } - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { ctx.ServerError("Convert Fork", err) return } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 99043e3ee7e3f..e3c61fa408bdb 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -1033,8 +1033,8 @@ func Forks(ctx *context.Context) { } for _, fork := range forks { - if err = fork.GetOwner(ctx); err != nil { - ctx.ServerError("GetOwner", err) + if err = fork.LoadOwner(ctx); err != nil { + ctx.ServerError("LoadOwner", err) return } } diff --git a/services/convert/issue.go b/services/convert/issue.go index 02f25e6e0e6a7..dccf2f3727845 100644 --- a/services/convert/issue.go +++ b/services/convert/issue.go @@ -32,7 +32,7 @@ func ToAPIIssue(ctx context.Context, issue *issues_model.Issue) *api.Issue { if err := issue.LoadRepo(ctx); err != nil { return &api.Issue{} } - if err := issue.Repo.GetOwner(ctx); err != nil { + if err := issue.Repo.LoadOwner(ctx); err != nil { return &api.Issue{} } diff --git a/services/convert/repository.go b/services/convert/repository.go index 5db68e837934d..fc965a94572af 100644 --- a/services/convert/repository.go +++ b/services/convert/repository.go @@ -100,7 +100,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc hasProjects = true } - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return nil } diff --git a/services/pull/check.go b/services/pull/check.go index ea5cccbdec8ef..310ea2e7147b7 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -261,8 +261,8 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool { // When the commit author is unknown set the BaseRepo owner as merger if merger == nil { if pr.BaseRepo.Owner == nil { - if err = pr.BaseRepo.GetOwner(ctx); err != nil { - log.Error("%-v BaseRepo.GetOwner: %v", pr, err) + if err = pr.BaseRepo.LoadOwner(ctx); err != nil { + log.Error("%-v BaseRepo.LoadOwner: %v", pr, err) return false } } diff --git a/services/pull/merge.go b/services/pull/merge.go index a3d69df8df048..3ac67d91b72f1 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -199,8 +199,8 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U if err := pr.Issue.LoadRepo(hammerCtx); err != nil { log.Error("LoadRepo for issue [%d]: %v", pr.ID, err) } - if err := pr.Issue.Repo.GetOwner(hammerCtx); err != nil { - log.Error("GetOwner for PR [%d]: %v", pr.ID, err) + if err := pr.Issue.Repo.LoadOwner(hammerCtx); err != nil { + log.Error("LoadOwner for PR [%d]: %v", pr.ID, err) } if wasAutoMerged { @@ -573,7 +573,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode } var headUser *user_model.User - err = pr.HeadRepo.GetOwner(ctx) + err = pr.HeadRepo.LoadOwner(ctx) if err != nil { if !user_model.IsErrUserNotExist(err) { log.Error("Can't find user: %d for head repository - %v", pr.HeadRepo.OwnerID, err) diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go index d49a15cea00ad..e0d6b4a158f6b 100644 --- a/services/pull/temp_repo.go +++ b/services/pull/temp_repo.go @@ -38,12 +38,12 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str return "", &repo_model.ErrRepoNotExist{ ID: pr.BaseRepoID, } - } else if err := pr.HeadRepo.GetOwner(ctx); err != nil { - log.Error("HeadRepo.GetOwner: %v", err) - return "", fmt.Errorf("HeadRepo.GetOwner: %w", err) - } else if err := pr.BaseRepo.GetOwner(ctx); err != nil { - log.Error("BaseRepo.GetOwner: %v", err) - return "", fmt.Errorf("BaseRepo.GetOwner: %w", err) + } else if err := pr.HeadRepo.LoadOwner(ctx); err != nil { + log.Error("HeadRepo.LoadOwner: %v", err) + return "", fmt.Errorf("HeadRepo.LoadOwner: %w", err) + } else if err := pr.BaseRepo.LoadOwner(ctx); err != nil { + log.Error("BaseRepo.LoadOwner: %v", err) + return "", fmt.Errorf("BaseRepo.LoadOwner: %w", err) } // Clone base repo. diff --git a/services/repository/review.go b/services/repository/review.go index d30d61ee06683..6b5f096053214 100644 --- a/services/repository/review.go +++ b/services/repository/review.go @@ -12,7 +12,7 @@ import ( // GetReviewerTeams get all teams can be requested to review func GetReviewerTeams(repo *repo_model.Repository) ([]*organization.Team, error) { - if err := repo.GetOwner(db.DefaultContext); err != nil { + if err := repo.LoadOwner(db.DefaultContext); err != nil { return nil, err } if !repo.Owner.IsOrganization() { diff --git a/services/repository/transfer.go b/services/repository/transfer.go index f4afb7e2dec28..8c167552da06f 100644 --- a/services/repository/transfer.go +++ b/services/repository/transfer.go @@ -26,7 +26,7 @@ var repoWorkingPool = sync.NewExclusivePool() // TransferOwnership transfers all corresponding setting from old user to new one. func TransferOwnership(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository, teams []*organization.Team) error { - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return err } for _, team := range teams { From 2838ddf030102df36a51472965badf7216a8fe18 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Sat, 18 Feb 2023 19:18:47 +0900 Subject: [PATCH 2/3] Update modules/repository/create.go Co-authored-by: Yarden Shoham --- modules/repository/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/repository/create.go b/modules/repository/create.go index 7851ba0db92e8..1704ea792cbf8 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -380,7 +380,7 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili if visibilityChanged { if err = repo.LoadOwner(ctx); err != nil { - return fmt.Errorf("getOwner: %w", err) + return fmt.Errorf("LoadOwner: %w", err) } if repo.Owner.IsOrganization() { // Organization repository need to recalculate access table when visibility is changed. From db72d22829a611d88f92148e1516bf3d1ac17676 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Sat, 18 Feb 2023 20:05:35 +0900 Subject: [PATCH 3/3] fix the description --- models/repo/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo/repo.go b/models/repo/repo.go index 74df46e605472..dcffb63fd1970 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -373,7 +373,7 @@ func (repo *Repository) GetUnit(ctx context.Context, tp unit.Type) (*RepoUnit, e return nil, ErrUnitTypeNotExist{tp} } -// LoadOwner returns the repository owner +// LoadOwner loads owner user func (repo *Repository) LoadOwner(ctx context.Context) (err error) { if repo.Owner != nil { return nil