Skip to content

Commit ef394de

Browse files
committed
Remove getPrivateReviewers and getPublicReviewer
These functions are not reusable and therefore should be folded back in to their calling function.
1 parent c83cc04 commit ef394de

File tree

1 file changed

+28
-46
lines changed

1 file changed

+28
-46
lines changed

models/repo.go

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -694,67 +694,49 @@ func (repo *Repository) GetAssignees() (_ []*User, err error) {
694694
return repo.getAssignees(x)
695695
}
696696

697-
func (repo *Repository) getReviewersPrivate(e Engine, doerID, posterID int64) (users []*User, err error) {
698-
users = make([]*User, 0, 20)
699-
700-
if err = e.
701-
SQL("SELECT * FROM `user` WHERE id in (SELECT user_id FROM `access` WHERE repo_id = ? AND mode >= ? AND user_id NOT IN ( ?, ?)) ORDER BY name",
702-
repo.ID, AccessModeRead,
703-
doerID, posterID).
704-
Find(&users); err != nil {
705-
return nil, err
706-
}
707-
708-
return users, nil
709-
}
710-
711-
func (repo *Repository) getReviewersPublic(e Engine, doerID, posterID int64) (_ []*User, err error) {
712-
713-
users := make([]*User, 0)
714-
715-
const SQLCmd = "SELECT * FROM `user` WHERE id IN ( " +
716-
"SELECT user_id FROM `access` WHERE repo_id = ? AND mode >= ? AND user_id NOT IN ( ?, ?) " +
717-
"UNION " +
718-
"SELECT user_id FROM `watch` WHERE repo_id = ? AND user_id NOT IN ( ?, ?) AND mode IN (?, ?) " +
719-
") ORDER BY name"
720-
721-
if err = e.
722-
SQL(SQLCmd,
723-
repo.ID, AccessModeRead, doerID, posterID,
724-
repo.ID, doerID, posterID, RepoWatchModeNormal, RepoWatchModeAuto).
725-
Find(&users); err != nil {
726-
return nil, err
727-
}
728-
729-
return users, nil
730-
}
731-
732697
func (repo *Repository) getReviewers(e Engine, doerID, posterID int64) ([]*User, error) {
698+
// Get the owner of the repository - this often already pre-cached and if so saves complexity for the following queries
733699
if err := repo.getOwner(e); err != nil {
734700
return nil, err
735701
}
736702

737-
var (
738-
users []*User
739-
err error
740-
)
703+
var users []*User
741704

742705
if repo.IsPrivate ||
743706
(repo.Owner.IsOrganization() && repo.Owner.Visibility == api.VisibleTypePrivate) {
744-
users, err = repo.getReviewersPrivate(x, doerID, posterID)
745-
} else {
746-
users, err = repo.getReviewersPublic(x, doerID, posterID)
707+
// This a private repository:
708+
// Anyone who can read the repository is a requestable reviewer
709+
if err := e.
710+
SQL("SELECT * FROM `user` WHERE id in (SELECT user_id FROM `access` WHERE repo_id = ? AND mode >= ? AND user_id NOT IN ( ?, ?)) ORDER BY name",
711+
repo.ID, AccessModeRead,
712+
doerID, posterID).
713+
Find(&users); err != nil {
714+
return nil, err
715+
}
716+
717+
return users, nil
747718
}
748-
if err != nil {
719+
720+
// This is a "public" repository:
721+
// Any user that has write access or who is a watcher can be requested to review
722+
if err := e.
723+
SQL("SELECT * FROM `user` WHERE id IN ( "+
724+
"SELECT user_id FROM `access` WHERE repo_id = ? AND mode >= ? AND user_id NOT IN ( ?, ?) "+
725+
"UNION "+
726+
"SELECT user_id FROM `watch` WHERE repo_id = ? AND user_id NOT IN ( ?, ?) AND mode IN (?, ?) "+
727+
") ORDER BY name",
728+
repo.ID, AccessModeRead, doerID, posterID,
729+
repo.ID, doerID, posterID, RepoWatchModeNormal, RepoWatchModeAuto).
730+
Find(&users); err != nil {
749731
return nil, err
750732
}
751733

752734
return users, nil
753735
}
754736

755-
// GetReviewers get all users can be requested to review
756-
// for private rpo , that return all users that have read access or higher to the repository.
757-
// but for public rpo, that return all users that have write access or higher to the repository,
737+
// GetReviewers get all users can be requested to review:
738+
// * for private repositories this returns all users that have read access or higher to the repository.
739+
// * for public repositories this returns all users that have write access or higher to the repository,
758740
// and all repo watchers.
759741
// TODO: may be we should hava a busy choice for users to block review request to them.
760742
func (repo *Repository) GetReviewers(doerID, posterID int64) ([]*User, error) {

0 commit comments

Comments
 (0)