aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authoryp053272023-02-18 21:11:03 +0900
committerGitHub2023-02-18 20:11:03 +0800
commitbd66fa586a0da58c4cf2f5f8390aef4bac9d0527 (patch)
tree0aa52def7fb8c81ca91a2b882261e9db6a7c174a /models
parent007d181bb51330c4c24e78c2f40a2e49cae45ed9 (diff)
Rename `repo.GetOwner` to `repo.LoadOwner` (#22967)
Fixes https://github.com/go-gitea/gitea/issues/22963 --------- Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
Diffstat (limited to 'models')
-rw-r--r--models/activities/action.go2
-rw-r--r--models/git/protected_branch.go4
-rw-r--r--models/issues/comment.go4
-rw-r--r--models/issues/issue.go2
-rw-r--r--models/issues/pull.go2
-rw-r--r--models/perm/access/access.go8
-rw-r--r--models/perm/access/access_test.go4
-rw-r--r--models/perm/access/repo_permission.go8
-rw-r--r--models/repo/repo.go8
-rw-r--r--models/repo/update.go2
-rw-r--r--models/repo/user_repo.go4
-rw-r--r--models/repo_collaboration_test.go2
12 files changed, 25 insertions, 25 deletions
diff --git a/models/activities/action.go b/models/activities/action.go
index 8e7492c00..2e845bf89 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 355a7464c..eef7e3935 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 36e7b8e78..a47dc7c15 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 e0dcf3d26..b1c7fdbf7 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 3f8b0bc7a..6a1dc3155 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 48ecf78a8..2d1b2daa6 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 bd828a1e9..79b131fe8 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 a6bf9b674..ee76e4820 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 e7ec93a22..dcffb63fd 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 loads owner user
+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 8dd109745..f4cb67bb8 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 0d5b8579e..cdb266e01 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 94c5ab529..95fb35fe6 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})