aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_comment.go
diff options
context:
space:
mode:
authorguillep2k <18600385+guillep2k@users.noreply.github.com>2019-09-20 02:45:38 -0300
committertechknowlogick <techknowlogick@gitea.io>2019-09-20 01:45:38 -0400
commit2a2b46c62ee0ac2b42b8bd0f28e05642d0cee25b (patch)
tree1b71938c5d9931808c336062859f6c1fb82b9c7a /models/issue_comment.go
parent8a0379d68aa723be9cf1b304068e6b0d098b8a6d (diff)
downloadgitea-2a2b46c62ee0ac2b42b8bd0f28e05642d0cee25b.tar.gz
gitea-2a2b46c62ee0ac2b42b8bd0f28e05642d0cee25b.zip
Reference issues from pull requests and other issues (#8137)
* Update ref comment * Generate comment on simple ref * Make fmt + remove unneeded repo load * Add TODO comments * Add ref-check in issue creation; re-arrange template * Make unit tests pass; rearrange code * Make fmt * Filter out xref comment if user can't see the referencing issue * Add TODOs * Add cross reference * Rearrange code; add cross-repository references * Striketrhough obsolete references * Remove unnecesary TODO * Add "not supported" note * Support for edits and deletes, and issue title * Revert changes to go.mod * Fix fmt * Add support for xref from API * Add first integration test * Add integration tests * Correct formatting * Fix add comment test * Add migration * Remove outdated comments; fix typo * Some code refactoring and rearranging * Rename findCrossReferences to createCrossReferences * Delete xrefs when repository is deleted * Corrections as suggested by @lafriks * Prepare for merge * Fix log for errors
Diffstat (limited to 'models/issue_comment.go')
-rw-r--r--models/issue_comment.go61
1 files changed, 55 insertions, 6 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go
index 2a9e8596cb..0bb313c30b 100644
--- a/models/issue_comment.go
+++ b/models/issue_comment.go
@@ -142,14 +142,30 @@ type Comment struct {
Review *Review `xorm:"-"`
ReviewID int64 `xorm:"index"`
Invalidated bool
+
+ // Reference an issue or pull from another comment, issue or PR
+ // All information is about the origin of the reference
+ RefRepoID int64 `xorm:"index"` // Repo where the referencing
+ RefIssueID int64 `xorm:"index"`
+ RefCommentID int64 `xorm:"index"` // 0 if origin is Issue title or content (or PR's)
+ RefAction XRefAction `xorm:"SMALLINT"` // What hapens if RefIssueID resolves
+ RefIsPull bool
+
+ RefRepo *Repository `xorm:"-"`
+ RefIssue *Issue `xorm:"-"`
+ RefComment *Comment `xorm:"-"`
}
// LoadIssue loads issue from database
func (c *Comment) LoadIssue() (err error) {
+ return c.loadIssue(x)
+}
+
+func (c *Comment) loadIssue(e Engine) (err error) {
if c.Issue != nil {
return nil
}
- c.Issue, err = GetIssueByID(c.IssueID)
+ c.Issue, err = getIssueByID(e, c.IssueID)
return
}
@@ -527,6 +543,11 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
TreePath: opts.TreePath,
ReviewID: opts.ReviewID,
Patch: opts.Patch,
+ RefRepoID: opts.RefRepoID,
+ RefIssueID: opts.RefIssueID,
+ RefCommentID: opts.RefCommentID,
+ RefAction: opts.RefAction,
+ RefIsPull: opts.RefIsPull,
}
if _, err = e.Insert(comment); err != nil {
return nil, err
@@ -540,6 +561,10 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
return nil, err
}
+ if err = comment.addCrossReferences(e, opts.Doer); err != nil {
+ return nil, err
+ }
+
return comment, nil
}
@@ -794,6 +819,11 @@ type CreateCommentOptions struct {
ReviewID int64
Content string
Attachments []string // UUIDs of attachments
+ RefRepoID int64
+ RefIssueID int64
+ RefCommentID int64
+ RefAction XRefAction
+ RefIsPull bool
}
// CreateComment creates comment of issue or commit.
@@ -934,21 +964,33 @@ func FindComments(opts FindCommentsOptions) ([]*Comment, error) {
// UpdateComment updates information of comment.
func UpdateComment(doer *User, c *Comment, oldContent string) error {
- if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
return err
}
- if err := c.LoadPoster(); err != nil {
+ if _, err := sess.ID(c.ID).AllCols().Update(c); err != nil {
return err
}
- if err := c.LoadIssue(); err != nil {
+ if err := c.loadIssue(sess); err != nil {
return err
}
+ if err := c.neuterCrossReferences(sess); err != nil {
+ return err
+ }
+ if err := c.addCrossReferences(sess, doer); err != nil {
+ return err
+ }
+ if err := sess.Commit(); err != nil {
+ return fmt.Errorf("Commit: %v", err)
+ }
+ sess.Close()
- if err := c.Issue.LoadAttributes(); err != nil {
+ if err := c.LoadPoster(); err != nil {
return err
}
- if err := c.loadPoster(x); err != nil {
+ if err := c.Issue.LoadAttributes(); err != nil {
return err
}
@@ -996,6 +1038,10 @@ func DeleteComment(doer *User, comment *Comment) error {
return err
}
+ if err := comment.neuterCrossReferences(sess); err != nil {
+ return err
+ }
+
if err := sess.Commit(); err != nil {
return err
}
@@ -1014,6 +1060,9 @@ func DeleteComment(doer *User, comment *Comment) error {
if err := comment.loadPoster(x); err != nil {
return err
}
+ if err := comment.neuterCrossReferences(x); err != nil {
+ return err
+ }
mode, _ := AccessLevel(doer, comment.Issue.Repo)