Add Review

Add IssueComment types

Signed-off-by: Jonas Franz <info@jonasfranz.software>

(cherry picked from commit 2b4daab)
Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
Jonas Franz 2018-05-06 22:04:40 +02:00
parent 85e1ad593a
commit 623a9f6e3c
No known key found for this signature in database
GPG Key ID: 506AEEBE80BEDECD
3 changed files with 97 additions and 1 deletions

View File

@ -1221,3 +1221,25 @@ func IsErrExternalLoginUserNotExist(err error) bool {
func (err ErrExternalLoginUserNotExist) Error() string { func (err ErrExternalLoginUserNotExist) Error() string {
return fmt.Sprintf("external login user link does not exists [userID: %d, loginSourceID: %d]", err.UserID, err.LoginSourceID) return fmt.Sprintf("external login user link does not exists [userID: %d, loginSourceID: %d]", err.UserID, err.LoginSourceID)
} }
// __________ .__
// \______ \ _______ _|__| ______ _ __
// | _// __ \ \/ / |/ __ \ \/ \/ /
// | | \ ___/\ /| \ ___/\ /
// |____|_ /\___ >\_/ |__|\___ >\/\_/
// \/ \/ \/
// ErrReviewNotExist represents a "ReviewNotExist" kind of error.
type ErrReviewNotExist struct {
ID int64
}
// IsErrReviewNotExist checks if an error is a ErrReviewNotExist.
func IsErrReviewNotExist(err error) bool {
_, ok := err.(ErrReviewNotExist)
return ok
}
func (err ErrReviewNotExist) Error() string {
return fmt.Sprintf("review does not exist [id: %d]", err.ID)
}

View File

@ -66,6 +66,10 @@ const (
CommentTypeModifiedDeadline CommentTypeModifiedDeadline
// Removed a due date // Removed a due date
CommentTypeRemovedDeadline CommentTypeRemovedDeadline
// Comment a line of code
CommentTypeCode
// Reviews a pull request by giving general feedback
CommentTypeReview
) )
// CommentTag defines comment tag type // CommentTag defines comment tag type
@ -100,7 +104,8 @@ type Comment struct {
NewTitle string NewTitle string
CommitID int64 CommitID int64
Line int64 Line int64 // - previous line / + proposed line
TreePath string
Content string `xorm:"TEXT"` Content string `xorm:"TEXT"`
RenderedContent string `xorm:"-"` RenderedContent string `xorm:"-"`
@ -115,6 +120,9 @@ type Comment struct {
// For view issue page. // For view issue page.
ShowTag CommentTag `xorm:"-"` ShowTag CommentTag `xorm:"-"`
Review *Review `xorm:"-"`
ReviewID int64
} }
// AfterLoad is invoked from XORM after setting the values of all fields of this object. // AfterLoad is invoked from XORM after setting the values of all fields of this object.
@ -318,6 +326,18 @@ func (c *Comment) LoadReactions() error {
return c.loadReactions(x) return c.loadReactions(x)
} }
func (c *Comment) loadReview(e Engine) (err error) {
if c.Review, err = getReviewByID(e, c.ReviewID); err != nil {
return err
}
return nil
}
// LoadReview loads the associated review
func (c *Comment) LoadReview() error {
return c.loadReview(x)
}
func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) { func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) {
var LabelID int64 var LabelID int64
if opts.Label != nil { if opts.Label != nil {
@ -339,6 +359,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
Content: opts.Content, Content: opts.Content,
OldTitle: opts.OldTitle, OldTitle: opts.OldTitle,
NewTitle: opts.NewTitle, NewTitle: opts.NewTitle,
TreePath: opts.TreePath,
} }
if _, err = e.Insert(comment); err != nil { if _, err = e.Insert(comment); err != nil {
return nil, err return nil, err
@ -557,6 +578,7 @@ type CreateCommentOptions struct {
CommitID int64 CommitID int64
CommitSHA string CommitSHA string
LineNum int64 LineNum int64
TreePath string
Content string Content string
Attachments []string // UUIDs of attachments Attachments []string // UUIDs of attachments
} }

52
models/review.go Normal file
View File

@ -0,0 +1,52 @@
// 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 models
import "code.gitea.io/gitea/modules/util"
type ReviewType int
const (
// Approving changes
ReviewTypeApprove ReviewType = iota
// General feedback
ReviewTypeComment
// Feedback blocking merge
ReviewTypeReject
)
// 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:"-"`
IssueID int64 `xorm:"index"`
ReviewCommentID int64 `xorm:"index"`
ReviewComment *Comment `xorm:"-"`
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
// CodeComments are the initial code comments of the review
CodeComments []*Comment `xorm:"-"`
}
func getReviewByID(e Engine, id int64) (*Review, error) {
review := new(Review)
if has, err := e.ID(id).Get(review); err != nil {
return nil, err
} else if !has {
return nil, ErrReviewNotExist{ID: id}
} else {
return review, nil
}
}
func GetReviewByID(id int64) (*Review, error) {
return getReviewByID(x, id)
}