diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-29 17:50:51 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-29 17:50:51 -0400 |
commit | 107a1eadac72e610a9bcb68498751ca51ec8f51a (patch) | |
tree | 07830d247f89887882427c0bb910178bde4298ce /models/issue.go | |
parent | 1f671e5d2900497e2c81e8123cc47fe7ca5ad371 (diff) | |
download | gitea-107a1eadac72e610a9bcb68498751ca51ec8f51a.tar.gz gitea-107a1eadac72e610a9bcb68498751ca51ec8f51a.zip |
Finish close and reopen issue, install page, ready going to test stage of v0.2.0
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/models/issue.go b/models/issue.go index 9fd1b905a5..f14030df5e 100644 --- a/models/issue.go +++ b/models/issue.go @@ -170,9 +170,17 @@ type Milestone struct { Created time.Time `xorm:"created"` } +// Issue types. +const ( + IT_PLAIN = iota // Pure comment. + IT_REOPEN // Issue reopen status change prompt. + IT_CLOSE // Issue close status change prompt. +) + // Comment represents a comment in commit and issue page. type Comment struct { Id int64 + Type int PosterId int64 Poster *User `xorm:"-"` IssueId int64 @@ -183,21 +191,37 @@ type Comment struct { } // CreateComment creates comment of issue or commit. -func CreateComment(userId, issueId, commitId, line int64, content string) error { +func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, content string) error { sess := orm.NewSession() defer sess.Close() sess.Begin() - if _, err := orm.Insert(&Comment{PosterId: userId, IssueId: issueId, + if _, err := orm.Insert(&Comment{PosterId: userId, Type: cmtType, IssueId: issueId, CommitId: commitId, Line: line, Content: content}); err != nil { sess.Rollback() return err } - rawSql := "UPDATE `issue` SET num_comments = num_comments + 1 WHERE id = ?" - if _, err := sess.Exec(rawSql, issueId); err != nil { - sess.Rollback() - return err + // Check comment type. + switch cmtType { + case IT_PLAIN: + rawSql := "UPDATE `issue` SET num_comments = num_comments + 1 WHERE id = ?" + if _, err := sess.Exec(rawSql, issueId); err != nil { + sess.Rollback() + return err + } + case IT_REOPEN: + rawSql := "UPDATE `repository` SET num_closed_issues = num_closed_issues - 1 WHERE id = ?" + if _, err := sess.Exec(rawSql, repoId); err != nil { + sess.Rollback() + return err + } + case IT_CLOSE: + rawSql := "UPDATE `repository` SET num_closed_issues = num_closed_issues + 1 WHERE id = ?" + if _, err := sess.Exec(rawSql, repoId); err != nil { + sess.Rollback() + return err + } } return sess.Commit() } |