|
7 | 7 | package models
|
8 | 8 |
|
9 | 9 | import (
|
10 |
| - "bytes" |
11 | 10 | "fmt"
|
12 | 11 | "strings"
|
13 | 12 |
|
14 | 13 | "code.gitea.io/gitea/modules/git"
|
15 | 14 | "code.gitea.io/gitea/modules/log"
|
16 | 15 | "code.gitea.io/gitea/modules/markup"
|
17 | 16 | "code.gitea.io/gitea/modules/markup/markdown"
|
18 |
| - "code.gitea.io/gitea/modules/setting" |
19 | 17 | api "code.gitea.io/gitea/modules/structs"
|
20 | 18 | "code.gitea.io/gitea/modules/timeutil"
|
21 | 19 |
|
@@ -488,32 +486,6 @@ func (c *Comment) UnsignedLine() uint64 {
|
488 | 486 | return uint64(c.Line)
|
489 | 487 | }
|
490 | 488 |
|
491 |
| -// AsDiff returns c.Patch as *Diff |
492 |
| -func (c *Comment) AsDiff() (*Diff, error) { |
493 |
| - diff, err := ParsePatch(setting.Git.MaxGitDiffLines, |
494 |
| - setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.Patch)) |
495 |
| - if err != nil { |
496 |
| - return nil, err |
497 |
| - } |
498 |
| - if len(diff.Files) == 0 { |
499 |
| - return nil, fmt.Errorf("no file found for comment ID: %d", c.ID) |
500 |
| - } |
501 |
| - secs := diff.Files[0].Sections |
502 |
| - if len(secs) == 0 { |
503 |
| - return nil, fmt.Errorf("no sections found for comment ID: %d", c.ID) |
504 |
| - } |
505 |
| - return diff, nil |
506 |
| -} |
507 |
| - |
508 |
| -// MustAsDiff executes AsDiff and logs the error instead of returning |
509 |
| -func (c *Comment) MustAsDiff() *Diff { |
510 |
| - diff, err := c.AsDiff() |
511 |
| - if err != nil { |
512 |
| - log.Warn("MustAsDiff: %v", err) |
513 |
| - } |
514 |
| - return diff |
515 |
| -} |
516 |
| - |
517 | 489 | // CodeCommentURL returns the url to a comment in code
|
518 | 490 | func (c *Comment) CodeCommentURL() string {
|
519 | 491 | err := c.LoadIssue()
|
@@ -873,59 +845,6 @@ func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content stri
|
873 | 845 | return comment, nil
|
874 | 846 | }
|
875 | 847 |
|
876 |
| -// CreateCodeComment creates a plain code comment at the specified line / path |
877 |
| -func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, treePath string, line, reviewID int64) (*Comment, error) { |
878 |
| - var commitID, patch string |
879 |
| - pr, err := GetPullRequestByIssueID(issue.ID) |
880 |
| - if err != nil { |
881 |
| - return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err) |
882 |
| - } |
883 |
| - if err := pr.GetBaseRepo(); err != nil { |
884 |
| - return nil, fmt.Errorf("GetHeadRepo: %v", err) |
885 |
| - } |
886 |
| - gitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath()) |
887 |
| - if err != nil { |
888 |
| - return nil, fmt.Errorf("OpenRepository: %v", err) |
889 |
| - } |
890 |
| - |
891 |
| - // FIXME validate treePath |
892 |
| - // Get latest commit referencing the commented line |
893 |
| - // No need for get commit for base branch changes |
894 |
| - if line > 0 { |
895 |
| - commit, err := gitRepo.LineBlame(pr.GetGitRefName(), gitRepo.Path, treePath, uint(line)) |
896 |
| - if err == nil { |
897 |
| - commitID = commit.ID.String() |
898 |
| - } else if !strings.Contains(err.Error(), "exit status 128 - fatal: no such path") { |
899 |
| - return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %v", pr.GetGitRefName(), gitRepo.Path, treePath, line, err) |
900 |
| - } |
901 |
| - } |
902 |
| - |
903 |
| - // Only fetch diff if comment is review comment |
904 |
| - if reviewID != 0 { |
905 |
| - headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) |
906 |
| - if err != nil { |
907 |
| - return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err) |
908 |
| - } |
909 |
| - patchBuf := new(bytes.Buffer) |
910 |
| - if err := GetRawDiffForFile(gitRepo.Path, pr.MergeBase, headCommitID, RawDiffNormal, treePath, patchBuf); err != nil { |
911 |
| - return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", err, gitRepo.Path, pr.MergeBase, headCommitID, treePath) |
912 |
| - } |
913 |
| - patch = CutDiffAroundLine(patchBuf, int64((&Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines) |
914 |
| - } |
915 |
| - return CreateComment(&CreateCommentOptions{ |
916 |
| - Type: CommentTypeCode, |
917 |
| - Doer: doer, |
918 |
| - Repo: repo, |
919 |
| - Issue: issue, |
920 |
| - Content: content, |
921 |
| - LineNum: line, |
922 |
| - TreePath: treePath, |
923 |
| - CommitSHA: commitID, |
924 |
| - ReviewID: reviewID, |
925 |
| - Patch: patch, |
926 |
| - }) |
927 |
| -} |
928 |
| - |
929 | 848 | // CreateRefComment creates a commit reference comment to issue.
|
930 | 849 | func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
|
931 | 850 | if len(commitSHA) == 0 {
|
|
0 commit comments