1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Add create review comment implementation

Add migration for review
Other small changes

Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
Jonas Franz
2018-05-10 16:35:25 +02:00
parent 2c18552576
commit 9544c46052
10 changed files with 193 additions and 9 deletions

View File

@@ -618,6 +618,20 @@ func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content stri
})
}
// CreateCodeComment creates a plain code comment at the specified line / path
func CreateCodeComment(doer *User, repo *Repository, issue *Issue, commitSHA, content, treePath string, line int64) (*Comment, error) {
return CreateComment(&CreateCommentOptions{
Type: CommentTypeCode,
Doer: doer,
Repo: repo,
Issue: issue,
Content: content,
LineNum: line,
TreePath: treePath,
CommitSHA: commitSHA,
})
}
// CreateRefComment creates a commit reference comment to issue.
func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
if len(commitSHA) == 0 {

View File

@@ -180,6 +180,8 @@ var migrations = []Migration{
NewMigration("add last used passcode column for TOTP", addLastUsedPasscodeTOTP),
// v63 -> v64
NewMigration("add language column for user setting", addLanguageSetting),
// v64 -> v65
NewMigration("add review", addReview),
}
// Migrate database to current version

31
models/migrations/v64.go Normal file
View File

@@ -0,0 +1,31 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package migrations
import (
"fmt"
"code.gitea.io/gitea/modules/util"
"github.com/go-xorm/xorm"
)
func addReview(x *xorm.Engine) error {
// Review see models/review.go
type Review struct {
ID int64 `xorm:"pk autoincr"`
Type string
ReviewerID int64 `xorm:"index"`
IssueID int64 `xorm:"index"`
Content string
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
}
if err := x.Sync2(new(Review)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
}

View File

@@ -119,6 +119,7 @@ func init() {
new(RepoIndexerStatus),
new(LFSLock),
new(Reaction),
new(Review),
)
gonicNames := []string{"SSL", "UID"}

View File

@@ -16,13 +16,14 @@ const (
ReviewTypeComment
// ReviewTypeReject gives feedback blocking merge
ReviewTypeReject
// ReviewTypePending is a review which is not published yet
ReviewTypePending
)
// Review represents collection of code comments giving feedback for a PR
type Review struct {
ID int64 `xorm:"pk autoincr"`
Type ReviewType
Pending bool
Reviewer *User `xorm:"-"`
ReviewerID int64 `xorm:"index"`
Issue *Issue `xorm:"-"`
@@ -86,3 +87,34 @@ func getReviewByID(e Engine, id int64) (*Review, error) {
func GetReviewByID(id int64) (*Review, error) {
return getReviewByID(x, id)
}
func getPendingReviewByReviewerID(e Engine, reviewer *User, issue *Issue) (review *Review, err error) {
var exists bool
if exists, err = e.Table("review").Where("reviewer_id = ? and issue_id = ? and type = ?", reviewer.ID, issue.ID, ReviewTypePending).
Get(review); !exists && err == nil {
return nil, nil
}
return
}
// GetPendingReviewByReviewer returns the latest pending review of reviewer at PR issue
func GetPendingReviewByReviewer(reviewer *User, issue *Issue) (*Review, error) {
return getPendingReviewByReviewerID(x, reviewer, issue)
}
func createPendingReview(e Engine, reviewer *User, issue *Issue) (*Review, error) {
review := &Review{
Type: ReviewTypePending,
Issue: issue,
IssueID: issue.ID,
Reviewer: reviewer,
ReviewerID: reviewer.ID,
}
_, err := e.Insert(review)
return review, err
}
// CreatePendingReview creates an empty pending review
func CreatePendingReview(reviewer *User, issue *Issue) (*Review, error) {
return createPendingReview(x, reviewer, issue)
}