Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 59ffdbf

Browse files
committedMar 22, 2014
Add create, list, view issue
1 parent b3cfd9f commit 59ffdbf

File tree

11 files changed

+221
-55
lines changed

11 files changed

+221
-55
lines changed
 

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language.
55

66
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.
77

8-
##### Current version: 0.1.5 Alpha
8+
##### Current version: 0.1.6 Alpha
99

1010
## Purpose
1111

‎models/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Action struct {
3030
ActUserName string // Action user name.
3131
RepoId int64
3232
RepoName string
33-
Content string
33+
Content string `xorm:"TEXT"`
3434
Created time.Time `xorm:"created"`
3535
}
3636

‎models/issue.go

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
package models
66

77
import (
8+
"errors"
89
"strings"
910
"time"
1011

1112
"github.com/gogits/gogs/modules/base"
1213
)
1314

15+
var (
16+
ErrIssueNotExist = errors.New("Issue does not exist")
17+
)
18+
1419
// Issue represents an issue or pull request of repository.
1520
type Issue struct {
1621
Id int64
@@ -22,22 +27,25 @@ type Issue struct {
2227
AssigneeId int64
2328
IsPull bool // Indicates whether is a pull request or not.
2429
IsClosed bool
25-
Labels string
26-
Mentions string
27-
Content string
30+
Labels string `xorm:"TEXT"`
31+
Mentions string `xorm:"TEXT"`
32+
Content string `xorm:"TEXT"`
2833
NumComments int
2934
Created time.Time `xorm:"created"`
3035
Updated time.Time `xorm:"updated"`
3136
}
3237

3338
// CreateIssue creates new issue for repository.
34-
func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, mentions, content string, isPull bool) error {
39+
func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, content string, isPull bool) (*Issue, error) {
3540
count, err := GetIssueCount(repoId)
3641
if err != nil {
37-
return err
42+
return nil, err
3843
}
3944

40-
_, err = orm.Insert(&Issue{
45+
// TODO: find out mentions
46+
mentions := ""
47+
48+
issue := &Issue{
4149
Index: count + 1,
4250
Name: name,
4351
RepoId: repoId,
@@ -48,18 +56,38 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, me
4856
Labels: labels,
4957
Mentions: mentions,
5058
Content: content,
51-
})
52-
return err
59+
}
60+
_, err = orm.Insert(issue)
61+
return issue, err
5362
}
5463

5564
// GetIssueCount returns count of issues in the repository.
5665
func GetIssueCount(repoId int64) (int64, error) {
5766
return orm.Count(&Issue{RepoId: repoId})
5867
}
5968

69+
// GetIssueById returns issue object by given id.
70+
func GetIssueById(id int64) (*Issue, error) {
71+
issue := new(Issue)
72+
has, err := orm.Id(id).Get(issue)
73+
if err != nil {
74+
return nil, err
75+
} else if !has {
76+
return nil, ErrIssueNotExist
77+
}
78+
return issue, nil
79+
}
80+
6081
// GetIssues returns a list of issues by given conditions.
6182
func GetIssues(userId, repoId, posterId, milestoneId int64, page int, isClosed, isMention bool, labels, sortType string) ([]Issue, error) {
62-
sess := orm.Limit(20, (page-1)*20).Where("repo_id=?", repoId).And("is_closed=?", isClosed)
83+
sess := orm.Limit(20, (page-1)*20)
84+
85+
if repoId > 0 {
86+
sess = sess.Where("repo_id=?", repoId).And("is_closed=?", isClosed)
87+
} else {
88+
sess = sess.Where("is_closed=?", isClosed)
89+
}
90+
6391
if userId > 0 {
6492
sess = sess.And("assignee_id=?", userId)
6593
} else if posterId > 0 {

‎models/publickey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type PublicKey struct {
8080
OwnerId int64 `xorm:"index"`
8181
Name string `xorm:"unique not null"`
8282
Fingerprint string
83-
Content string `xorm:"text not null"`
83+
Content string `xorm:"TEXT not null"`
8484
Created time.Time `xorm:"created"`
8585
Updated time.Time `xorm:"updated"`
8686
}

‎models/repo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@ func RepoPath(userName, repoName string) string {
372372
}
373373

374374
func UpdateRepository(repo *Repository) error {
375+
if len(repo.Description) > 255 {
376+
repo.Description = repo.Description[:255]
377+
}
378+
if len(repo.Website) > 255 {
379+
repo.Website = repo.Website[:255]
380+
}
381+
375382
_, err := orm.Id(repo.Id).UseBool().Cols("description", "website").Update(repo)
376383
return err
377384
}

‎models/user.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ func VerifyUserActiveCode(code string) (user *User) {
201201

202202
// UpdateUser updates user's information.
203203
func UpdateUser(user *User) (err error) {
204+
if len(user.Location) > 255 {
205+
user.Location = user.Location[:255]
206+
}
207+
if len(user.Website) > 255 {
208+
user.Website = user.Website[:255]
209+
}
210+
204211
_, err = orm.Id(user.Id).UseBool().Cols("website", "location").Update(user)
205212
return err
206213
}

‎modules/auth/issue.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2014 The Gogs Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package auth
6+
7+
import (
8+
"net/http"
9+
"reflect"
10+
11+
"github.com/codegangsta/martini"
12+
13+
"github.com/gogits/binding"
14+
15+
"github.com/gogits/gogs/modules/base"
16+
"github.com/gogits/gogs/modules/log"
17+
)
18+
19+
type CreateIssueForm struct {
20+
IssueName string `form:"name" binding:"Required;MaxSize(50)"`
21+
RepoId int64 `form:"repoid" binding:"Required"`
22+
MilestoneId int64 `form:"milestoneid" binding:"Required"`
23+
AssigneeId int64 `form:"assigneeid"`
24+
Labels string `form:"labels"`
25+
Content string `form:"content"`
26+
}
27+
28+
func (f *CreateIssueForm) Name(field string) string {
29+
names := map[string]string{
30+
"IssueName": "Issue name",
31+
"RepoId": "Repository ID",
32+
"MilestoneId": "Milestone ID",
33+
}
34+
return names[field]
35+
}
36+
37+
func (f *CreateIssueForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
38+
if req.Method == "GET" || errors.Count() == 0 {
39+
return
40+
}
41+
42+
data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
43+
data["HasError"] = true
44+
AssignForm(f, data)
45+
46+
if len(errors.Overall) > 0 {
47+
for _, err := range errors.Overall {
48+
log.Error("CreateIssueForm.Validate: %v", err)
49+
}
50+
return
51+
}
52+
53+
validate(errors, data, f)
54+
}

‎routers/repo/issue.go

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
package repo
66

77
import (
8+
"fmt"
9+
810
"github.com/codegangsta/martini"
911

1012
"github.com/gogits/gogs/models"
13+
"github.com/gogits/gogs/modules/auth"
1114
"github.com/gogits/gogs/modules/base"
15+
"github.com/gogits/gogs/modules/log"
1216
"github.com/gogits/gogs/modules/middleware"
1317
)
1418

1519
func Issues(ctx *middleware.Context, params martini.Params) {
20+
ctx.Data["Title"] = "Issues"
1621
ctx.Data["IsRepoToolbarIssues"] = true
1722

1823
milestoneId, _ := base.StrTo(params["milestone"]).Int()
@@ -29,12 +34,52 @@ func Issues(ctx *middleware.Context, params martini.Params) {
2934
ctx.HTML(200, "repo/issues")
3035
}
3136

32-
func CreateIssue(ctx *middleware.Context, params martini.Params) {
37+
func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
3338
if !ctx.Repo.IsOwner {
3439
ctx.Error(404)
3540
return
3641
}
37-
// else if err = models.CreateIssue(userId, repoId, milestoneId, assigneeId, name, labels, mentions, content, isPull); err != nil {
3842

39-
// }
43+
ctx.Data["Title"] = "Create issue"
44+
45+
if ctx.Req.Method == "GET" {
46+
ctx.HTML(200, "issue/create")
47+
return
48+
}
49+
50+
if ctx.HasError() {
51+
ctx.HTML(200, "issue/create")
52+
return
53+
}
54+
55+
issue, err := models.CreateIssue(ctx.User.Id, form.RepoId, form.MilestoneId, form.AssigneeId,
56+
form.IssueName, form.Labels, form.Content, false)
57+
if err == nil {
58+
log.Trace("%s Issue created: %d", form.RepoId, issue.Id)
59+
ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index), 302)
60+
return
61+
}
62+
ctx.Handle(200, "issue.CreateIssue", err)
63+
}
64+
65+
func ViewIssue(ctx *middleware.Context, params martini.Params) {
66+
issueid, err := base.StrTo(params["issueid"]).Int()
67+
if err != nil {
68+
ctx.Error(404)
69+
return
70+
}
71+
72+
issue, err := models.GetIssueById(int64(issueid))
73+
if err != nil {
74+
if err == models.ErrIssueNotExist {
75+
ctx.Error(404)
76+
} else {
77+
ctx.Handle(200, "issue.ViewIssue", err)
78+
}
79+
return
80+
}
81+
82+
ctx.Data["Title"] = issue.Name
83+
ctx.Data["Issue"] = issue
84+
ctx.HTML(200, "issue/view")
4085
}

‎routers/repo/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
3131
return
3232
}
3333

34+
if ctx.HasError() {
35+
ctx.HTML(200, "repo/create")
36+
return
37+
}
38+
3439
_, err := models.CreateRepository(ctx.User, form.RepoName, form.Description,
3540
form.Language, form.License, form.Visibility == "private", form.InitReadme == "on")
3641
if err == nil {

‎templates/admin/repos.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<td>{{.Id}}</td>
2828
<th>{{.UserName}}</th>
2929
<td><a href="/{{.UserName}}/{{.Name}}">{{.Name}}</a></td>
30-
<td><i class="fa fa{{if .Private}}-check{{end}}-square-o"></i></td>
30+
<td><i class="fa fa{{if .IsPrivate}}-check{{end}}-square-o"></i></td>
3131
<td>{{.NumWatches}}</td>
3232
<td>{{.NumForks}}</td>
3333
<td>{{DateFormat .Created "M d, Y"}}</td>

‎web.go

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -91,53 +91,73 @@ func runWeb(*cli.Context) {
9191
m.Get("/issues", reqSignIn, user.Issues)
9292
m.Get("/pulls", reqSignIn, user.Pulls)
9393
m.Get("/stars", reqSignIn, user.Stars)
94-
m.Any("/user/login", reqSignOut, binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
95-
m.Any("/user/logout", reqSignIn, user.SignOut)
96-
m.Any("/user/sign_up", reqSignOut, binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
97-
m.Any("/user/delete", reqSignIn, user.Delete)
98-
m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds)
99-
m.Get("/user/activate", user.Activate)
100-
101-
m.Any("/user/setting", reqSignIn, binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting)
102-
m.Any("/user/setting/password", reqSignIn, binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword)
103-
m.Any("/user/setting/ssh", reqSignIn, binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys)
104-
m.Any("/user/setting/notification", reqSignIn, user.SettingNotification)
105-
m.Any("/user/setting/security", reqSignIn, user.SettingSecurity)
94+
m.Get("/help", routers.Help)
95+
96+
m.Group("/user", func(r martini.Router) {
97+
r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
98+
r.Any("/sign_up", reqSignOut, binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
99+
}, reqSignOut)
100+
m.Group("/user", func(r martini.Router) {
101+
r.Any("/logout", user.SignOut)
102+
r.Any("/delete", user.Delete)
103+
r.Any("/setting", binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting)
104+
}, reqSignIn)
105+
m.Group("/user", func(r martini.Router) {
106+
r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds)
107+
r.Get("/activate", user.Activate)
108+
})
109+
110+
m.Group("/user/setting", func(r martini.Router) {
111+
r.Any("/password", binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword)
112+
r.Any("/ssh", binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys)
113+
r.Any("/notification", user.SettingNotification)
114+
r.Any("/security", user.SettingSecurity)
115+
}, reqSignIn)
106116

107117
m.Get("/user/:username", ignSignIn, user.Profile)
108118

109119
m.Any("/repo/create", reqSignIn, binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
110120

111-
m.Get("/help", routers.Help)
112-
113121
adminReq := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true, AdminRequire: true})
114122

115123
m.Get("/admin", adminReq, admin.Dashboard)
116-
m.Get("/admin/users", adminReq, admin.Users)
117-
m.Any("/admin/users/new", adminReq, binding.BindIgnErr(auth.RegisterForm{}), admin.NewUser)
118-
m.Any("/admin/users/:userid", adminReq, binding.BindIgnErr(auth.AdminEditUserForm{}), admin.EditUser)
119-
m.Any("/admin/users/:userid/delete", adminReq, admin.DeleteUser)
120-
m.Get("/admin/repos", adminReq, admin.Repositories)
121-
m.Get("/admin/config", adminReq, admin.Config)
122-
123-
m.Post("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.SettingPost)
124-
m.Get("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.Setting)
125-
126-
m.Get("/:username/:reponame/commits/:branchname", ignSignIn, middleware.RepoAssignment(true), repo.Commits)
127-
m.Get("/:username/:reponame/issues", ignSignIn, middleware.RepoAssignment(true), repo.Issues)
128-
m.Get("/:username/:reponame/pulls", ignSignIn, middleware.RepoAssignment(true), repo.Pulls)
129-
m.Get("/:username/:reponame/branches", ignSignIn, middleware.RepoAssignment(true), repo.Branches)
130-
m.Get("/:username/:reponame/action/:action", reqSignIn, middleware.RepoAssignment(true), repo.Action)
131-
m.Get("/:username/:reponame/src/:branchname/**",
132-
ignSignIn, middleware.RepoAssignment(true), repo.Single)
133-
m.Get("/:username/:reponame/src/:branchname",
134-
ignSignIn, middleware.RepoAssignment(true), repo.Single)
135-
m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Single)
136-
m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Single)
137-
138-
m.Get("/:username/:reponame", ignSignIn, middleware.RepoAssignment(true), repo.Single)
139-
140-
m.Any("/:username/:reponame/**", ignSignIn, repo.Http)
124+
m.Group("/admin", func(r martini.Router) {
125+
r.Get("/users", admin.Users)
126+
r.Get("/repos", admin.Repositories)
127+
r.Get("/config", admin.Config)
128+
}, adminReq)
129+
m.Group("/admin/users", func(r martini.Router) {
130+
r.Any("/new", binding.BindIgnErr(auth.RegisterForm{}), admin.NewUser)
131+
r.Any("/:userid", binding.BindIgnErr(auth.AdminEditUserForm{}), admin.EditUser)
132+
r.Any("/:userid/delete", admin.DeleteUser)
133+
}, adminReq)
134+
135+
m.Group("/:username/:reponame", func(r martini.Router) {
136+
r.Post("/settings", repo.SettingPost)
137+
r.Get("/settings", repo.Setting)
138+
r.Get("/action/:action", repo.Action)
139+
}, reqSignIn, middleware.RepoAssignment(true))
140+
m.Group("/:username/:reponame", func(r martini.Router) {
141+
r.Get("/commits/:branchname", repo.Commits)
142+
r.Get("/issues", repo.Issues)
143+
r.Any("/issues/new", binding.BindIgnErr(auth.CreateIssueForm{}), repo.CreateIssue)
144+
r.Get("/issues/:issueid", repo.ViewIssue)
145+
r.Get("/pulls", repo.Pulls)
146+
r.Get("/branches", repo.Branches)
147+
r.Get("/src/:branchname", repo.Single)
148+
r.Get("/src/:branchname/**", repo.Single)
149+
r.Get("/commits/:branchname", repo.Commits)
150+
r.Get("/commits/:branchname", repo.Commits)
151+
}, ignSignIn, middleware.RepoAssignment(true))
152+
153+
// TODO: implement single commit page
154+
// m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Single)
155+
// m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Single)
156+
157+
m.Group("/:username", func(r martini.Router) {
158+
r.Get("/:reponame", middleware.RepoAssignment(true), repo.Single)
159+
r.Any("/:reponame/**", repo.Http)
160+
}, ignSignIn)
141161

142162
if martini.Env == martini.Dev {
143163
m.Get("/template/**", dev.TemplatePreview)

0 commit comments

Comments
 (0)
Please sign in to comment.