Branch protection: Possibility to not use whitelist but allow anyone with write access (#9055)
* Possibility to not use whitelist but allow anyone with write access
* fix existing test
* rename migration function
* Try to give a better name for migration step
* Clear settings if higher level setting is not set
* Move official reviews to db instead of counting approvals each time
* migration
* fix
* fix migration
* fix migration
* Remove NOT NULL from EnableWhitelist as migration isn't possible
* Fix migration, reviews are connected to issues.
* Fix SQL query issues in GetReviewersByPullID.
* Simplify function GetReviewersByIssueID
* Handle reviewers that has been deleted
* Ensure reviews for test is in a well defined order
* Only clear and set official reviews when it is an approve or reject.
if_,err:=sess.Exec("UPDATE `protected_branch` SET `can_push` = `enable_whitelist`");err!=nil{
returnerr
}
if_,err:=sess.Exec("UPDATE `protected_branch` SET `enable_approvals_whitelist` = ? WHERE `required_approvals` > ?",true,0);err!=nil{
returnerr
}
varpageSizeint64=20
qresult,err:=sess.QueryInterface("SELECT max(id) as max_id FROM issue")
iferr!=nil{
returnerr
}
vartotalIssuesint64
totalIssues,ok:=qresult[0]["max_id"].(int64)
if!ok{
// If there are no issues at all we ignore it
returnnil
}
totalPages:=totalIssues/pageSize
// Find latest review of each user in each pull request, and set official field if appropriate
reviews:=[]*models.Review{}
varpageint64
forpage=0;page<=totalPages;page++{
iferr:=sess.SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id > ? AND issue_id <= ? AND type in (?, ?) GROUP BY issue_id, reviewer_id)",
Where("review.issue_id = ? AND (review.type = ? OR review.type = ?)",
pullID,ReviewTypeApprove,ReviewTypeReject).
GroupBy("`user`.id, review.type").
OrderBy("review_updated_unix DESC").
Find(&irs)
sess:=x.NewSession()
defersess.Close()
iferr:=sess.Begin();err!=nil{
returnnil,err
}
// We need to group our results by user id _and_ review type, otherwise the query fails when using postgresql.
// But becaus we're doing this, we need to manually filter out multiple reviews of different types by the
// same person because we only want to show the newest review grouped by user. Thats why we're using a map here.
issueReviewers=[]*PullReviewersWithType{}
usersInArray:=make(map[int64]bool)
for_,ir:=rangeirs{
if!usersInArray[ir.ID]{
issueReviewers=append(issueReviewers,ir)
usersInArray[ir.ID]=true
// Get latest review of each reviwer, sorted in order they were made
iferr:=sess.SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id = ? AND type in (?, ?) GROUP BY issue_id, reviewer_id) ORDER BY review.updated_unix ASC",
@ -1398,7 +1402,9 @@ settings.protect_check_status_contexts = Enable Status Check
settings.protect_check_status_contexts_desc=Require status checks to pass before merging Choose which status checks must pass before branches can be merged into a branch that matches this rule. When enabled, commits must first be pushed to another branch, then merged or pushed directly to a branch that matches this rule after status checks have passed. If no contexts are selected, the last commit must be successful regardless of context.
settings.protect_check_status_contexts_list=Status checks found in the last week for this repository
settings.protect_required_approvals_desc=Allow only to merge pull request with enough positive reviews of whitelisted users or teams.
settings.protect_required_approvals_desc=Allow only to merge pull request with enough positive reviews.
settings.protect_approvals_whitelist_enabled=Restrict approvals to whitelisted users or teams
settings.protect_approvals_whitelist_enabled_desc=Only reviews from whitelisted users or teams will count to the required approvals. Without approval whitelist, reviews from anyone with write access count to the required approvals.