mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Mark PR reviews as stale at push and allow to dismiss stale approvals (#9532)
Fix #5997. If a push causes the patch/diff of a PR towards target branch to change, all existing reviews for the PR will be set and shown as stale. New branch protection option to dismiss stale approvals are added. To show that a review is not based on the latest PR changes, an hourglass is shown
This commit is contained in:
committed by
zeripath
parent
5b2d9333f1
commit
25531c71a7
@@ -53,7 +53,9 @@ type Review struct {
|
||||
IssueID int64 `xorm:"index"`
|
||||
Content string `xorm:"TEXT"`
|
||||
// Official is a review made by an assigned approver (counts towards approval)
|
||||
Official bool `xorm:"NOT NULL DEFAULT false"`
|
||||
Official bool `xorm:"NOT NULL DEFAULT false"`
|
||||
CommitID string `xorm:"VARCHAR(40)"`
|
||||
Stale bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
@@ -169,6 +171,8 @@ type CreateReviewOptions struct {
|
||||
Issue *Issue
|
||||
Reviewer *User
|
||||
Official bool
|
||||
CommitID string
|
||||
Stale bool
|
||||
}
|
||||
|
||||
// IsOfficialReviewer check if reviewer can make official reviews in issue (counts towards required approvals)
|
||||
@@ -200,6 +204,8 @@ func createReview(e Engine, opts CreateReviewOptions) (*Review, error) {
|
||||
ReviewerID: opts.Reviewer.ID,
|
||||
Content: opts.Content,
|
||||
Official: opts.Official,
|
||||
CommitID: opts.CommitID,
|
||||
Stale: opts.Stale,
|
||||
}
|
||||
if _, err := e.Insert(review); err != nil {
|
||||
return nil, err
|
||||
@@ -258,7 +264,7 @@ func IsContentEmptyErr(err error) bool {
|
||||
}
|
||||
|
||||
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
|
||||
func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content string) (*Review, *Comment, error) {
|
||||
func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool) (*Review, *Comment, error) {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
@@ -295,6 +301,8 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content strin
|
||||
Reviewer: doer,
|
||||
Content: content,
|
||||
Official: official,
|
||||
CommitID: commitID,
|
||||
Stale: stale,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -322,8 +330,10 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content strin
|
||||
review.Issue = issue
|
||||
review.Content = content
|
||||
review.Type = reviewType
|
||||
review.CommitID = commitID
|
||||
review.Stale = stale
|
||||
|
||||
if _, err := sess.ID(review.ID).Cols("content, type, official").Update(review); err != nil {
|
||||
if _, err := sess.ID(review.ID).Cols("content, type, official, commit_id, stale").Update(review); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
@@ -374,3 +384,17 @@ func GetReviewersByIssueID(issueID int64) (reviews []*Review, err error) {
|
||||
|
||||
return reviews, nil
|
||||
}
|
||||
|
||||
// MarkReviewsAsStale marks existing reviews as stale
|
||||
func MarkReviewsAsStale(issueID int64) (err error) {
|
||||
_, err = x.Exec("UPDATE `review` SET stale=? WHERE issue_id=?", true, issueID)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// MarkReviewsAsNotStale marks existing reviews as not stale for a giving commit SHA
|
||||
func MarkReviewsAsNotStale(issueID int64, commitID string) (err error) {
|
||||
_, err = x.Exec("UPDATE `review` SET stale=? WHERE issue_id=? AND commit_id=?", false, issueID, commitID)
|
||||
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user