mirror of
https://github.com/go-gitea/gitea
synced 2025-02-09 11:17:01 +01:00
Merge pull request #2 from JonasFranzDEV/feat/approval
Reviews and Pull Request comments
This commit is contained in:
commit
2f466132cc
@ -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)
|
||||||
|
}
|
||||||
|
@ -20,3 +20,22 @@
|
|||||||
issue_id: 1 # in repo_id 1
|
issue_id: 1 # in repo_id 1
|
||||||
content: "meh..."
|
content: "meh..."
|
||||||
created_unix: 946684812
|
created_unix: 946684812
|
||||||
|
-
|
||||||
|
id: 4
|
||||||
|
type: 19 # code comment
|
||||||
|
poster_id: 1
|
||||||
|
issue_id: 2
|
||||||
|
content: "meh..."
|
||||||
|
review_id: 4
|
||||||
|
line: 4
|
||||||
|
tree_path: "README.md"
|
||||||
|
created_unix: 946684812
|
||||||
|
-
|
||||||
|
id: 5
|
||||||
|
type: 19 # code comment
|
||||||
|
poster_id: 1
|
||||||
|
issue_id: 2
|
||||||
|
content: "meh..."
|
||||||
|
line: -4
|
||||||
|
tree_path: "README.md"
|
||||||
|
created_unix: 946684812
|
||||||
|
32
models/fixtures/review.yml
Normal file
32
models/fixtures/review.yml
Normal file
@ -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
|
@ -14,6 +14,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ type DiffLine struct {
|
|||||||
RightIdx int
|
RightIdx int
|
||||||
Type DiffLineType
|
Type DiffLineType
|
||||||
Content string
|
Content string
|
||||||
|
Comments []*Comment
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetType returns the type of a DiffLine.
|
// GetType returns the type of a DiffLine.
|
||||||
@ -225,6 +227,32 @@ type Diff struct {
|
|||||||
IsIncomplete bool
|
IsIncomplete bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadComments loads comments into each line
|
||||||
|
func (diff *Diff) LoadComments(issue *Issue, currentUser *User) error {
|
||||||
|
allComments, err := FetchCodeComments(issue, currentUser)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, file := range diff.Files {
|
||||||
|
if lineCommits, ok := allComments[file.Name]; ok {
|
||||||
|
for _, section := range file.Sections {
|
||||||
|
for _, line := range section.Lines {
|
||||||
|
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
|
||||||
|
line.Comments = comments
|
||||||
|
}
|
||||||
|
if comments, ok := lineCommits[int64(line.RightIdx)]; ok {
|
||||||
|
line.Comments = append(line.Comments, comments...)
|
||||||
|
}
|
||||||
|
sort.SliceStable(line.Comments, func(i, j int) bool {
|
||||||
|
return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NumFiles returns number of files changes in a diff.
|
// NumFiles returns number of files changes in a diff.
|
||||||
func (diff *Diff) NumFiles() int {
|
func (diff *Diff) NumFiles() int {
|
||||||
return len(diff.Files)
|
return len(diff.Files)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
dmp "github.com/sergi/go-diff/diffmatchpatch"
|
dmp "github.com/sergi/go-diff/diffmatchpatch"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func assertEqual(t *testing.T, s1 string, s2 template.HTML) {
|
func assertEqual(t *testing.T, s1 string, s2 template.HTML) {
|
||||||
@ -34,3 +35,28 @@ func TestDiffToHTML(t *testing.T) {
|
|||||||
{Type: dmp.DiffEqual, Text: " biz"},
|
{Type: dmp.DiffEqual, Text: " biz"},
|
||||||
}, DiffLineDel))
|
}, DiffLineDel))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDiff_LoadComments(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
|
||||||
|
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||||
|
diff := &Diff{
|
||||||
|
Files: []*DiffFile{
|
||||||
|
{
|
||||||
|
Name: "README.md",
|
||||||
|
Sections: []*DiffSection{
|
||||||
|
{
|
||||||
|
Lines: []*DiffLine{
|
||||||
|
{
|
||||||
|
LeftIdx: 4,
|
||||||
|
RightIdx: 4,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.NoError(t, diff.LoadComments(issue, user))
|
||||||
|
assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 2)
|
||||||
|
}
|
||||||
|
@ -6,8 +6,11 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"code.gitea.io/git"
|
||||||
|
"code.gitea.io/gitea/modules/markup/markdown"
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
"github.com/go-xorm/builder"
|
"github.com/go-xorm/builder"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
@ -66,6 +69,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 +107,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 +123,10 @@ type Comment struct {
|
|||||||
|
|
||||||
// For view issue page.
|
// For view issue page.
|
||||||
ShowTag CommentTag `xorm:"-"`
|
ShowTag CommentTag `xorm:"-"`
|
||||||
|
|
||||||
|
Review *Review `xorm:"-"`
|
||||||
|
ReviewID int64
|
||||||
|
Invalidated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 +330,52 @@ 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 (c *Comment) getPathAndFile(repoPath string) (string, string) {
|
||||||
|
p := path.Dir(c.TreePath)
|
||||||
|
if p == "." {
|
||||||
|
p = ""
|
||||||
|
}
|
||||||
|
p = fmt.Sprintf("%s/%s", repoPath, p)
|
||||||
|
file := path.Base(c.TreePath)
|
||||||
|
return p, file
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Comment) checkInvalidation(e Engine, repo *git.Repository, branch string) error {
|
||||||
|
p, file := c.getPathAndFile(repo.Path)
|
||||||
|
// FIXME differentiate between previous and proposed line
|
||||||
|
var line = c.Line
|
||||||
|
if line < 0 {
|
||||||
|
line *= -1
|
||||||
|
}
|
||||||
|
commit, err := repo.LineBlame(branch, p, file, uint(line))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if c.CommitSHA != commit.ID.String() {
|
||||||
|
c.Invalidated = true
|
||||||
|
return UpdateComment(c)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckInvalidation checks if the line of code comment got changed by another commit.
|
||||||
|
// If the line got changed the comment is going to be invalidated.
|
||||||
|
func (c *Comment) CheckInvalidation(repo *git.Repository, branch string) error {
|
||||||
|
return c.checkInvalidation(x, repo, branch)
|
||||||
|
}
|
||||||
|
|
||||||
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 +397,8 @@ 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,
|
||||||
|
ReviewID: opts.ReviewID,
|
||||||
}
|
}
|
||||||
if _, err = e.Insert(comment); err != nil {
|
if _, err = e.Insert(comment); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -557,6 +617,8 @@ type CreateCommentOptions struct {
|
|||||||
CommitID int64
|
CommitID int64
|
||||||
CommitSHA string
|
CommitSHA string
|
||||||
LineNum int64
|
LineNum int64
|
||||||
|
TreePath string
|
||||||
|
ReviewID int64
|
||||||
Content string
|
Content string
|
||||||
Attachments []string // UUIDs of attachments
|
Attachments []string // UUIDs of attachments
|
||||||
}
|
}
|
||||||
@ -596,6 +658,43 @@ 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, content, treePath string, line, reviewID int64) (*Comment, error) {
|
||||||
|
pr, err := GetPullRequestByIssueID(issue.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err)
|
||||||
|
}
|
||||||
|
if err := pr.GetHeadRepo(); err != nil {
|
||||||
|
return nil, fmt.Errorf("GetHeadRepo: %v", err)
|
||||||
|
}
|
||||||
|
gitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("OpenRepository: %v", err)
|
||||||
|
}
|
||||||
|
dummyComment := &Comment{Line: line, TreePath: treePath}
|
||||||
|
p, file := dummyComment.getPathAndFile(gitRepo.Path)
|
||||||
|
// FIXME differentiate between previous and proposed line
|
||||||
|
var gitLine = line
|
||||||
|
if gitLine < 0 {
|
||||||
|
gitLine *= -1
|
||||||
|
}
|
||||||
|
commit, err := gitRepo.LineBlame(pr.HeadBranch, p, file, uint(gitLine))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return CreateComment(&CreateCommentOptions{
|
||||||
|
Type: CommentTypeCode,
|
||||||
|
Doer: doer,
|
||||||
|
Repo: repo,
|
||||||
|
Issue: issue,
|
||||||
|
Content: content,
|
||||||
|
LineNum: line,
|
||||||
|
TreePath: treePath,
|
||||||
|
CommitSHA: commit.ID.String(),
|
||||||
|
ReviewID: reviewID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// CreateRefComment creates a commit reference comment to issue.
|
// CreateRefComment creates a commit reference comment to issue.
|
||||||
func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
|
func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
|
||||||
if len(commitSHA) == 0 {
|
if len(commitSHA) == 0 {
|
||||||
@ -641,6 +740,7 @@ func GetCommentByID(id int64) (*Comment, error) {
|
|||||||
type FindCommentsOptions struct {
|
type FindCommentsOptions struct {
|
||||||
RepoID int64
|
RepoID int64
|
||||||
IssueID int64
|
IssueID int64
|
||||||
|
ReviewID int64
|
||||||
Since int64
|
Since int64
|
||||||
Type CommentType
|
Type CommentType
|
||||||
}
|
}
|
||||||
@ -653,6 +753,9 @@ func (opts *FindCommentsOptions) toConds() builder.Cond {
|
|||||||
if opts.IssueID > 0 {
|
if opts.IssueID > 0 {
|
||||||
cond = cond.And(builder.Eq{"comment.issue_id": opts.IssueID})
|
cond = cond.And(builder.Eq{"comment.issue_id": opts.IssueID})
|
||||||
}
|
}
|
||||||
|
if opts.ReviewID > 0 {
|
||||||
|
cond = cond.And(builder.Eq{"comment.review_id": opts.ReviewID})
|
||||||
|
}
|
||||||
if opts.Since > 0 {
|
if opts.Since > 0 {
|
||||||
cond = cond.And(builder.Gte{"comment.updated_unix": opts.Since})
|
cond = cond.And(builder.Gte{"comment.updated_unix": opts.Since})
|
||||||
}
|
}
|
||||||
@ -745,3 +848,59 @@ func DeleteComment(comment *Comment) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchCodeComments(e Engine, issue *Issue, currentUser *User) (map[string]map[int64][]*Comment, error) {
|
||||||
|
pathToLineToComment := make(map[string]map[int64][]*Comment)
|
||||||
|
|
||||||
|
//Find comments
|
||||||
|
opts := FindCommentsOptions{
|
||||||
|
Type: CommentTypeCode,
|
||||||
|
IssueID: issue.ID,
|
||||||
|
}
|
||||||
|
var comments []*Comment
|
||||||
|
if err := e.Where(opts.toConds().And(builder.Eq{"invalidated": false})).
|
||||||
|
Asc("comment.created_unix").
|
||||||
|
Asc("comment.id").
|
||||||
|
Find(&comments); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := issue.loadRepo(e); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Find all reviews by ReviewID
|
||||||
|
reviews := make(map[int64]*Review)
|
||||||
|
var ids = make([]int64, 0, len(comments))
|
||||||
|
for _, comment := range comments {
|
||||||
|
if comment.ReviewID != 0 {
|
||||||
|
ids = append(ids, comment.ReviewID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := e.In("id", ids).Find(&reviews); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, comment := range comments {
|
||||||
|
if re, ok := reviews[comment.ReviewID]; ok && re != nil {
|
||||||
|
// If the review is pending only the author can see the comments
|
||||||
|
if re.Type == ReviewTypePending &&
|
||||||
|
(currentUser == nil || currentUser.ID != re.ReviewerID) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
comment.Review = re
|
||||||
|
}
|
||||||
|
|
||||||
|
comment.RenderedContent = string(markdown.Render([]byte(comment.Content), issue.Repo.Link(),
|
||||||
|
issue.Repo.ComposeMetas()))
|
||||||
|
|
||||||
|
if pathToLineToComment[comment.TreePath] == nil {
|
||||||
|
pathToLineToComment[comment.TreePath] = make(map[int64][]*Comment)
|
||||||
|
}
|
||||||
|
pathToLineToComment[comment.TreePath][comment.Line] = append(pathToLineToComment[comment.TreePath][comment.Line], comment)
|
||||||
|
}
|
||||||
|
return pathToLineToComment, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
|
||||||
|
func FetchCodeComments(issue *Issue, currentUser *User) (map[string]map[int64][]*Comment, error) {
|
||||||
|
return fetchCodeComments(x, issue, currentUser)
|
||||||
|
}
|
||||||
|
@ -39,3 +39,21 @@ func TestCreateComment(t *testing.T) {
|
|||||||
updatedIssue := AssertExistsAndLoadBean(t, &Issue{ID: issue.ID}).(*Issue)
|
updatedIssue := AssertExistsAndLoadBean(t, &Issue{ID: issue.ID}).(*Issue)
|
||||||
AssertInt64InRange(t, now, then, int64(updatedIssue.UpdatedUnix))
|
AssertInt64InRange(t, now, then, int64(updatedIssue.UpdatedUnix))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFetchCodeComments(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
|
||||||
|
issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
|
||||||
|
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||||
|
res, err := FetchCodeComments(issue, user)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Contains(t, res, "README.md")
|
||||||
|
assert.Contains(t, res["README.md"], int64(4))
|
||||||
|
assert.Len(t, res["README.md"][4], 1)
|
||||||
|
assert.Equal(t, int64(4), res["README.md"][4][0].ID)
|
||||||
|
|
||||||
|
user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||||
|
res, err = FetchCodeComments(issue, user2)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Empty(t, res)
|
||||||
|
}
|
||||||
|
@ -180,6 +180,8 @@ var migrations = []Migration{
|
|||||||
NewMigration("add last used passcode column for TOTP", addLastUsedPasscodeTOTP),
|
NewMigration("add last used passcode column for TOTP", addLastUsedPasscodeTOTP),
|
||||||
// v63 -> v64
|
// v63 -> v64
|
||||||
NewMigration("add language column for user setting", addLanguageSetting),
|
NewMigration("add language column for user setting", addLanguageSetting),
|
||||||
|
// v64 -> v65
|
||||||
|
NewMigration("add review", addReview),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate database to current version
|
// Migrate database to current version
|
||||||
|
31
models/migrations/v64.go
Normal file
31
models/migrations/v64.go
Normal 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
|
||||||
|
}
|
@ -119,6 +119,7 @@ func init() {
|
|||||||
new(RepoIndexerStatus),
|
new(RepoIndexerStatus),
|
||||||
new(LFSLock),
|
new(LFSLock),
|
||||||
new(Reaction),
|
new(Reaction),
|
||||||
|
new(Review),
|
||||||
)
|
)
|
||||||
|
|
||||||
gonicNames := []string{"SSL", "UID"}
|
gonicNames := []string{"SSL", "UID"}
|
||||||
|
@ -1063,10 +1063,7 @@ func (prs PullRequestList) loadAttributes(e Engine) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load issues.
|
// Load issues.
|
||||||
issueIDs := make([]int64, 0, len(prs))
|
issueIDs := prs.getIssueIDs()
|
||||||
for i := range prs {
|
|
||||||
issueIDs = append(issueIDs, prs[i].IssueID)
|
|
||||||
}
|
|
||||||
issues := make([]*Issue, 0, len(issueIDs))
|
issues := make([]*Issue, 0, len(issueIDs))
|
||||||
if err := e.
|
if err := e.
|
||||||
Where("id > 0").
|
Where("id > 0").
|
||||||
@ -1085,11 +1082,44 @@ func (prs PullRequestList) loadAttributes(e Engine) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (prs PullRequestList) getIssueIDs() []int64 {
|
||||||
|
issueIDs := make([]int64, 0, len(prs))
|
||||||
|
for i := range prs {
|
||||||
|
issueIDs = append(issueIDs, prs[i].IssueID)
|
||||||
|
}
|
||||||
|
return issueIDs
|
||||||
|
}
|
||||||
|
|
||||||
// LoadAttributes load all the prs attributes
|
// LoadAttributes load all the prs attributes
|
||||||
func (prs PullRequestList) LoadAttributes() error {
|
func (prs PullRequestList) LoadAttributes() error {
|
||||||
return prs.loadAttributes(x)
|
return prs.loadAttributes(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (prs PullRequestList) invalidateCodeComments(e Engine, repo *git.Repository, branch string) error {
|
||||||
|
if len(prs) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
issueIDs := prs.getIssueIDs()
|
||||||
|
var codeComments []*Comment
|
||||||
|
if err := e.
|
||||||
|
Where("type = ? and invalidated = ?", CommentTypeCode, false).
|
||||||
|
In("issue_id", issueIDs).
|
||||||
|
Find(&codeComments); err != nil {
|
||||||
|
return fmt.Errorf("find code comments: %v", err)
|
||||||
|
}
|
||||||
|
for _, comment := range codeComments {
|
||||||
|
if err := comment.CheckInvalidation(repo, branch); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// InvalidateCodeComments will lookup the prs for code comments which got invalidated by change
|
||||||
|
func (prs PullRequestList) InvalidateCodeComments(repo *git.Repository, branch string) error {
|
||||||
|
return prs.invalidateCodeComments(x, repo, branch)
|
||||||
|
}
|
||||||
|
|
||||||
func addHeadRepoTasks(prs []*PullRequest) {
|
func addHeadRepoTasks(prs []*PullRequest) {
|
||||||
for _, pr := range prs {
|
for _, pr := range prs {
|
||||||
log.Trace("addHeadRepoTasks[%d]: composing new test task", pr.ID)
|
log.Trace("addHeadRepoTasks[%d]: composing new test task", pr.ID)
|
||||||
@ -1116,10 +1146,29 @@ func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
if isSync {
|
if isSync {
|
||||||
if err = PullRequestList(prs).LoadAttributes(); err != nil {
|
requests := PullRequestList(prs)
|
||||||
|
if err = requests.LoadAttributes(); err != nil {
|
||||||
log.Error(4, "PullRequestList.LoadAttributes: %v", err)
|
log.Error(4, "PullRequestList.LoadAttributes: %v", err)
|
||||||
}
|
}
|
||||||
|
var gitRepo *git.Repository
|
||||||
|
repo, err := GetRepositoryByID(repoID)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(4, "GetRepositoryByID: %v", err)
|
||||||
|
goto REQUIRED_PROCEDURE
|
||||||
|
}
|
||||||
|
gitRepo, err = git.OpenRepository(repo.RepoPath())
|
||||||
|
if err != nil {
|
||||||
|
log.Error(4, "git.OpenRepository: %v", err)
|
||||||
|
goto REQUIRED_PROCEDURE
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
err := requests.InvalidateCodeComments(gitRepo, branch)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(4, "PullRequestList.InvalidateCodeComments: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
REQUIRED_PROCEDURE:
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, pr := range prs {
|
for _, pr := range prs {
|
||||||
pr.Issue.PullRequest = pr
|
pr.Issue.PullRequest = pr
|
||||||
|
202
models/review.go
Normal file
202
models/review.go
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
// 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"
|
||||||
|
|
||||||
|
"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 []*Comment `xorm:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Review) loadCodeComments(e Engine) (err error) {
|
||||||
|
r.CodeComments, err = findComments(e, FindCommentsOptions{IssueID: r.IssueID, ReviewID: r.ID, Type: CommentTypeCode})
|
||||||
|
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) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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
|
||||||
|
}
|
106
models/review_test.go
Normal file
106
models/review_test.go
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
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.LoadCodeComments())
|
||||||
|
assert.Len(t, review.CodeComments, 1)
|
||||||
|
assert.Equal(t, int64(4), review.CodeComments[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"})
|
||||||
|
}
|
@ -356,6 +356,45 @@ func (f *MergePullRequestForm) Validate(ctx *macaron.Context, errs binding.Error
|
|||||||
return validate(errs, ctx.Data, f, ctx.Locale)
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CodeCommentForm form for adding code comments for PRs
|
||||||
|
type CodeCommentForm struct {
|
||||||
|
Content string `binding:"Required"`
|
||||||
|
Side string `binding:"Required;In(previous,proposed)"`
|
||||||
|
Line int64
|
||||||
|
TreePath string `form:"path" binding:"Required"`
|
||||||
|
IsReview bool `form:"is_review"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate validates the fields
|
||||||
|
func (f *CodeCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||||||
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SubmitReviewForm for submitting a finished code review
|
||||||
|
type SubmitReviewForm struct {
|
||||||
|
Content string
|
||||||
|
Type string `binding:"Required;In(approve,comment,reject)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate validates the fields
|
||||||
|
func (f *SubmitReviewForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||||||
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewType will return the corresponding reviewtype for type
|
||||||
|
func (f SubmitReviewForm) ReviewType() models.ReviewType {
|
||||||
|
switch f.Type {
|
||||||
|
case "approve":
|
||||||
|
return models.ReviewTypeApprove
|
||||||
|
case "comment":
|
||||||
|
return models.ReviewTypeComment
|
||||||
|
case "reject":
|
||||||
|
return models.ReviewTypeReject
|
||||||
|
default:
|
||||||
|
return models.ReviewTypeUnknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// __________ .__
|
// __________ .__
|
||||||
// \______ \ ____ | | ____ _____ ______ ____
|
// \______ \ ____ | | ____ _____ ______ ____
|
||||||
// | _// __ \| | _/ __ \\__ \ / ___// __ \
|
// | _// __ \| | _/ __ \\__ \ / ___// __ \
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"mime"
|
"mime"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -186,6 +187,36 @@ func NewFuncMap() []template.FuncMap {
|
|||||||
"ParseDeadline": func(deadline string) []string {
|
"ParseDeadline": func(deadline string) []string {
|
||||||
return strings.Split(deadline, "|")
|
return strings.Split(deadline, "|")
|
||||||
},
|
},
|
||||||
|
"mul": func(first int, second int64) int64 { return second * int64(first) },
|
||||||
|
"dict": func(values ...interface{}) (map[string]interface{}, error) {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil, errors.New("invalid dict call")
|
||||||
|
}
|
||||||
|
|
||||||
|
dict := make(map[string]interface{})
|
||||||
|
|
||||||
|
for i := 0; i < len(values); i++ {
|
||||||
|
key, isset := values[i].(string)
|
||||||
|
if !isset {
|
||||||
|
if reflect.TypeOf(values[i]).Kind() == reflect.Map {
|
||||||
|
m := values[i].(map[string]interface{})
|
||||||
|
for i, v := range m {
|
||||||
|
dict[i] = v
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("dict values must be maps")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
i++
|
||||||
|
if i == len(values) {
|
||||||
|
return nil, errors.New("specify the key for non array values")
|
||||||
|
}
|
||||||
|
dict[key] = values[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return dict, nil
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -757,6 +757,11 @@ issues.due_date_added = "added the due date %s %s"
|
|||||||
issues.due_date_modified = "modified the due date to %s from %s %s"
|
issues.due_date_modified = "modified the due date to %s from %s %s"
|
||||||
issues.due_date_remove = "removed the due date %s %s"
|
issues.due_date_remove = "removed the due date %s %s"
|
||||||
issues.due_date_overdue = "Overdue"
|
issues.due_date_overdue = "Overdue"
|
||||||
|
issues.review.approve = "approved these changes %s"
|
||||||
|
issues.review.comment = "left review comments %s"
|
||||||
|
issues.review.reject = "rejected these changes %s"
|
||||||
|
issues.review.pending = Pending
|
||||||
|
issues.review.review = Review
|
||||||
|
|
||||||
pulls.desc = Enable merge requests and code reviews.
|
pulls.desc = Enable merge requests and code reviews.
|
||||||
pulls.new = New Pull Request
|
pulls.new = New Pull Request
|
||||||
|
File diff suppressed because one or more lines are too long
@ -781,7 +781,6 @@ function initPullRequestReview() {
|
|||||||
commentCloud.find('.tab.segment').each(function(i, item) {
|
commentCloud.find('.tab.segment').each(function(i, item) {
|
||||||
$(item).attr('data-tab', $(item).attr('data-tab') + id);
|
$(item).attr('data-tab', $(item).attr('data-tab') + id);
|
||||||
});
|
});
|
||||||
|
|
||||||
initCommentPreviewTab(commentCloud.find('.form'));
|
initCommentPreviewTab(commentCloud.find('.form'));
|
||||||
}
|
}
|
||||||
commentCloud.find('textarea').focus();
|
commentCloud.find('textarea').focus();
|
||||||
|
@ -684,6 +684,21 @@
|
|||||||
margin-right: -1px;
|
margin-right: -1px;
|
||||||
font-size: 25px;
|
font-size: 25px;
|
||||||
}
|
}
|
||||||
|
&.octicon-comment {
|
||||||
|
margin-top: 4px;
|
||||||
|
margin-left: -35px;
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
&.octicon-eye {
|
||||||
|
margin-top: 3px;
|
||||||
|
margin-left: -35px;
|
||||||
|
margin-right: 0px;
|
||||||
|
font-size: 22px;
|
||||||
|
}
|
||||||
|
&.octicon-x {
|
||||||
|
margin-left: -33px;
|
||||||
|
font-size: 25px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.detail {
|
.detail {
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
|
@ -61,7 +61,7 @@ func GlobalInit() {
|
|||||||
}
|
}
|
||||||
models.HasEngine = true
|
models.HasEngine = true
|
||||||
if err := models.InitOAuth2(); err != nil {
|
if err := models.InitOAuth2(); err != nil {
|
||||||
log.Fatal(4, "Failed to initialize OAuth2 support: %v", err)
|
//log.Fatal(4, "Failed to initialize OAuth2 support: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
models.LoadRepoConfig()
|
models.LoadRepoConfig()
|
||||||
|
@ -706,6 +706,11 @@ func ViewIssue(ctx *context.Context) {
|
|||||||
ctx.ServerError("LoadAssignees", err)
|
ctx.ServerError("LoadAssignees", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if comment.Type == models.CommentTypeCode || comment.Type == models.CommentTypeReview {
|
||||||
|
if err = comment.LoadReview(); err != nil && !models.IsErrReviewNotExist(err) {
|
||||||
|
ctx.ServerError("LoadReview", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,6 +456,12 @@ func ViewPullFiles(ctx *context.Context) {
|
|||||||
ctx.ServerError("GetDiffRange", err)
|
ctx.ServerError("GetDiffRange", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = diff.LoadComments(issue, ctx.User); err != nil {
|
||||||
|
ctx.ServerError("LoadComments", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Data["Diff"] = diff
|
ctx.Data["Diff"] = diff
|
||||||
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
||||||
|
|
||||||
@ -470,7 +476,11 @@ func ViewPullFiles(ctx *context.Context) {
|
|||||||
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(headTarget, "src", "commit", startCommitID)
|
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(headTarget, "src", "commit", startCommitID)
|
||||||
ctx.Data["RawPath"] = setting.AppSubURL + "/" + path.Join(headTarget, "raw", "commit", endCommitID)
|
ctx.Data["RawPath"] = setting.AppSubURL + "/" + path.Join(headTarget, "raw", "commit", endCommitID)
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
|
ctx.Data["CurrentReview"], err = models.GetCurrentReview(ctx.User, issue)
|
||||||
|
if err != nil && !models.IsErrReviewNotExist(err) {
|
||||||
|
ctx.ServerError("GetCurrentReview", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
ctx.HTML(200, tplPullFiles)
|
ctx.HTML(200, tplPullFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
152
routers/repo/pull_review.go
Normal file
152
routers/repo/pull_review.go
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
// 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(fmt.Sprintf("%s/pulls/%d/files#%s", ctx.Repo.RepoLink, issue.Index, comment.HashTag()))
|
||||||
|
} 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
|
||||||
|
defer func() {
|
||||||
|
if review != nil {
|
||||||
|
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.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Redirect(fmt.Sprintf("%s/pulls/%d#%s", ctx.Repo.RepoLink, issue.Index, comm.HashTag()))
|
||||||
|
} else {
|
||||||
|
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
review.Content = form.Content
|
||||||
|
review.Type = reviewType
|
||||||
|
if err = models.UpdateReview(review); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
@ -633,9 +633,15 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||||||
m.Get(".diff", repo.DownloadPullDiff)
|
m.Get(".diff", repo.DownloadPullDiff)
|
||||||
m.Get(".patch", repo.DownloadPullPatch)
|
m.Get(".patch", repo.DownloadPullPatch)
|
||||||
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
|
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
|
||||||
m.Get("/files", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ViewPullFiles)
|
|
||||||
m.Post("/merge", reqRepoWriter, bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest)
|
m.Post("/merge", reqRepoWriter, bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest)
|
||||||
m.Post("/cleanup", context.RepoRef(), repo.CleanUpPullRequest)
|
m.Post("/cleanup", context.RepoRef(), repo.CleanUpPullRequest)
|
||||||
|
m.Group("/files", func() {
|
||||||
|
m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ViewPullFiles)
|
||||||
|
m.Group("/reviews", func() {
|
||||||
|
m.Post("/comments", bindIgnErr(auth.CodeCommentForm{}), repo.CreateCodeComment)
|
||||||
|
m.Post("/submit", bindIgnErr(auth.SubmitReviewForm{}), repo.SubmitReview)
|
||||||
|
})
|
||||||
|
})
|
||||||
}, repo.MustAllowPulls)
|
}, repo.MustAllowPulls)
|
||||||
|
|
||||||
m.Group("/raw", func() {
|
m.Group("/raw", func() {
|
||||||
|
@ -114,14 +114,29 @@
|
|||||||
<a class="ui green button add-code-comment add-code-comment-right" data-side="right" data-idx="{{$line.RightIdx}}">+</a>
|
<a class="ui green button add-code-comment add-code-comment-right" data-side="right" data-idx="{{$line.RightIdx}}">+</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="lines-code lines-code-new halfwidth">
|
<td class="lines-code lines-code-new halfwidth">
|
||||||
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
|
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{{if gt (len $line.Comments) 0}}
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="add-comment-left add-comment-right">
|
||||||
|
<div class="field comment-code-cloud">
|
||||||
|
<div class="comment-list">
|
||||||
|
<ui class="ui comments">
|
||||||
|
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
|
||||||
|
</ui>
|
||||||
|
</div>
|
||||||
|
{{template "repo/diff/comment_form" $}}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{template "repo/diff/section_unified" .}}
|
{{template "repo/diff/section_unified" dict "file" . "root" $}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
37
templates/repo/diff/comment_form.tmpl
Normal file
37
templates/repo/diff/comment_form.tmpl
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<form class="ui form" action="{{.Link}}/reviews/comments" method="post">
|
||||||
|
{{.CsrfTokenHtml}}
|
||||||
|
<input type="hidden" name="side" value="previous">
|
||||||
|
<input type="hidden" name="line" value="2">
|
||||||
|
<input type="hidden" name="path" value="README.md">
|
||||||
|
<input type="hidden" name="commit_id" value="e324f1688f063d6fd9268fb8f02149c9eb1a867c">
|
||||||
|
<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" data-write="write" data-preview="preview">
|
||||||
|
<a class="active item" data-tab="write">{{.i18n.Tr "write"}}</a>
|
||||||
|
<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}">{{.i18n.Tr "preview"}}</a>
|
||||||
|
</div>
|
||||||
|
<div class="ui bottom attached active tab segment" data-tab="write">
|
||||||
|
<div class="field">
|
||||||
|
<textarea name="content" placeholder="{{$.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> {{$.i18n.Tr "repo.diff.comment.markdown_info"}}</span>
|
||||||
|
<div class="ui right floated">
|
||||||
|
{{if $.CurrentReview}}
|
||||||
|
<button name="is_review" value="true" type="submit"
|
||||||
|
class="ui submit green tiny button btn-add-comment">{{$.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">{{$.i18n.Tr "repo.diff.comment.start_review"}}</button>
|
||||||
|
{{end}}
|
||||||
|
<button type="submit"
|
||||||
|
class="ui submit tiny basic button btn-add-single">{{$.i18n.Tr "repo.diff.comment.add_single_comment"}}</button>
|
||||||
|
<button type="button" class="ui submit tiny basic button btn-cancel">{{$.i18n.Tr "cancel"}}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
51
templates/repo/diff/comments.tmpl
Normal file
51
templates/repo/diff/comments.tmpl
Normal file
@ -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}}
|
@ -1,33 +1,3 @@
|
|||||||
<div class="field comment-code-cloud">
|
<div class="field comment-code-cloud">
|
||||||
<form class="ui form" action="{{.Link}}" method="post">
|
{{ template "repo/diff/comment_form" .}}
|
||||||
{{.CsrfTokenHtml}}
|
|
||||||
<input type="hidden" name="side">
|
|
||||||
<input type="hidden" name="line">
|
|
||||||
<input type="hidden" name="path">
|
|
||||||
<input type="hidden" name="commit_id">
|
|
||||||
<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" data-write="write" data-preview="preview">
|
|
||||||
<a class="active item" data-tab="write">{{.i18n.Tr "write"}}</a>
|
|
||||||
<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}">{{.i18n.Tr "preview"}}</a>
|
|
||||||
</div>
|
|
||||||
<div class="ui bottom attached active tab segment" data-tab="write">
|
|
||||||
<div class="field">
|
|
||||||
<textarea name="content" placeholder="{{$.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> {{$.i18n.Tr "repo.diff.comment.markdown_info"}}</span>
|
|
||||||
<div class="ui right floated">
|
|
||||||
<div class="ui submit tiny basic button btn-cancel">{{$.i18n.Tr "cancel"}}</div>
|
|
||||||
<div class="ui submit tiny basic button btn-add-single">{{$.i18n.Tr "repo.diff.comment.add_single_comment"}}</div>
|
|
||||||
<div class="ui submit green tiny button btn-add-comment">{{$.i18n.Tr "repo.diff.comment.add_review_comment"}}</div>
|
|
||||||
<div class="ui submit green tiny button btn-start-review">{{$.i18n.Tr "repo.diff.comment.start_review"}}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,25 +1,29 @@
|
|||||||
<div class="ui top right pointing dropdown custom">
|
<div class="ui top right pointing dropdown custom" id="review-box">
|
||||||
<div class="ui tiny green button btn-review">
|
<div class="ui tiny green button btn-review">
|
||||||
<span class="text">{{.i18n.Tr "repo.diff.review"}}</span>
|
<span class="text">{{.i18n.Tr "repo.diff.review"}}</span>
|
||||||
<i class="dropdown icon"></i>
|
<i class="dropdown icon"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
<div class="ui clearing segment">
|
<div class="ui clearing segment">
|
||||||
<form class="ui form" action="{{.Link}}" method="post">
|
<form class="ui form" action="{{.Link}}/reviews/submit" method="post">
|
||||||
{{.CsrfTokenHtml}}
|
{{.CsrfTokenHtml}}
|
||||||
<div class="ui right floated">
|
<div class="ui right floated">
|
||||||
<a href="#" class="close"><i class="icon close"></i></a>
|
<button onclick="$('.btn-review').click()" type="button" class="ui tiny icon button"><i class="icon close"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
{{$.i18n.Tr "repo.diff.review.header"}}
|
{{$.i18n.Tr "repo.diff.review.header"}}
|
||||||
</div>
|
</div>
|
||||||
<div class="ui field">
|
<div class="ui field">
|
||||||
<textarea name="comment" tabindex="0" rows="2" placeholder="{{$.i18n.Tr "repo.diff.review.placeholder"}}"></textarea>
|
<textarea name="content" tabindex="0" rows="2"
|
||||||
|
placeholder="{{$.i18n.Tr "repo.diff.review.placeholder"}}"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
<div class="ui submit green tiny button btn-submit">{{$.i18n.Tr "repo.diff.review.approve"}}</div>
|
<button type="submit" name="type" value="approve"
|
||||||
<div class="ui submit tiny basic button btn-submit">{{$.i18n.Tr "repo.diff.review.comment"}}</div>
|
class="ui submit green tiny button btn-submit">{{$.i18n.Tr "repo.diff.review.approve"}}</button>
|
||||||
<div class="ui submit red tiny button btn-submit">{{$.i18n.Tr "repo.diff.review.reject"}}</div>
|
<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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{{$file := .}}
|
{{$file := .file}}
|
||||||
{{$highlightClass := $file.GetHighlightClass}}
|
{{$highlightClass := $file.GetHighlightClass}}
|
||||||
{{range $j, $section := $file.Sections}}
|
{{range $j, $section := $file.Sections}}
|
||||||
{{range $k, $line := $section.Lines}}
|
{{range $k, $line := $section.Lines}}
|
||||||
@ -20,5 +20,19 @@
|
|||||||
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
|
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{{if gt (len $line.Comments) 0}}
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="add-comment-left add-comment-right">
|
||||||
|
<div class="field comment-code-cloud">
|
||||||
|
<div class="comment-list">
|
||||||
|
<ui class="ui comments">
|
||||||
|
{{ template "repo/diff/comments" dict "root" $.root "comments" $line.Comments}}
|
||||||
|
</ui>
|
||||||
|
</div>
|
||||||
|
{{template "repo/diff/comment_form" $.root }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{{range .Issue.Comments}}
|
{{range .Issue.Comments}}
|
||||||
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.Lang }}
|
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.Lang }}
|
||||||
|
|
||||||
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 12 = START_TRACKING, 13 = STOP_TRACKING, 14 = ADD_TIME_MANUAL, 16 = ADDED_DEADLINE, 17 = MODIFIED_DEADLINE, 18 = REMOVED_DEADLINE -->
|
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 12 = START_TRACKING, 13 = STOP_TRACKING, 14 = ADD_TIME_MANUAL, 16 = ADDED_DEADLINE, 17 = MODIFIED_DEADLINE, 18 = REMOVED_DEADLINE, 19 = CODE, 20 = REVIEW -->
|
||||||
{{if eq .Type 0}}
|
{{if eq .Type 0}}
|
||||||
<div class="comment" id="{{.HashTag}}">
|
<div class="comment" id="{{.HashTag}}">
|
||||||
<a class="avatar" {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>
|
<a class="avatar" {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>
|
||||||
@ -219,5 +219,29 @@
|
|||||||
{{$.i18n.Tr "repo.issues.due_date_remove" .Content $createdStr | Safe}}
|
{{$.i18n.Tr "repo.issues.due_date_remove" .Content $createdStr | Safe}}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
{{else if eq .Type 20}}
|
||||||
|
<div class="event" id="{{.HashTag}}">
|
||||||
|
<span class="octicon octicon-{{.Review.Type.Icon}}"></span>
|
||||||
|
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
|
||||||
|
<img src="{{.Poster.RelAvatarLink}}">
|
||||||
|
</a>
|
||||||
|
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a>
|
||||||
|
{{if eq .Review.Type 1}}
|
||||||
|
{{$.i18n.Tr "repo.issues.review.approve" $createdStr | Safe}}
|
||||||
|
{{else if eq .Review.Type 2}}
|
||||||
|
{{$.i18n.Tr "repo.issues.review.comment" $createdStr | Safe}}
|
||||||
|
{{else if eq .Review.Type 3}}
|
||||||
|
{{$.i18n.Tr "repo.issues.review.reject" $createdStr | Safe}}
|
||||||
|
{{else}}
|
||||||
|
{{$.i18n.Tr "repo.issues.review.comment" $createdStr | Safe}}
|
||||||
|
{{end}}
|
||||||
|
</span>
|
||||||
|
{{if .Content}}
|
||||||
|
<div class="detail">
|
||||||
|
<span class="octicon octicon-quote"></span>
|
||||||
|
<span class="text grey">{{.Content}}</span>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
14
vendor/code.gitea.io/git/repo_blame.go
generated
vendored
14
vendor/code.gitea.io/git/repo_blame.go
generated
vendored
@ -4,7 +4,21 @@
|
|||||||
|
|
||||||
package git
|
package git
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// FileBlame return the Blame object of file
|
// FileBlame return the Blame object of file
|
||||||
func (repo *Repository) FileBlame(revision, path, file string) ([]byte, error) {
|
func (repo *Repository) FileBlame(revision, path, file string) ([]byte, error) {
|
||||||
return NewCommand("blame", "--root", file).RunInDirBytes(path)
|
return NewCommand("blame", "--root", file).RunInDirBytes(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LineBlame returns the latest commit at the given line
|
||||||
|
func (repo *Repository) LineBlame(revision, path, file string, line uint) (*Commit, error) {
|
||||||
|
res, err := NewCommand("blame", fmt.Sprintf("-L %d,%d", line, line), "-p", revision, file).RunInDir(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(res) < 40 {
|
||||||
|
return nil, fmt.Errorf("invalid result of blame: %s", res)
|
||||||
|
}
|
||||||
|
return repo.GetCommit(string(res[:40]))
|
||||||
|
}
|
||||||
|
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
@ -3,10 +3,10 @@
|
|||||||
"ignore": "test appengine",
|
"ignore": "test appengine",
|
||||||
"package": [
|
"package": [
|
||||||
{
|
{
|
||||||
"checksumSHA1": "BfL4Z7P1alyUUNspKJu7Q4GPCNs=",
|
"checksumSHA1": "jkAY8qJRd3N2isGPpoCMoq+QkBc=",
|
||||||
"path": "code.gitea.io/git",
|
"path": "code.gitea.io/git",
|
||||||
"revision": "f1ecc138bebcffed32be1a574ed0c2701b33733f",
|
"revision": "258a447de641abb5382ad9e2f166e6011dff30fc",
|
||||||
"revisionTime": "2018-04-21T01:08:19Z"
|
"revisionTime": "2018-05-13T13:21:47Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "WMD6+Qh2+5hd9uiq910pF/Ihylw=",
|
"checksumSHA1": "WMD6+Qh2+5hd9uiq910pF/Ihylw=",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user