Skip to content

repo.GetOwner should be repo.LoadOwner #22963

Closed
@yp05327

Description

@yp05327

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/refactoringExisting code has been cleaned up. There should be no new functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions