Skip to content

Commit 61e2922

Browse files
committed
Working on issues
1 parent e3f55ca commit 61e2922

File tree

7 files changed

+443
-310
lines changed

7 files changed

+443
-310
lines changed

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
2121
const go12tag = true
2222

23-
const APP_VER = "0.1.5.0322.2"
23+
const APP_VER = "0.1.6.0323.1"
2424

2525
func init() {
2626
base.AppVer = APP_VER

models/action.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func CommitRepoAction(userId int64, userName string,
8888
return err
8989
}
9090
repo.IsBare = false
91-
repo.Updated = time.Now()
9291
if err = UpdateRepository(repo); err != nil {
9392
return err
9493
}

models/issue.go

Lines changed: 117 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,127 @@
44

55
package models
66

7+
import (
8+
"strings"
9+
"time"
10+
11+
"github.com/gogits/gogs/modules/base"
12+
)
13+
14+
// Issue represents an issue or pull request of repository.
715
type Issue struct {
8-
Id int64
9-
RepoId int64 `xorm:"index"`
10-
PosterId int64
16+
Id int64
17+
Index int64 // Index in one repository.
18+
Name string
19+
RepoId int64 `xorm:"index"`
20+
PosterId int64
21+
MilestoneId int64
22+
AssigneeId int64
23+
IsPull bool // Indicates whether is a pull request or not.
24+
IsClosed bool
25+
Labels string
26+
Mentions string
27+
Content string
28+
NumComments int
29+
Created time.Time `xorm:"created"`
30+
Updated time.Time `xorm:"updated"`
31+
}
32+
33+
// CreateIssue creates new issue for repository.
34+
func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, mentions, content string, isPull bool) error {
35+
count, err := GetIssueCount(repoId)
36+
if err != nil {
37+
return err
38+
}
39+
40+
_, err = orm.Insert(&Issue{
41+
Index: count + 1,
42+
Name: name,
43+
RepoId: repoId,
44+
PosterId: userId,
45+
MilestoneId: milestoneId,
46+
AssigneeId: assigneeId,
47+
IsPull: isPull,
48+
Labels: labels,
49+
Mentions: mentions,
50+
Content: content,
51+
})
52+
return err
1153
}
1254

13-
type PullRequest struct {
14-
Id int64
55+
// GetIssueCount returns count of issues in the repository.
56+
func GetIssueCount(repoId int64) (int64, error) {
57+
return orm.Count(&Issue{RepoId: repoId})
1558
}
1659

60+
// GetIssues returns a list of issues by given conditions.
61+
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)
63+
if userId > 0 {
64+
sess = sess.And("assignee_id=?", userId)
65+
} else if posterId > 0 {
66+
sess = sess.And("poster_id=?", posterId)
67+
} else if isMention {
68+
sess = sess.And("mentions like '%$" + base.ToStr(userId) + "|%'")
69+
}
70+
71+
if milestoneId > 0 {
72+
sess = sess.And("milestone_id=?", milestoneId)
73+
}
74+
75+
if len(labels) > 0 {
76+
for _, label := range strings.Split(labels, ",") {
77+
sess = sess.And("mentions like '%$" + label + "|%'")
78+
}
79+
}
80+
81+
switch sortType {
82+
case "oldest":
83+
sess = sess.Asc("created")
84+
case "recentupdate":
85+
sess = sess.Desc("updated")
86+
case "leastupdate":
87+
sess = sess.Asc("updated")
88+
case "mostcomment":
89+
sess = sess.Desc("num_comments")
90+
case "leastcomment":
91+
sess = sess.Asc("num_comments")
92+
default:
93+
sess = sess.Desc("created")
94+
}
95+
96+
var issues []Issue
97+
err := sess.Find(&issues)
98+
return issues, err
99+
}
100+
101+
// Label represents a list of labels of repository for issues.
102+
type Label struct {
103+
Id int64
104+
RepoId int64 `xorm:"index"`
105+
Names string
106+
Colors string
107+
}
108+
109+
// Milestone represents a milestone of repository.
110+
type Milestone struct {
111+
Id int64
112+
Name string
113+
RepoId int64 `xorm:"index"`
114+
IsClosed bool
115+
Content string
116+
NumIssues int
117+
DueDate time.Time
118+
Created time.Time `xorm:"created"`
119+
}
120+
121+
// Comment represents a comment in commit and issue page.
17122
type Comment struct {
18-
Id int64
123+
Id int64
124+
PosterId int64
125+
IssueId int64
126+
CommitId int64
127+
Line int
128+
Content string
129+
Created time.Time `xorm:"created"`
19130
}

models/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func setEngine() {
7272
func NewEngine() {
7373
setEngine()
7474
if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
75-
new(Action), new(Access)); err != nil {
75+
new(Action), new(Access), new(Issue)); err != nil {
7676
fmt.Printf("sync database struct error: %v\n", err)
7777
os.Exit(2)
7878
}

routers/repo/issue.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 repo
6+
7+
import (
8+
"github.com/codegangsta/martini"
9+
10+
"github.com/gogits/gogs/models"
11+
"github.com/gogits/gogs/modules/base"
12+
"github.com/gogits/gogs/modules/middleware"
13+
)
14+
15+
func Issues(ctx *middleware.Context, params martini.Params) {
16+
ctx.Data["IsRepoToolbarIssues"] = true
17+
18+
milestoneId, _ := base.StrTo(params["milestone"]).Int()
19+
page, _ := base.StrTo(params["page"]).Int()
20+
21+
var err error
22+
ctx.Data["Issues"], err = models.GetIssues(0, ctx.Repo.Repository.Id, 0,
23+
int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"])
24+
if err != nil {
25+
ctx.Handle(200, "issue.Issues: %v", err)
26+
return
27+
}
28+
29+
ctx.HTML(200, "repo/issues")
30+
}

0 commit comments

Comments
 (0)