summaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go36
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()
}