summaryrefslogtreecommitdiffstats
path: root/models/issue.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.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.go')
-rw-r--r--models/issue.go57
1 files changed, 52 insertions, 5 deletions
diff --git a/models/issue.go b/models/issue.go
index 87e64ce99b..bb2db94407 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -595,8 +595,9 @@ func (issue *Issue) ClearLabels(doer *User) (err error) {
if err = sess.Commit(); err != nil {
return fmt.Errorf("Commit: %v", err)
}
+ sess.Close()
- if err = issue.loadPoster(x); err != nil {
+ if err = issue.LoadPoster(); err != nil {
return fmt.Errorf("loadPoster: %v", err)
}
@@ -870,9 +871,18 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
return fmt.Errorf("createChangeTitleComment: %v", err)
}
+ if err = issue.neuterCrossReferences(sess); err != nil {
+ return err
+ }
+
+ if err = issue.addCrossReferences(sess, doer); err != nil {
+ return err
+ }
+
if err = sess.Commit(); err != nil {
return err
}
+ sess.Close()
mode, _ := AccessLevel(issue.Poster, issue.Repo)
if issue.IsPull {
@@ -939,9 +949,26 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
oldContent := issue.Content
issue.Content = content
- if err = UpdateIssueCols(issue, "content"); err != nil {
+ sess := x.NewSession()
+ defer sess.Close()
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ if err = updateIssueCols(sess, issue, "content"); err != nil {
return fmt.Errorf("UpdateIssueCols: %v", err)
}
+ if err = issue.neuterCrossReferences(sess); err != nil {
+ return err
+ }
+ if err = issue.addCrossReferences(sess, doer); err != nil {
+ return err
+ }
+
+ if err = sess.Commit(); err != nil {
+ return err
+ }
+ sess.Close()
mode, _ := AccessLevel(issue.Poster, issue.Repo)
if issue.IsPull {
@@ -1171,8 +1198,10 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
}
}
}
-
- return opts.Issue.loadAttributes(e)
+ if err = opts.Issue.loadAttributes(e); err != nil {
+ return err
+ }
+ return opts.Issue.addCrossReferences(e, doer)
}
// NewIssue creates new issue with labels for repository.
@@ -1199,6 +1228,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, assigneeIDs []in
if err = sess.Commit(); err != nil {
return fmt.Errorf("Commit: %v", err)
}
+ sess.Close()
if err = NotifyWatchers(&Action{
ActUserID: issue.Poster.ID,
@@ -1808,7 +1838,24 @@ func updateIssue(e Engine, issue *Issue) error {
// UpdateIssue updates all fields of given issue.
func UpdateIssue(issue *Issue) error {
- return updateIssue(x, issue)
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+ if err := updateIssue(sess, issue); err != nil {
+ return err
+ }
+ if err := issue.neuterCrossReferences(sess); err != nil {
+ return err
+ }
+ if err := issue.loadPoster(sess); err != nil {
+ return err
+ }
+ if err := issue.addCrossReferences(sess, issue.Poster); err != nil {
+ return err
+ }
+ return sess.Commit()
}
// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.