diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-27 12:48:29 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-27 12:48:29 -0400 |
commit | 3144fac03cb468aa28c0ade7687b1d4df1de6abb (patch) | |
tree | cb17846a0d9ca04f3cdfc0d5d27d25c4ff09bce7 /models/issue.go | |
parent | 442996f03200e5c8dce6f8d428426e8a6c3db051 (diff) | |
download | gitea-3144fac03cb468aa28c0ade7687b1d4df1de6abb.tar.gz gitea-3144fac03cb468aa28c0ade7687b1d4df1de6abb.zip |
IP: RC Code Review
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 25 |
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. |