Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo.GetOwner should be repo.LoadOwner #22963

Closed
yp05327 opened this issue Feb 18, 2023 · 0 comments · Fixed by #22967
Closed

repo.GetOwner should be repo.LoadOwner #22963

yp05327 opened this issue Feb 18, 2023 · 0 comments · Fixed by #22967
Labels
type/refactoring Existing code has been cleaned up. There should be no new functionality.

Comments

@yp05327
Copy link
Contributor

yp05327 commented Feb 18, 2023

Feature Description

I think the GetOwner here should be LoadOwner. Get means return something and Load means something is nil, we need to load it.
This func dosen't return anything, but the description of this func says GetOwner returns the repository owner

gitea/models/repo/repo.go

Lines 376 to 384 in 8bba7e3

// GetOwner returns the repository owner
func (repo *Repository) GetOwner(ctx context.Context) (err error) {
if repo.Owner != nil {
return nil
}
repo.Owner, err = user_model.GetUserByID(ctx, repo.OwnerID)
return err
}

In other places, the functions which do samething are called LoadOwner

func (p *Project) LoadOwner(ctx context.Context) (err error) {
if p.Owner != nil {
return nil
}
p.Owner, err = user_model.GetUserByID(ctx, p.OwnerID)
return err
}

gitea/models/admin/task.go

Lines 95 to 112 in 8bba7e3

func (task *Task) LoadOwner() error {
if task.Owner != nil {
return nil
}
var owner user_model.User
has, err := db.GetEngine(db.DefaultContext).ID(task.OwnerID).Get(&owner)
if err != nil {
return err
} else if !has {
return user_model.ErrUserNotExist{
UID: task.OwnerID,
}
}
task.Owner = &owner
return nil
}

Screenshots

No response

@yp05327 yp05327 added type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/proposal The new feature has not been accepted yet but needs to be discussed first. labels Feb 18, 2023
@lunny lunny added type/refactoring Existing code has been cleaned up. There should be no new functionality. and removed type/proposal The new feature has not been accepted yet but needs to be discussed first. type/feature Completely new functionality. Can only be merged if feature freeze is not active. labels Feb 18, 2023
lunny pushed a commit that referenced this issue Feb 18, 2023
Fixes #22963

---------

Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants