mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-20 14:00:04 +02:00
Finish close and reopen issue, install page, ready going to test stage of v0.2.0
This commit is contained in:
parent
1f671e5d29
commit
107a1eadac
15 changed files with 315 additions and 161 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue