Finish close and reopen issue, install page, ready going to test stage of v0.2.0

This commit is contained in:
Unknown 2014-03-29 17:50:51 -04:00
parent 1f671e5d29
commit 107a1eadac
15 changed files with 315 additions and 161 deletions

View file

@ -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()
}

View file

@ -34,8 +34,7 @@ func LoadModelsConfig() {
DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db")
}
func SetEngine() {
var err error
func SetEngine() (err error) {
switch DbCfg.Type {
case "mysql":
orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",
@ -47,12 +46,10 @@ func SetEngine() {
os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
orm, err = xorm.NewEngine("sqlite3", DbCfg.Path)
default:
fmt.Printf("Unknown database type: %s\n", DbCfg.Type)
os.Exit(2)
return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type)
}
if err != nil {
fmt.Printf("models.init(fail to conntect database): %v\n", err)
os.Exit(2)
return fmt.Errorf("models.init(fail to conntect database): %v\n", err)
}
// WARNNING: for serv command, MUST remove the output to os.stdout,
@ -62,20 +59,21 @@ func SetEngine() {
//orm.ShowErr = true
f, err := os.Create("xorm.log")
if err != nil {
fmt.Printf("models.init(fail to create xorm.log): %v\n", err)
os.Exit(2)
return fmt.Errorf("models.init(fail to create xorm.log): %v\n", err)
}
orm.Logger = f
orm.ShowSQL = true
return nil
}
func NewEngine() {
SetEngine()
if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
func NewEngine() (err error) {
if err = SetEngine(); err != nil {
return err
} else if err = orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
new(Action), new(Access), new(Issue), new(Comment)); err != nil {
fmt.Printf("sync database struct error: %v\n", err)
os.Exit(2)
return fmt.Errorf("sync database struct error: %v\n", err)
}
return nil
}
type Statistic struct {

View file

@ -11,7 +11,6 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"time"
"unicode/utf8"
@ -59,15 +58,6 @@ func NewRepoContext() {
os.Exit(2)
}
}
// Initialize illegal patterns.
for i := range illegalPatterns[1:] {
pattern := ""
for j := range illegalPatterns[i+1] {
pattern += "[" + string(illegalPatterns[i+1][j]-32) + string(illegalPatterns[i+1][j]) + "]"
}
illegalPatterns[i+1] = pattern
}
}
// Repository represents a git repository.
@ -105,15 +95,20 @@ func IsRepositoryExist(user *User, repoName string) (bool, error) {
}
var (
// Define as all lower case!!
illegalPatterns = []string{"[.][Gg][Ii][Tt]", "raw", "user", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin"}
illegalEquals = []string{"raw", "install", "api", "avatar", "user", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin"}
illegalSuffixs = []string{".git"}
)
// IsLegalName returns false if name contains illegal characters.
func IsLegalName(repoName string) bool {
for _, pattern := range illegalPatterns {
has, _ := regexp.MatchString(pattern, repoName)
if has {
repoName = strings.ToLower(repoName)
for _, char := range illegalEquals {
if repoName == char {
return false
}
}
for _, char := range illegalSuffixs {
if strings.HasSuffix(repoName, char) {
return false
}
}