mirror of https://github.com/go-gitea/gitea.git
Pull request review/approval and comment on code (#3748)
* Initial ui components for pull request review
* 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>
* Replace ReviewComment with Content
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add load functions
Add ReviewID to findComments
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add create review comment implementation
Add migration for review
Other small changes
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Simplified create and find functions for review
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Moved "Pending" to first position
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add GetCurrentReview to simplify fetching current review
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Preview for listing comments
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Move new comment form to its own file
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Implement Review form
Show Review comments on comment stream
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add support for single comments
Showing buttons in context
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add pending tag to pending review comments
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add unit tests for Review
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Fetch all review ids at once
Add unit tests
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* gofmt
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Improved comment rendering in "Files" view by adding Comments to DiffLine
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add support for invalidating comments
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Switched back to code.gitea.io/git
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Moved review migration from v64 to v65
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Rebuild css
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* gofmt
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Improve translations
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Fix unit tests by updating fixtures and updating outdated test
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Comments will be shown at the right place now
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add support for deleting CodeComments
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Fix problems caused by files in subdirectories
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add support for showing code comments of reviews in conversation
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add support for "Show/Hide outdated"
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Update code.gitea.io/git
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add support for new webhooks
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Update comparison
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Resolve conflicts
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Minor UI improvements
* update code.gitea.io/git
* Fix ui bug reported by @lunny causing wrong position of add button
Add functionality to "Cancel" button
Add scale effects to add button
Hide "Cancel" button for existing comments
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Prepare solving conflicts
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Show add button only if no comments already exist for the line
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add missing vendor files
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Check if reviewer is nil
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Show forms only to users who are logged in
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Revert "Show forms only to users who are logged in"
This reverts commit c083682
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Save patch in comment
Render patch for code comments
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add link to comment in code
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add reply form to comment list
Show forms only to signed in users
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add 'Reply' as translatable
Add CODE_COMMENT_LINES setting
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* gofmt
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Fix problems introduced by checking for singed in user
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add v70
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Update generated stylesheet
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Fix preview
Beginn with new review comment patch system
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add new algo to generate diff for line range
Remove old algo used for cutting big diffs (it was very buggy)
* Add documentation and example for CutDiffAroundLine
* Fix example of CutDiffAroundLine
* Fix some comment UI rendering bugs
* Add code comment edit mode
* Send notifications / actions to users until review gets published
Fix diff generation bug
Fix wrong hashtag
* Fix vet errors
* Send notifications also for single comments
* Fix some notification bugs, fix link
* Fix: add comment icon is only shown on code lines
* Add lint comment
* Add unit tests for git diff
* Add more error messages
* Regenerated css
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* fmt
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Regenerated CSS with latest less version
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Fix test by updating comment type to new ID
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Introducing CodeComments as type for map[string]map[int64][]*Comment
Other minor code improvements
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Fix data-tab issues
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Remove unnecessary change
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* refactored checkForInvalidation
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Append comments instead of setting
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Use HeadRepo instead of BaseRepo
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Update migration
Signed-off-by: Jonas Franz <info@jonasfranz.de>
* Regenerated CSS
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add copyright
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Update index.css
Signed-off-by: Jonas Franz <info@jonasfranz.software>
pull/4616/head^2
parent
9c354a539a
commit
6e64f9db8e
@ -0,0 +1,32 @@
|
||||
-
|
||||
id: 1
|
||||
type: 1
|
||||
reviewer_id: 1
|
||||
issue_id: 2
|
||||
content: "Demo Review"
|
||||
updated_unix: 946684810
|
||||
created_unix: 946684810
|
||||
-
|
||||
id: 2
|
||||
type: 1
|
||||
reviewer_id: 534543
|
||||
issue_id: 534543
|
||||
content: "Invalid Review #1"
|
||||
updated_unix: 946684810
|
||||
created_unix: 946684810
|
||||
-
|
||||
id: 3
|
||||
type: 1
|
||||
reviewer_id: 1
|
||||
issue_id: 343545
|
||||
content: "Invalid Review #2"
|
||||
updated_unix: 946684810
|
||||
created_unix: 946684810
|
||||
-
|
||||
id: 4
|
||||
type: 0 # Pending review
|
||||
reviewer_id: 1
|
||||
issue_id: 2
|
||||
content: "Pending Review"
|
||||
updated_unix: 946684810
|
||||
created_unix: 946684810
|
@ -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
|
||||
}
|
@ -0,0 +1,256 @@
|
||||
// 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 (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"github.com/go-xorm/xorm"
|
||||
|
||||
"github.com/go-xorm/builder"
|
||||
)
|
||||
|
||||
// ReviewType defines the sort of feedback a review gives
|
||||
type ReviewType int
|
||||
|
||||
// ReviewTypeUnknown unknown review type
|
||||
const ReviewTypeUnknown ReviewType = -1
|
||||
|
||||
const (
|
||||
// ReviewTypePending is a review which is not published yet
|
||||
ReviewTypePending ReviewType = iota
|
||||
// ReviewTypeApprove approves changes
|
||||
ReviewTypeApprove
|
||||
// ReviewTypeComment gives general feedback
|
||||
ReviewTypeComment
|
||||
// ReviewTypeReject gives feedback blocking merge
|
||||
ReviewTypeReject
|
||||
)
|
||||
|
||||
// Icon returns the corresponding icon for the review type
|
||||
func (rt ReviewType) Icon() string {
|
||||
switch rt {
|
||||
case ReviewTypeApprove:
|
||||
return "eye"
|
||||
case ReviewTypeReject:
|
||||
return "x"
|
||||
default:
|
||||
case ReviewTypeComment:
|
||||
case ReviewTypeUnknown:
|
||||
return "comment"
|
||||
}
|
||||
return "comment"
|
||||
}
|
||||
|
||||
// Review represents collection of code comments giving feedback for a PR
|
||||
type Review struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Type ReviewType
|
||||
Reviewer *User `xorm:"-"`
|
||||
ReviewerID int64 `xorm:"index"`
|
||||
Issue *Issue `xorm:"-"`
|
||||
IssueID int64 `xorm:"index"`
|
||||
Content string
|
||||
|
||||
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
||||
|
||||
// CodeComments are the initial code comments of the review
|
||||
CodeComments CodeComments `xorm:"-"`
|
||||
}
|
||||
|
||||
func (r *Review) loadCodeComments(e Engine) (err error) {
|
||||
r.CodeComments, err = fetchCodeCommentsByReview(e, r.Issue, nil, r)
|
||||
return
|
||||
}
|
||||
|
||||
// LoadCodeComments loads CodeComments
|
||||
func (r *Review) LoadCodeComments() error {
|
||||
return r.loadCodeComments(x)
|
||||
}
|
||||
|
||||
func (r *Review) loadIssue(e Engine) (err error) {
|
||||
r.Issue, err = getIssueByID(e, r.IssueID)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *Review) loadReviewer(e Engine) (err error) {
|
||||
if r.ReviewerID == 0 {
|
||||
return nil
|
||||
}
|
||||
r.Reviewer, err = getUserByID(e, r.ReviewerID)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *Review) loadAttributes(e Engine) (err error) {
|
||||
if err = r.loadReviewer(e); err != nil {
|
||||
return
|
||||
}
|
||||
if err = r.loadIssue(e); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// LoadAttributes loads all attributes except CodeComments
|
||||
func (r *Review) LoadAttributes() error {
|
||||
return r.loadAttributes(x)
|
||||
}
|
||||
|
||||
// Publish will send notifications / actions to participants for all code comments; parts are concurrent
|
||||
func (r *Review) Publish() error {
|
||||
return r.publish(x)
|
||||
}
|
||||
|
||||
func (r *Review) publish(e *xorm.Engine) error {
|
||||
if r.Type == ReviewTypePending || r.Type == ReviewTypeUnknown {
|
||||
return fmt.Errorf("review cannot be published if type is pending or unknown")
|
||||
}
|
||||
if r.Issue == nil {
|
||||
if err := r.loadIssue(e); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := r.Issue.loadRepo(e); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(r.CodeComments) == 0 {
|
||||
if err := r.loadCodeComments(e); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, lines := range r.CodeComments {
|
||||
for _, comments := range lines {
|
||||
for _, comment := range comments {
|
||||
go func(en *xorm.Engine, review *Review, comm *Comment) {
|
||||
sess := en.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sendCreateCommentAction(sess, &CreateCommentOptions{
|
||||
Doer: comm.Poster,
|
||||
Issue: review.Issue,
|
||||
Repo: review.Issue.Repo,
|
||||
Type: comm.Type,
|
||||
Content: comm.Content,
|
||||
}, comm); err != nil {
|
||||
log.Warn("sendCreateCommentAction: %v", err)
|
||||
}
|
||||
}(e, r, comment)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// GetReviewByID returns the review by the given ID
|
||||
func GetReviewByID(id int64) (*Review, error) {
|
||||
return getReviewByID(x, id)
|
||||
}
|
||||
|
||||
// FindReviewOptions represent possible filters to find reviews
|
||||
type FindReviewOptions struct {
|
||||
Type ReviewType
|
||||
IssueID int64
|
||||
ReviewerID int64
|
||||
}
|
||||
|
||||
func (opts *FindReviewOptions) toCond() builder.Cond {
|
||||
var cond = builder.NewCond()
|
||||
if opts.IssueID > 0 {
|
||||
cond = cond.And(builder.Eq{"issue_id": opts.IssueID})
|
||||
}
|
||||
if opts.ReviewerID > 0 {
|
||||
cond = cond.And(builder.Eq{"reviewer_id": opts.ReviewerID})
|
||||
}
|
||||
if opts.Type != ReviewTypeUnknown {
|
||||
cond = cond.And(builder.Eq{"type": opts.Type})
|
||||
}
|
||||
return cond
|
||||
}
|
||||
|
||||
func findReviews(e Engine, opts FindReviewOptions) ([]*Review, error) {
|
||||
reviews := make([]*Review, 0, 10)
|
||||
sess := e.Where(opts.toCond())
|
||||
return reviews, sess.
|
||||
Asc("created_unix").
|
||||
Asc("id").
|
||||
Find(&reviews)
|
||||
}
|
||||
|
||||
// FindReviews returns reviews passing FindReviewOptions
|
||||
func FindReviews(opts FindReviewOptions) ([]*Review, error) {
|
||||
return findReviews(x, opts)
|
||||
}
|
||||
|
||||
// CreateReviewOptions represent the options to create a review. Type, Issue and Reviewer are required.
|
||||
type CreateReviewOptions struct {
|
||||
Content string
|
||||
Type ReviewType
|
||||
Issue *Issue
|
||||
Reviewer *User
|
||||
}
|
||||
|
||||
func createReview(e Engine, opts CreateReviewOptions) (*Review, error) {
|
||||
review := &Review{
|
||||
Type: opts.Type,
|
||||
Issue: opts.Issue,
|
||||
IssueID: opts.Issue.ID,
|
||||
Reviewer: opts.Reviewer,
|
||||
ReviewerID: opts.Reviewer.ID,
|
||||
Content: opts.Content,
|
||||
}
|
||||
if _, err := e.Insert(review); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return review, nil
|
||||
}
|
||||
|
||||
// CreateReview creates a new review based on opts
|
||||
func CreateReview(opts CreateReviewOptions) (*Review, error) {
|
||||
return createReview(x, opts)
|
||||
}
|
||||
|
||||
func getCurrentReview(e Engine, reviewer *User, issue *Issue) (*Review, error) {
|
||||
if reviewer == nil {
|
||||
return nil, nil
|
||||
}
|
||||
reviews, err := findReviews(e, FindReviewOptions{
|
||||
Type: ReviewTypePending,
|
||||
IssueID: issue.ID,
|
||||
ReviewerID: reviewer.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(reviews) == 0 {
|
||||
return nil, ErrReviewNotExist{}
|
||||
}
|
||||
return reviews[0], nil
|
||||
}
|
||||
|
||||
// GetCurrentReview returns the current pending review of reviewer for given issue
|
||||
func GetCurrentReview(reviewer *User, issue *Issue) (*Review, error) {
|
||||
return getCurrentReview(x, reviewer, issue)
|
||||
}
|
||||
|
||||
// UpdateReview will update all cols of the given review in db
|
||||
func UpdateReview(r *Review) error {
|
||||
if _, err := x.ID(r.ID).AllCols().Update(r); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetReviewByID(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
review, err := GetReviewByID(1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Demo Review", review.Content)
|
||||
assert.Equal(t, ReviewTypeApprove, review.Type)
|
||||
|
||||
_, err = GetReviewByID(23892)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrReviewNotExist(err), "IsErrReviewNotExist")
|
||||
}
|
||||
|
||||
func TestReview_LoadAttributes(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
review := AssertExistsAndLoadBean(t, &Review{ID: 1}).(*Review)
|
||||
assert.NoError(t, review.LoadAttributes())
|
||||
assert.NotNil(t, review.Issue)
|
||||
assert.NotNil(t, review.Reviewer)
|
||||
|
||||
invalidReview1 := AssertExistsAndLoadBean(t, &Review{ID: 2}).(*Review)
|
||||
assert.Error(t, invalidReview1.LoadAttributes())
|
||||
|
||||
invalidReview2 := AssertExistsAndLoadBean(t, &Review{ID: 3}).(*Review)
|
||||
assert.Error(t, invalidReview2.LoadAttributes())
|
||||
|
||||
}
|
||||
|
||||
func TestReview_LoadCodeComments(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
review := AssertExistsAndLoadBean(t, &Review{ID: 4}).(*Review)
|
||||
assert.NoError(t, review.LoadAttributes())
|
||||
assert.NoError(t, review.LoadCodeComments())
|
||||
assert.Len(t, review.CodeComments, 1)
|
||||
assert.Equal(t, int64(4), review.CodeComments["README.md"][int64(4)][0].Line)
|
||||
}
|
||||
|
||||
func TestReviewType_Icon(t *testing.T) {
|
||||
assert.Equal(t, "eye", ReviewTypeApprove.Icon())
|
||||
assert.Equal(t, "x", ReviewTypeReject.Icon())
|
||||
assert.Equal(t, "comment", ReviewTypeComment.Icon())
|
||||
assert.Equal(t, "comment", ReviewTypeUnknown.Icon())
|
||||
assert.Equal(t, "comment", ReviewType(4).Icon())
|
||||
}
|
||||
|
||||
func TestFindReviews(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
reviews, err := FindReviews(FindReviewOptions{
|
||||
Type: ReviewTypeApprove,
|
||||
IssueID: 2,
|
||||
ReviewerID: 1,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, reviews, 1)
|
||||
assert.Equal(t, "Demo Review", reviews[0].Content)
|
||||
}
|
||||
|
||||
func TestGetCurrentReview(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
|
||||
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
review, err := GetCurrentReview(user, issue)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, review)
|
||||
assert.Equal(t, ReviewTypePending, review.Type)
|
||||
assert.Equal(t, "Pending Review", review.Content)
|
||||
|
||||
user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
review2, err := GetCurrentReview(user2, issue)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrReviewNotExist(err))
|
||||
assert.Nil(t, review2)
|
||||
}
|
||||
|
||||
func TestCreateReview(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
|
||||
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
review, err := CreateReview(CreateReviewOptions{
|
||||
Content: "New Review",
|
||||
Type: ReviewTypePending,
|
||||
Issue: issue,
|
||||
Reviewer: user,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "New Review", review.Content)
|
||||
AssertExistsAndLoadBean(t, &Review{Content: "New Review"})
|
||||
}
|
||||
|
||||
func TestUpdateReview(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
review := AssertExistsAndLoadBean(t, &Review{ID: 1}).(*Review)
|
||||
review.Content = "Updated Review"
|
||||
assert.NoError(t, UpdateReview(review))
|
||||
AssertExistsAndLoadBean(t, &Review{ID: 1, Content: "Updated Review"})
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,103 @@
|
||||
.ui.button.add-code-comment {
|
||||
font-size: 14px;
|
||||
height: 16px;
|
||||
padding: 2px 0 0;
|
||||
position: relative;
|
||||
width: 16px;
|
||||
z-index: 5;
|
||||
float: left;
|
||||
margin: -2px -10px -2px -20px;
|
||||
opacity: 0;
|
||||
transition: transform 0.1s ease-in-out;
|
||||
transform: scale(1, 1);
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.2, 1.2);
|
||||
}
|
||||
}
|
||||
|
||||
.focus-lines-new .ui.button.add-code-comment.add-code-comment-right,
|
||||
.focus-lines-old .ui.button.add-code-comment.add-code-comment-left {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.comment-code-cloud {
|
||||
padding: 4px;
|
||||
margin: 0 auto;
|
||||
position: relative;
|
||||
border: 1px solid #f1f1f1;
|
||||
margin-top: 13px;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 5px;
|
||||
|
||||
&:before {
|
||||
content: " ";
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 13px solid transparent;
|
||||
border-right: 13px solid transparent;
|
||||
border-bottom: 13px solid #f1f1f1;
|
||||
left: 20px;
|
||||
position: absolute;
|
||||
top: -13px;
|
||||
}
|
||||
|
||||
.attached.tab {
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
|
||||
&.markdown {
|
||||
padding: 1em;
|
||||
min-height: 168px;
|
||||
}
|
||||
}
|
||||
|
||||
.right.menu.options .item {
|
||||
padding: 0.85714286em 0.442857em;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ui.form textarea {
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
.ui.attached.tabular.menu {
|
||||
background: #f7f7f7;
|
||||
border: 1px solid #d4d4d5;
|
||||
padding-top: 5px;
|
||||
padding-left: 5px;
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
border-top: 1px solid #f1f1f1;
|
||||
margin-top: 10px;
|
||||
|
||||
.markdown-info {
|
||||
display: inline-block;
|
||||
margin: 5px 0;
|
||||
font-size: 12px;
|
||||
color: rgba(0,0,0,.6)
|
||||
}
|
||||
|
||||
.ui.right.floated {
|
||||
padding-top: 6px;
|
||||
}
|
||||
|
||||
&:after{
|
||||
clear: both;
|
||||
content: "";
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.comment-form-reply {
|
||||
margin: 0.5em !important;
|
||||
}
|
||||
}
|
||||
|
||||
.file-comment {
|
||||
font: 12px Consolas,"Liberation Mono",Menlo,Courier,monospace;
|
||||
color: rgba(0,0,0,.87);
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
// 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 repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
)
|
||||
|
||||
// CreateCodeComment will create a code comment including an pending review if required
|
||||
func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
|
||||
issue := GetActionIssue(ctx)
|
||||
if !issue.IsPull {
|
||||
return
|
||||
}
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
|
||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
|
||||
return
|
||||
}
|
||||
var comment *models.Comment
|
||||
defer func() {
|
||||
if comment != nil {
|
||||
ctx.Redirect(comment.HTMLURL())
|
||||
} else {
|
||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
|
||||
}
|
||||
}()
|
||||
signedLine := form.Line
|
||||
if form.Side == "previous" {
|
||||
signedLine *= -1
|
||||
}
|
||||
|
||||
review := new(models.Review)
|
||||
if form.IsReview {
|
||||
var err error
|
||||
// Check if the user has already a pending review for this issue
|
||||
if review, err = models.GetCurrentReview(ctx.User, issue); err != nil {
|
||||
if !models.IsErrReviewNotExist(err) {
|
||||
ctx.ServerError("CreateCodeComment", err)
|
||||
return
|
||||
}
|
||||
// No pending review exists
|
||||
// Create a new pending review for this issue & user
|
||||
if review, err = models.CreateReview(models.CreateReviewOptions{
|
||||
Type: models.ReviewTypePending,
|
||||
Reviewer: ctx.User,
|
||||
Issue: issue,
|
||||
}); err != nil {
|
||||
ctx.ServerError("CreateCodeComment", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
//FIXME check if line, commit and treepath exist
|
||||
comment, err := models.CreateCodeComment(
|
||||
ctx.User,
|
||||
issue.Repo,
|
||||
issue,
|
||||
form.Content,
|
||||
form.TreePath,
|
||||
signedLine,
|
||||
review.ID,
|
||||
)
|
||||
if err != nil {
|
||||
ctx.ServerError("CreateCodeComment", err)
|
||||
return
|
||||
}
|
||||
// Send no notification if comment is pending
|
||||
if !form.IsReview {
|
||||
notification.Service.NotifyIssue(issue, ctx.User.ID)
|
||||
}
|
||||
|
||||
log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
|
||||
}
|
||||
|
||||
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
|
||||
func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) {
|
||||
issue := GetActionIssue(ctx)
|
||||
if !issue.IsPull {
|
||||
return
|
||||
}
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if ctx.HasError() {
|
||||
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
|
||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
|
||||
return
|
||||
}
|
||||
var review *models.Review
|
||||
var err error
|
||||
|
||||
reviewType := form.ReviewType()
|
||||
if reviewType == models.ReviewTypeUnknown {
|
||||
ctx.ServerError("GetCurrentReview", fmt.Errorf("unknown ReviewType: %s", form.Type))
|
||||
return
|
||||
}
|
||||
review, err = models.GetCurrentReview(ctx.User, issue)
|
||||
if err != nil {
|
||||
if !models.IsErrReviewNotExist(err) {
|
||||
ctx.ServerError("GetCurrentReview", err)
|
||||
return
|
||||
}
|
||||
// No current review. Create a new one!
|
||||
if review, err = models.CreateReview(models.CreateReviewOptions{
|
||||
Type: reviewType,
|
||||
Issue: issue,
|
||||
Reviewer: ctx.User,
|
||||
Content: form.Content,
|
||||
}); err != nil {
|
||||
ctx.ServerError("CreateReview", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
review.Content = form.Content
|
||||
review.Type = reviewType
|
||||
if err = models.UpdateReview(review); err != nil {
|
||||
ctx.ServerError("UpdateReview", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
comm, err := models.CreateComment(&models.CreateCommentOptions{
|
||||
Type: models.CommentTypeReview,
|
||||
Doer: ctx.User,
|
||||
Content: review.Content,
|
||||
Issue: issue,
|
||||
Repo: issue.Repo,
|
||||
ReviewID: review.ID,
|
||||
})
|
||||
if err != nil || comm == nil {
|
||||
ctx.ServerError("CreateComment", err)
|
||||
return
|
||||
}
|
||||
if err = review.Publish(); err != nil {
|
||||
ctx.ServerError("Publish", err)
|
||||
return
|
||||
}
|
||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d#%s", ctx.Repo.RepoLink, issue.Index, comm.HashTag()))
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
{{if $.root.SignedUserID}}
|
||||
{{if $.hidden}}
|
||||
<button class="comment-form-reply ui green labeled icon tiny button"><i class="reply icon"></i> {{$.root.i18n.Tr "repo.diff.comment.reply"}}</button>
|
||||
{{end}}
|
||||
<form class="ui form {{if $.hidden}}hide comment-form{{end}}" action="{{$.root.Issue.HTMLURL}}/files/reviews/comments" method="post">
|
||||
{{$.root.CsrfTokenHtml}}
|
||||
<input type="hidden" name="side" value="{{if $.Side}}{{$.Side}}{{end}}">
|
||||
<input type="hidden" name="line" value="{{if $.Line}}{{$.Line}}{{end}}">
|
||||
<input type="hidden" name="path" value="{{if $.File}}{{$.File}}{{end}}">
|
||||
<input type="hidden" name="diff_start_cid">
|
||||
<input type="hidden" name="diff_end_cid">
|
||||
<input type="hidden" name="diff_base_cid">
|
||||
<div class="ui top attached tabular menu" {{if not $.hidden}}onload="assingMenuAttributes(this)" {{end}}data-write="write" data-preview="preview">
|
||||
<a class="active item" data-tab="write">{{$.root.i18n.Tr "write"}}</a>
|
||||
<a class="item" data-tab="preview" data-url="{{$.root.AppSubUrl}}/api/v1/markdown" data-context="{{$.root.RepoLink}}">{{$.root.i18n.Tr "preview"}}</a>
|
||||
</div>
|
||||
<div class="ui bottom attached active tab segment" data-tab="write">
|
||||
<div class="field">
|
||||
<textarea name="content" placeholder="{{$.root.i18n.Tr "repo.diff.comment.placeholder"}}"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui bottom attached tab segment markdown" data-tab="preview">
|
||||
{{.i18n.Tr "loading"}}
|
||||
</div>
|
||||
<div class="footer">
|
||||
<span class="markdown-info"><i class="octicon octicon-markdown"></i> {{$.root.i18n.Tr "repo.diff.comment.markdown_info"}}</span>
|
||||
<div class="ui right floated">
|
||||
{{if not $.reply}}
|
||||
{{if $.root.CurrentReview}}
|
||||
<button name="is_review" value="true" type="submit"
|
||||
class="ui submit green tiny button btn-add-comment">{{$.root.i18n.Tr "repo.diff.comment.add_review_comment"}}</button>
|
||||
{{else}}
|
||||
<button name="is_review" value="true" type="submit"
|
||||
class="ui submit green tiny button btn-start-review">{{$.root.i18n.Tr "repo.diff.comment.start_review"}}</button>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<button type="submit"
|
||||
class="ui submit tiny basic button btn-add-single">{{$.root.i18n.Tr "repo.diff.comment.add_single_comment"}}</button>
|
||||
{{if or (not $.HasComments) $.hidden}}
|
||||
<button type="button" class="ui submit tiny basic button btn-cancel" onclick="cancelCodeComment(this);">{{$.root.i18n.Tr "cancel"}}</button>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{{end}}
|
@ -0,0 +1,7 @@
|
||||
{{if $.comment}}
|
||||
{{ template "repo/diff/comment_form" dict "root" $.root "hidden" $.hidden "reply" $.reply "Line" $.comment.UnsignedLine "File" $.comment.TreePath "Side" $.comment.DiffSide "HasComments" true}}
|
||||
{{else if $.root}}
|
||||
{{ template "repo/diff/comment_form" $}}
|
||||
{{else}}
|
||||
{{ template "repo/diff/comment_form" dict "root" $}}
|
||||
{{end}}
|
@ -0,0 +1,51 @@
|
||||
{{range .comments}}
|
||||
|
||||
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.root.Lang }}
|
||||
<div class="comment" id="{{.HashTag}}">
|
||||
<a class="avatar" {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>
|
||||
<img src="{{.Poster.RelAvatarLink}}">
|
||||
</a>
|
||||
<div class="content">
|
||||
<div class="ui top attached header">
|
||||
<span class="text grey"><a {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.Name}}</a> {{$.root.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}}</span>
|
||||
<div class="ui right actions">
|
||||
{{if and .Review}}
|
||||
{{if eq .Review.Type 0}}
|
||||
<div class="item tag">
|
||||
{{$.root.i18n.Tr "repo.issues.review.pending"}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="item tag">
|
||||
{{$.root.i18n.Tr "repo.issues.review.review"}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID) }}
|
||||
{{if or $.root.IsRepositoryAdmin (eq .Poster.ID $.root.SignedUserID)}}
|
||||
<div class="item action">
|
||||
<a class="edit-content" href="#"><i class="octicon octicon-pencil"></i></a>
|
||||
<a class="delete-comment" href="#" data-comment-id={{.HashTag}} data-url="{{$.root.RepoLink}}/comments/{{.ID}}/delete" data-locale="{{$.root.i18n.Tr "repo.issues.delete_comment_confirm"}}"><i class="octicon octicon-x"></i></a>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui attached segment">
|
||||
<div class="render-content markdown has-emoji">
|
||||
{{if .RenderedContent}}
|
||||
{{.RenderedContent|Str2html}}
|
||||
{{else}}
|
||||
<span class="no-content">{{$.root.i18n.Tr "repo.issues.no_content"}}</span>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="raw-content hide">{{.Content}}</div>
|
||||
<div class="edit-content-zone hide" data-write="issuecomment-{{.ID}}-write" data-preview="issuecomment-{{.ID}}-preview" data-update-url="{{$.root.RepoLink}}/comments/{{.ID}}" data-context="{{$.root.RepoLink}}"></div>
|
||||
</div>
|
||||
{{$reactions := .Reactions.GroupByType}}
|
||||
{{if $reactions}}
|
||||
<div class="ui attached segment reactions">
|
||||
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID) "Reactions" $reactions }}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
@ -0,0 +1,3 @@
|
||||
<div class="field comment-code-cloud">
|
||||
{{template "repo/diff/comment_form_datahandler" .}}
|
||||
</div>
|
@ -0,0 +1,28 @@
|
||||
<div class="ui top right pointing dropdown custom" id="review-box">
|
||||
<div class="ui tiny green button btn-review">
|
||||
<span class="text">{{.i18n.Tr "repo.diff.review"}}</span>
|
||||
<i class="dropdown icon"></i>
|
||||
</div>
|
||||
<div class="menu">
|
||||
<div class="ui clearing segment">
|
||||
<form class="ui form" action="{{.Link}}/reviews/submit" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<i class="ui right floated link icon close"></i>
|
||||
<div class="header">
|
||||
{{$.i18n.Tr "repo.diff.review.header"}}
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<textarea name="content" tabindex="0" rows="2"
|
||||
placeholder="{{$.i18n.Tr "repo.diff.review.placeholder"}}"></textarea>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
<button type="submit" name="type" value="approve"
|
||||
class="ui submit green tiny button btn-submit">{{$.i18n.Tr "repo.diff.review.approve"}}</button>
|
||||
<button type="submit" name="type" value="comment"
|
||||
class="ui submit tiny basic button btn-submit">{{$.i18n.Tr "repo.diff.review.comment"}}</button>
|
||||
<button type="submit" name="type" value="reject"
|
||||
class="ui submit red tiny button btn-submit">{{$.i18n.Tr "repo.diff.review.reject"}}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue