diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-19 21:39:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 21:39:57 +0800 |
commit | fc3d0826096943b979717ed46c9a4cfd86e06106 (patch) | |
tree | 3143882ccf4dea3a8bf2a0de9c8da9a4efec26ce /models/issue_dependency.go | |
parent | 7a0347315995b25bcb2dca4786504fb699b5f004 (diff) | |
download | gitea-fc3d0826096943b979717ed46c9a4cfd86e06106.tar.gz gitea-fc3d0826096943b979717ed46c9a4cfd86e06106.zip |
Move attachment into models/repo/ (#17650)
* Move attachment into models/repo/
* Fix test
* Fix bug
Diffstat (limited to 'models/issue_dependency.go')
-rw-r--r-- | models/issue_dependency.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/models/issue_dependency.go b/models/issue_dependency.go index f58bb3da0a..ee984fbe3e 100644 --- a/models/issue_dependency.go +++ b/models/issue_dependency.go @@ -37,11 +37,12 @@ const ( // CreateIssueDependency creates a new dependency for an issue func CreateIssueDependency(user *User, issue, dep *Issue) error { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() + sess := db.GetEngine(ctx) // Check if it aleready exists exists, err := issueDepExists(sess, issue.ID, dep.ID) @@ -69,20 +70,20 @@ func CreateIssueDependency(user *User, issue, dep *Issue) error { } // Add comment referencing the new dependency - if err = createIssueDependencyComment(sess, user, issue, dep, true); err != nil { + if err = createIssueDependencyComment(ctx, user, issue, dep, true); err != nil { return err } - return sess.Commit() + return committer.Commit() } // RemoveIssueDependency removes a dependency from an issue func RemoveIssueDependency(user *User, issue, dep *Issue, depType DependencyType) (err error) { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err = sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() var issueDepToDelete IssueDependency @@ -95,7 +96,7 @@ func RemoveIssueDependency(user *User, issue, dep *Issue, depType DependencyType return ErrUnknownDependencyType{depType} } - affected, err := sess.Delete(&issueDepToDelete) + affected, err := db.GetEngine(ctx).Delete(&issueDepToDelete) if err != nil { return err } @@ -106,10 +107,10 @@ func RemoveIssueDependency(user *User, issue, dep *Issue, depType DependencyType } // Add comment referencing the removed dependency - if err = createIssueDependencyComment(sess, user, issue, dep, false); err != nil { + if err = createIssueDependencyComment(ctx, user, issue, dep, false); err != nil { return err } - return sess.Commit() + return committer.Commit() } // Check if the dependency already exists |