mirror of
https://github.com/go-gitea/gitea
synced 2024-12-24 13:15:55 +01:00
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:
parent
85e1ad593a
commit
623a9f6e3c
@ -1221,3 +1221,25 @@ func IsErrExternalLoginUserNotExist(err error) bool {
|
||||
func (err ErrExternalLoginUserNotExist) Error() string {
|
||||
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)
|
||||
}
|
||||
|
@ -66,6 +66,10 @@ const (
|
||||
CommentTypeModifiedDeadline
|
||||
// Removed a due date
|
||||
CommentTypeRemovedDeadline
|
||||
// Comment a line of code
|
||||
CommentTypeCode
|
||||
// Reviews a pull request by giving general feedback
|
||||
CommentTypeReview
|
||||
)
|
||||
|
||||
// CommentTag defines comment tag type
|
||||
@ -100,7 +104,8 @@ type Comment struct {
|
||||
NewTitle string
|
||||
|
||||
CommitID int64
|
||||
Line int64
|
||||
Line int64 // - previous line / + proposed line
|
||||
TreePath string
|
||||
Content string `xorm:"TEXT"`
|
||||
RenderedContent string `xorm:"-"`
|
||||
|
||||
@ -115,6 +120,9 @@ type Comment struct {
|
||||
|
||||
// For view issue page.
|
||||
ShowTag CommentTag `xorm:"-"`
|
||||
|
||||
Review *Review `xorm:"-"`
|
||||
ReviewID int64
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
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) {
|
||||
var LabelID int64
|
||||
if opts.Label != nil {
|
||||
@ -339,6 +359,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
||||
Content: opts.Content,
|
||||
OldTitle: opts.OldTitle,
|
||||
NewTitle: opts.NewTitle,
|
||||
TreePath: opts.TreePath,
|
||||
}
|
||||
if _, err = e.Insert(comment); err != nil {
|
||||
return nil, err
|
||||
@ -557,6 +578,7 @@ type CreateCommentOptions struct {
|
||||
CommitID int64
|
||||
CommitSHA string
|
||||
LineNum int64
|
||||
TreePath string
|
||||
Content string
|
||||
Attachments []string // UUIDs of attachments
|
||||
}
|
||||
|
52
models/review.go
Normal file
52
models/review.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user