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
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,
Labels: labels,
Mentions: mentions,
Content: content,
- })
- return err
+ }
+ _, err = orm.Insert(issue)
+ return issue, err
}
// GetIssueCount returns count of issues in the repository.
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 {
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()
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")
}
m.Get("/issues", reqSignIn, user.Issues)
m.Get("/pulls", reqSignIn, user.Pulls)
m.Get("/stars", reqSignIn, user.Stars)
- m.Any("/user/login", reqSignOut, binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
- m.Any("/user/logout", reqSignIn, user.SignOut)
- m.Any("/user/sign_up", reqSignOut, binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
- m.Any("/user/delete", reqSignIn, user.Delete)
- m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds)
- m.Get("/user/activate", user.Activate)
-
- m.Any("/user/setting", reqSignIn, binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting)
- m.Any("/user/setting/password", reqSignIn, binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword)
- m.Any("/user/setting/ssh", reqSignIn, binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys)
- m.Any("/user/setting/notification", reqSignIn, user.SettingNotification)
- m.Any("/user/setting/security", reqSignIn, user.SettingSecurity)
+ m.Get("/help", routers.Help)
+
+ m.Group("/user", func(r martini.Router) {
+ r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
+ r.Any("/sign_up", reqSignOut, binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
+ }, reqSignOut)
+ m.Group("/user", func(r martini.Router) {
+ r.Any("/logout", user.SignOut)
+ r.Any("/delete", user.Delete)
+ r.Any("/setting", binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting)
+ }, reqSignIn)
+ m.Group("/user", func(r martini.Router) {
+ r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds)
+ r.Get("/activate", user.Activate)
+ })
+
+ m.Group("/user/setting", func(r martini.Router) {
+ r.Any("/password", binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword)
+ r.Any("/ssh", binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys)
+ r.Any("/notification", user.SettingNotification)
+ r.Any("/security", user.SettingSecurity)
+ }, reqSignIn)
m.Get("/user/:username", ignSignIn, user.Profile)
m.Any("/repo/create", reqSignIn, binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
- m.Get("/help", routers.Help)
-
adminReq := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true, AdminRequire: true})
m.Get("/admin", adminReq, admin.Dashboard)
- m.Get("/admin/users", adminReq, admin.Users)
- m.Any("/admin/users/new", adminReq, binding.BindIgnErr(auth.RegisterForm{}), admin.NewUser)
- m.Any("/admin/users/:userid", adminReq, binding.BindIgnErr(auth.AdminEditUserForm{}), admin.EditUser)
- m.Any("/admin/users/:userid/delete", adminReq, admin.DeleteUser)
- m.Get("/admin/repos", adminReq, admin.Repositories)
- m.Get("/admin/config", adminReq, admin.Config)
-
- m.Post("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.SettingPost)
- m.Get("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.Setting)
-
- m.Get("/:username/:reponame/commits/:branchname", ignSignIn, middleware.RepoAssignment(true), repo.Commits)
- m.Get("/:username/:reponame/issues", ignSignIn, middleware.RepoAssignment(true), repo.Issues)
- m.Get("/:username/:reponame/pulls", ignSignIn, middleware.RepoAssignment(true), repo.Pulls)
- m.Get("/:username/:reponame/branches", ignSignIn, middleware.RepoAssignment(true), repo.Branches)
- m.Get("/:username/:reponame/action/:action", reqSignIn, middleware.RepoAssignment(true), repo.Action)
- m.Get("/:username/:reponame/src/:branchname/**",
- ignSignIn, middleware.RepoAssignment(true), repo.Single)
- m.Get("/:username/:reponame/src/:branchname",
- ignSignIn, middleware.RepoAssignment(true), repo.Single)
- m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Single)
- m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Single)
-
- m.Get("/:username/:reponame", ignSignIn, middleware.RepoAssignment(true), repo.Single)
-
- m.Any("/:username/:reponame/**", ignSignIn, repo.Http)
+ m.Group("/admin", func(r martini.Router) {
+ r.Get("/users", admin.Users)
+ r.Get("/repos", admin.Repositories)
+ r.Get("/config", admin.Config)
+ }, adminReq)
+ m.Group("/admin/users", func(r martini.Router) {
+ r.Any("/new", binding.BindIgnErr(auth.RegisterForm{}), admin.NewUser)
+ r.Any("/:userid", binding.BindIgnErr(auth.AdminEditUserForm{}), admin.EditUser)
+ r.Any("/:userid/delete", admin.DeleteUser)
+ }, adminReq)
+
+ m.Group("/:username/:reponame", func(r martini.Router) {
+ r.Post("/settings", repo.SettingPost)
+ r.Get("/settings", repo.Setting)
+ r.Get("/action/:action", repo.Action)
+ }, reqSignIn, middleware.RepoAssignment(true))
+ m.Group("/:username/:reponame", func(r martini.Router) {
+ r.Get("/commits/:branchname", repo.Commits)
+ r.Get("/issues", repo.Issues)
+ r.Any("/issues/new", binding.BindIgnErr(auth.CreateIssueForm{}), repo.CreateIssue)
+ r.Get("/issues/:issueid", repo.ViewIssue)
+ r.Get("/pulls", repo.Pulls)
+ r.Get("/branches", repo.Branches)
+ r.Get("/src/:branchname", repo.Single)
+ r.Get("/src/:branchname/**", repo.Single)
+ r.Get("/commits/:branchname", repo.Commits)
+ r.Get("/commits/:branchname", repo.Commits)
+ }, ignSignIn, middleware.RepoAssignment(true))
+
+ // TODO: implement single commit page
+ // m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Single)
+ // m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Single)
+
+ m.Group("/:username", func(r martini.Router) {
+ r.Get("/:reponame", middleware.RepoAssignment(true), repo.Single)
+ r.Any("/:reponame/**", repo.Http)
+ }, ignSignIn)
if martini.Env == martini.Dev {
m.Get("/template/**", dev.TemplatePreview)