Fix some notification bugs, fix link

This commit is contained in:
Jonas Franz 2018-07-06 19:25:29 +02:00
parent dbc7aee713
commit a0d9afd0da
No known key found for this signature in database
GPG Key ID: 506AEEBE80BEDECD
3 changed files with 38 additions and 14 deletions

View File

@ -368,7 +368,7 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
// headers + hunk header
newHunk := make([]string, headerLines)
// transfer existing headers
for idx, lof := range hunk[:numbersOfLine] {
for idx, lof := range hunk[:headerLines] {
newHunk[idx] = lof
}
// transfer last n lines

View File

@ -181,6 +181,19 @@ func (c *Comment) HTMLURL() string {
log.Error(4, "LoadIssue(%d): %v", c.IssueID, err)
return ""
}
if c.Type == CommentTypeCode {
if c.ReviewID == 0 {
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
}
if c.Review == nil {
if err := c.LoadReview(); err != nil {
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
}
}
if c.Review.Type <= ReviewTypePending {
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
}
}
return fmt.Sprintf("%s#%s", c.Issue.HTMLURL(), c.HashTag())
}
@ -482,8 +495,15 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen
// Check comment type.
switch opts.Type {
case CommentTypeCode:
if comment.Review != nil && comment.Review.Type <= ReviewTypePending {
break
if comment.ReviewID != 0 {
if comment.Review == nil {
if err := comment.LoadReview(); err != nil {
return err
}
}
if comment.Review.Type <= ReviewTypePending {
return nil
}
}
fallthrough
case CommentTypeComment:
@ -738,6 +758,7 @@ 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) {
var commitID, patch string
pr, err := GetPullRequestByIssueID(issue.ID)
if err != nil {
return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err)
@ -760,16 +781,19 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree
if err != nil {
return nil, err
}
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil {
return nil, err
// Only fetch diff if comment is review comment
if reviewID != 0 {
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil {
return nil, err
}
patchBuf := new(bytes.Buffer)
if err := GetRawDiffForFile(gitRepo.Path, pr.MergeBase, headCommitID, RawDiffNormal, treePath, patchBuf); err != nil {
return nil, err
}
patch = CutDiffAroundLine(strings.NewReader(patchBuf.String()), int64((&Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
commitID = commit.ID.String()
}
patchBuf := new(bytes.Buffer)
if err := GetRawDiffForFile(gitRepo.Path, pr.MergeBase, headCommitID, RawDiffNormal, treePath, patchBuf); err != nil {
return nil, err
}
patch := CutDiffAroundLine(strings.NewReader(patchBuf.String()), int64((&Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
return CreateComment(&CreateCommentOptions{
Type: CommentTypeCode,
Doer: doer,
@ -778,7 +802,7 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree
Content: content,
LineNum: line,
TreePath: treePath,
CommitSHA: commit.ID.String(),
CommitSHA: commitID,
ReviewID: reviewID,
Patch: patch,
})

View File

@ -32,7 +32,7 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
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()))
ctx.Redirect(comment.HTMLURL())
} else {
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
}