-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Show review labels in the pull request lists #9274
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
Changes from 9 commits
d9f1bbf
4ff5406
46b9e29
8236a04
6686bd7
3761e06
582d7ef
d723929
9a6f4a8
f670132
3c16eea
3f93cfe
d3657fd
deca4a8
4f792ec
fbd4c09
64b47d5
b3ef97e
01bd93c
f84ce89
eea70d5
6577c95
d97dc25
c63d0a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"github.com/unknwon/com" | ||
"github.com/unknwon/i18n" | ||
) | ||
|
||
var pullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength) | ||
|
@@ -176,6 +177,39 @@ func (pr *PullRequest) loadProtectedBranch(e Engine) (err error) { | |
return | ||
} | ||
|
||
func (pr *PullRequest) requiredApprovals() int64 { | ||
if pr.ProtectedBranch == nil { | ||
if err := pr.loadProtectedBranch(x); err != nil { | ||
log.Error("Error loading ProtectedBranch", err) | ||
} | ||
} | ||
if pr.ProtectedBranch != nil { | ||
return pr.ProtectedBranch.RequiredApprovals | ||
} | ||
return 0 | ||
} | ||
|
||
// RequiresApproval returns true if this pull request requires approval, otherwise returns false | ||
func (pr *PullRequest) RequiresApproval() bool { | ||
return pr.requiredApprovals() > 0 | ||
} | ||
|
||
// GetReviewLabel returns the formatted review label with counter for the review of this pull request | ||
func (pr *PullRequest) GetReviewLabel(lang string) string { | ||
if pr.RequiresApproval() { | ||
rejections := pr.ProtectedBranch.GetRejectedReviewsCount(pr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO we should display # of changes requested and approvals. That would solve the problem of whether the change requests are blocking or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's incomplete information. The PR can have 17 approvals and 1 change request. Should it show "1 changes requested" or "17 people approved this"? I think both. |
||
if pr.ProtectedBranch.GetRejectedReviewsCount(pr) > 0 { | ||
oscarcosta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return i18n.Tr(lang, "repo.pulls.review_rejected", rejections) | ||
oscarcosta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
approvals := pr.ProtectedBranch.GetGrantedApprovalsCount(pr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that a PR that has been repeatedly approved and rejected from one reviewer should count only one approval or one rejection, depending on which happened last:
Grand total: 2 approvals, 2 change requests To achieve that, IMHO all counts (approvals, rejections) should be processed in the same database query. Check this comment (and other reviews of mine in that PR) for examples on how to achieve that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is already achieved. Both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duh, I forgot about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use different color tag for approved counter and requested counter. Even the approval requirement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One should approve or request change. |
||
if approvals >= pr.ProtectedBranch.RequiredApprovals { | ||
return i18n.Tr(lang, "repo.pulls.review_approved", approvals) | ||
} | ||
return i18n.Tr(lang, "repo.pulls.review_required", pr.ProtectedBranch.RequiredApprovals-approvals) | ||
} | ||
return i18n.Tr(lang, "repo.pulls.review_approved", 0) // by default | ||
} | ||
|
||
// GetDefaultMergeMessage returns default message used when merging pull request | ||
func (pr *PullRequest) GetDefaultMergeMessage() string { | ||
if pr.HeadRepo == nil { | ||
|
Uh oh!
There was an error while loading. Please reload this page.