summaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-27 12:48:29 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-27 12:48:29 -0400
commit3144fac03cb468aa28c0ade7687b1d4df1de6abb (patch)
treecb17846a0d9ca04f3cdfc0d5d27d25c4ff09bce7 /models/issue.go
parent442996f03200e5c8dce6f8d428426e8a6c3db051 (diff)
downloadgitea-3144fac03cb468aa28c0ade7687b1d4df1de6abb.tar.gz
gitea-3144fac03cb468aa28c0ade7687b1d4df1de6abb.zip
IP: RC Code Review
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/models/issue.go b/models/issue.go
index 97e51a0c58..6b657b7b90 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -37,7 +37,7 @@ type Issue struct {
}
// CreateIssue creates new issue for repository.
-func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, content string, isPull bool) (*Issue, error) {
+func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int, name, labels, content string, isPull bool) (*Issue, error) {
count, err := GetIssueCount(repoId)
if err != nil {
return nil, err
@@ -46,6 +46,10 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, co
// TODO: find out mentions
mentions := ""
+ sess := orm.NewSession()
+ defer sess.Close()
+ sess.Begin()
+
issue := &Issue{
Index: count + 1,
Name: name,
@@ -58,8 +62,23 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, co
Mentions: mentions,
Content: content,
}
- _, err = orm.Insert(issue)
- return issue, err
+ if _, err = sess.Insert(issue); err != nil {
+ sess.Rollback()
+ return nil, err
+ }
+
+ rawSql := "UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?"
+ if _, err = sess.Exec(rawSql, repoId); err != nil {
+ sess.Rollback()
+ return nil, err
+ }
+
+ if err = sess.Commit(); err != nil {
+ sess.Rollback()
+ return nil, err
+ }
+
+ return issue, nil
}
// GetIssueCount returns count of issues in the repository.