diff --git a/README.md b/README.md index 35044927f..89a346d60 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language. Since we choose to use pure Go implementation of Git manipulation, Gogs certainly supports **ALL platforms** that Go supports, including Linux, Max OS X, and Windows with **ZERO** dependency. -##### Current version: 0.1.5 Alpha +##### Current version: 0.1.6 Alpha ## Purpose diff --git a/models/action.go b/models/action.go index a996e16aa..cfb124363 100644 --- a/models/action.go +++ b/models/action.go @@ -30,7 +30,7 @@ type Action struct { ActUserName string // Action user name. RepoId int64 RepoName string - Content string + Content string `xorm:"TEXT"` Created time.Time `xorm:"created"` } diff --git a/models/issue.go b/models/issue.go index 0b6ca4c32..f78c240cb 100644 --- a/models/issue.go +++ b/models/issue.go @@ -5,12 +5,17 @@ package models import ( + "errors" "strings" "time" "github.com/gogits/gogs/modules/base" ) +var ( + ErrIssueNotExist = errors.New("Issue does not exist") +) + // Issue represents an issue or pull request of repository. type Issue struct { Id int64 @@ -22,22 +27,25 @@ type Issue struct { AssigneeId int64 IsPull bool // Indicates whether is a pull request or not. IsClosed bool - Labels string - Mentions string - Content string + Labels string `xorm:"TEXT"` + Mentions string `xorm:"TEXT"` + Content string `xorm:"TEXT"` NumComments int Created time.Time `xorm:"created"` Updated time.Time `xorm:"updated"` } // CreateIssue creates new issue for repository. -func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, mentions, content string, isPull bool) error { +func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, content string, isPull bool) (*Issue, error) { count, err := GetIssueCount(repoId) if err != nil { - return err + return nil, err } - _, err = orm.Insert(&Issue{ + // TODO: find out mentions + mentions := "" + + issue := &Issue{ Index: count + 1, Name: name, RepoId: repoId, @@ -48,8 +56,9 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, me Labels: labels, Mentions: mentions, Content: content, - }) - return err + } + _, err = orm.Insert(issue) + return issue, err } // GetIssueCount returns count of issues in the repository. @@ -57,9 +66,28 @@ func GetIssueCount(repoId int64) (int64, error) { return orm.Count(&Issue{RepoId: repoId}) } +// GetIssueById returns issue object by given id. +func GetIssueById(id int64) (*Issue, error) { + issue := new(Issue) + has, err := orm.Id(id).Get(issue) + if err != nil { + return nil, err + } else if !has { + return nil, ErrIssueNotExist + } + return issue, nil +} + // GetIssues returns a list of issues by given conditions. func GetIssues(userId, repoId, posterId, milestoneId int64, page int, isClosed, isMention bool, labels, sortType string) ([]Issue, error) { - sess := orm.Limit(20, (page-1)*20).Where("repo_id=?", repoId).And("is_closed=?", isClosed) + sess := orm.Limit(20, (page-1)*20) + + if repoId > 0 { + sess = sess.Where("repo_id=?", repoId).And("is_closed=?", isClosed) + } else { + sess = sess.Where("is_closed=?", isClosed) + } + if userId > 0 { sess = sess.And("assignee_id=?", userId) } else if posterId > 0 { diff --git a/models/publickey.go b/models/publickey.go index 9e7cc6f74..3f2fcabd3 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -80,7 +80,7 @@ type PublicKey struct { OwnerId int64 `xorm:"index"` Name string `xorm:"unique not null"` Fingerprint string - Content string `xorm:"text not null"` + Content string `xorm:"TEXT not null"` Created time.Time `xorm:"created"` Updated time.Time `xorm:"updated"` } diff --git a/models/repo.go b/models/repo.go index 317f936ec..a37923c8b 100644 --- a/models/repo.go +++ b/models/repo.go @@ -372,6 +372,13 @@ func RepoPath(userName, repoName string) string { } func UpdateRepository(repo *Repository) error { + if len(repo.Description) > 255 { + repo.Description = repo.Description[:255] + } + if len(repo.Website) > 255 { + repo.Website = repo.Website[:255] + } + _, err := orm.Id(repo.Id).UseBool().Cols("description", "website").Update(repo) return err } diff --git a/models/user.go b/models/user.go index 88c29ae43..9333d1ee6 100644 --- a/models/user.go +++ b/models/user.go @@ -201,6 +201,13 @@ func VerifyUserActiveCode(code string) (user *User) { // UpdateUser updates user's information. func UpdateUser(user *User) (err error) { + if len(user.Location) > 255 { + user.Location = user.Location[:255] + } + if len(user.Website) > 255 { + user.Website = user.Website[:255] + } + _, err = orm.Id(user.Id).UseBool().Cols("website", "location").Update(user) return err } diff --git a/modules/auth/issue.go b/modules/auth/issue.go new file mode 100644 index 000000000..e2b1f9f2a --- /dev/null +++ b/modules/auth/issue.go @@ -0,0 +1,54 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package auth + +import ( + "net/http" + "reflect" + + "github.com/codegangsta/martini" + + "github.com/gogits/binding" + + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" +) + +type CreateIssueForm struct { + IssueName string `form:"name" binding:"Required;MaxSize(50)"` + RepoId int64 `form:"repoid" binding:"Required"` + MilestoneId int64 `form:"milestoneid" binding:"Required"` + AssigneeId int64 `form:"assigneeid"` + Labels string `form:"labels"` + Content string `form:"content"` +} + +func (f *CreateIssueForm) Name(field string) string { + names := map[string]string{ + "IssueName": "Issue name", + "RepoId": "Repository ID", + "MilestoneId": "Milestone ID", + } + return names[field] +} + +func (f *CreateIssueForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { + if req.Method == "GET" || errors.Count() == 0 { + return + } + + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + data["HasError"] = true + AssignForm(f, data) + + if len(errors.Overall) > 0 { + for _, err := range errors.Overall { + log.Error("CreateIssueForm.Validate: %v", err) + } + return + } + + validate(errors, data, f) +} diff --git a/routers/repo/issue.go b/routers/repo/issue.go index eee55c6fd..154e8308a 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -5,14 +5,19 @@ package repo import ( + "fmt" + "github.com/codegangsta/martini" "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" ) func Issues(ctx *middleware.Context, params martini.Params) { + ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true milestoneId, _ := base.StrTo(params["milestone"]).Int() @@ -29,12 +34,52 @@ func Issues(ctx *middleware.Context, params martini.Params) { ctx.HTML(200, "repo/issues") } -func CreateIssue(ctx *middleware.Context, params martini.Params) { +func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { if !ctx.Repo.IsOwner { ctx.Error(404) return } - // else if err = models.CreateIssue(userId, repoId, milestoneId, assigneeId, name, labels, mentions, content, isPull); err != nil { - // } + ctx.Data["Title"] = "Create issue" + + if ctx.Req.Method == "GET" { + ctx.HTML(200, "issue/create") + return + } + + if ctx.HasError() { + ctx.HTML(200, "issue/create") + return + } + + issue, err := models.CreateIssue(ctx.User.Id, form.RepoId, form.MilestoneId, form.AssigneeId, + form.IssueName, form.Labels, form.Content, false) + if err == nil { + log.Trace("%s Issue created: %d", form.RepoId, issue.Id) + ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index), 302) + return + } + ctx.Handle(200, "issue.CreateIssue", err) +} + +func ViewIssue(ctx *middleware.Context, params martini.Params) { + issueid, err := base.StrTo(params["issueid"]).Int() + if err != nil { + ctx.Error(404) + return + } + + issue, err := models.GetIssueById(int64(issueid)) + if err != nil { + if err == models.ErrIssueNotExist { + ctx.Error(404) + } else { + ctx.Handle(200, "issue.ViewIssue", err) + } + return + } + + ctx.Data["Title"] = issue.Name + ctx.Data["Issue"] = issue + ctx.HTML(200, "issue/view") } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index ff0fa85dd..c436d3871 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -31,6 +31,11 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { return } + if ctx.HasError() { + ctx.HTML(200, "repo/create") + return + } + _, err := models.CreateRepository(ctx.User, form.RepoName, form.Description, form.Language, form.License, form.Visibility == "private", form.InitReadme == "on") if err == nil { diff --git a/templates/admin/repos.tmpl b/templates/admin/repos.tmpl index a1f41d836..2c91ccc09 100644 --- a/templates/admin/repos.tmpl +++ b/templates/admin/repos.tmpl @@ -27,7 +27,7 @@