Fix some notification bugs, fix link
This commit is contained in:
parent
dbc7aee713
commit
a0d9afd0da
|
|
@ -368,7 +368,7 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
|
||||||
// headers + hunk header
|
// headers + hunk header
|
||||||
newHunk := make([]string, headerLines)
|
newHunk := make([]string, headerLines)
|
||||||
// transfer existing headers
|
// transfer existing headers
|
||||||
for idx, lof := range hunk[:numbersOfLine] {
|
for idx, lof := range hunk[:headerLines] {
|
||||||
newHunk[idx] = lof
|
newHunk[idx] = lof
|
||||||
}
|
}
|
||||||
// transfer last n lines
|
// transfer last n lines
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,19 @@ func (c *Comment) HTMLURL() string {
|
||||||
log.Error(4, "LoadIssue(%d): %v", c.IssueID, err)
|
log.Error(4, "LoadIssue(%d): %v", c.IssueID, err)
|
||||||
return ""
|
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())
|
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.
|
// Check comment type.
|
||||||
switch opts.Type {
|
switch opts.Type {
|
||||||
case CommentTypeCode:
|
case CommentTypeCode:
|
||||||
if comment.Review != nil && comment.Review.Type <= ReviewTypePending {
|
if comment.ReviewID != 0 {
|
||||||
break
|
if comment.Review == nil {
|
||||||
|
if err := comment.LoadReview(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if comment.Review.Type <= ReviewTypePending {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
case CommentTypeComment:
|
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
|
// 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) {
|
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)
|
pr, err := GetPullRequestByIssueID(issue.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err)
|
return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err)
|
||||||
|
|
@ -760,6 +781,8 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Only fetch diff if comment is review comment
|
||||||
|
if reviewID != 0 {
|
||||||
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -768,8 +791,9 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree
|
||||||
if err := GetRawDiffForFile(gitRepo.Path, pr.MergeBase, headCommitID, RawDiffNormal, treePath, patchBuf); err != nil {
|
if err := GetRawDiffForFile(gitRepo.Path, pr.MergeBase, headCommitID, RawDiffNormal, treePath, patchBuf); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
patch := CutDiffAroundLine(strings.NewReader(patchBuf.String()), int64((&Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
|
patch = CutDiffAroundLine(strings.NewReader(patchBuf.String()), int64((&Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
|
||||||
|
commitID = commit.ID.String()
|
||||||
|
}
|
||||||
return CreateComment(&CreateCommentOptions{
|
return CreateComment(&CreateCommentOptions{
|
||||||
Type: CommentTypeCode,
|
Type: CommentTypeCode,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
|
|
@ -778,7 +802,7 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree
|
||||||
Content: content,
|
Content: content,
|
||||||
LineNum: line,
|
LineNum: line,
|
||||||
TreePath: treePath,
|
TreePath: treePath,
|
||||||
CommitSHA: commit.ID.String(),
|
CommitSHA: commitID,
|
||||||
ReviewID: reviewID,
|
ReviewID: reviewID,
|
||||||
Patch: patch,
|
Patch: patch,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
|
||||||
var comment *models.Comment
|
var comment *models.Comment
|
||||||
defer func() {
|
defer func() {
|
||||||
if comment != nil {
|
if comment != nil {
|
||||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files#%s", ctx.Repo.RepoLink, issue.Index, comment.HashTag()))
|
ctx.Redirect(comment.HTMLURL())
|
||||||
} else {
|
} else {
|
||||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
|
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user