Working on issues
This commit is contained in:
2
gogs.go
2
gogs.go
@ -20,7 +20,7 @@ import (
|
|||||||
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
|
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
|
||||||
const go12tag = true
|
const go12tag = true
|
||||||
|
|
||||||
const APP_VER = "0.1.5.0322.2"
|
const APP_VER = "0.1.6.0323.1"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
base.AppVer = APP_VER
|
base.AppVer = APP_VER
|
||||||
|
@ -88,7 +88,6 @@ func CommitRepoAction(userId int64, userName string,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
repo.IsBare = false
|
repo.IsBare = false
|
||||||
repo.Updated = time.Now()
|
|
||||||
if err = UpdateRepository(repo); err != nil {
|
if err = UpdateRepository(repo); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
123
models/issue.go
123
models/issue.go
@ -4,16 +4,127 @@
|
|||||||
|
|
||||||
package models
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/modules/base"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Issue represents an issue or pull request of repository.
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
Id int64
|
Id int64
|
||||||
RepoId int64 `xorm:"index"`
|
Index int64 // Index in one repository.
|
||||||
PosterId int64
|
Name string
|
||||||
|
RepoId int64 `xorm:"index"`
|
||||||
|
PosterId int64
|
||||||
|
MilestoneId int64
|
||||||
|
AssigneeId int64
|
||||||
|
IsPull bool // Indicates whether is a pull request or not.
|
||||||
|
IsClosed bool
|
||||||
|
Labels string
|
||||||
|
Mentions string
|
||||||
|
Content string
|
||||||
|
NumComments int
|
||||||
|
Created time.Time `xorm:"created"`
|
||||||
|
Updated time.Time `xorm:"updated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PullRequest struct {
|
// CreateIssue creates new issue for repository.
|
||||||
Id int64
|
func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, mentions, content string, isPull bool) error {
|
||||||
|
count, err := GetIssueCount(repoId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = orm.Insert(&Issue{
|
||||||
|
Index: count + 1,
|
||||||
|
Name: name,
|
||||||
|
RepoId: repoId,
|
||||||
|
PosterId: userId,
|
||||||
|
MilestoneId: milestoneId,
|
||||||
|
AssigneeId: assigneeId,
|
||||||
|
IsPull: isPull,
|
||||||
|
Labels: labels,
|
||||||
|
Mentions: mentions,
|
||||||
|
Content: content,
|
||||||
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIssueCount returns count of issues in the repository.
|
||||||
|
func GetIssueCount(repoId int64) (int64, error) {
|
||||||
|
return orm.Count(&Issue{RepoId: repoId})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
if userId > 0 {
|
||||||
|
sess = sess.And("assignee_id=?", userId)
|
||||||
|
} else if posterId > 0 {
|
||||||
|
sess = sess.And("poster_id=?", posterId)
|
||||||
|
} else if isMention {
|
||||||
|
sess = sess.And("mentions like '%$" + base.ToStr(userId) + "|%'")
|
||||||
|
}
|
||||||
|
|
||||||
|
if milestoneId > 0 {
|
||||||
|
sess = sess.And("milestone_id=?", milestoneId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(labels) > 0 {
|
||||||
|
for _, label := range strings.Split(labels, ",") {
|
||||||
|
sess = sess.And("mentions like '%$" + label + "|%'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch sortType {
|
||||||
|
case "oldest":
|
||||||
|
sess = sess.Asc("created")
|
||||||
|
case "recentupdate":
|
||||||
|
sess = sess.Desc("updated")
|
||||||
|
case "leastupdate":
|
||||||
|
sess = sess.Asc("updated")
|
||||||
|
case "mostcomment":
|
||||||
|
sess = sess.Desc("num_comments")
|
||||||
|
case "leastcomment":
|
||||||
|
sess = sess.Asc("num_comments")
|
||||||
|
default:
|
||||||
|
sess = sess.Desc("created")
|
||||||
|
}
|
||||||
|
|
||||||
|
var issues []Issue
|
||||||
|
err := sess.Find(&issues)
|
||||||
|
return issues, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Label represents a list of labels of repository for issues.
|
||||||
|
type Label struct {
|
||||||
|
Id int64
|
||||||
|
RepoId int64 `xorm:"index"`
|
||||||
|
Names string
|
||||||
|
Colors string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Milestone represents a milestone of repository.
|
||||||
|
type Milestone struct {
|
||||||
|
Id int64
|
||||||
|
Name string
|
||||||
|
RepoId int64 `xorm:"index"`
|
||||||
|
IsClosed bool
|
||||||
|
Content string
|
||||||
|
NumIssues int
|
||||||
|
DueDate time.Time
|
||||||
|
Created time.Time `xorm:"created"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comment represents a comment in commit and issue page.
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
Id int64
|
Id int64
|
||||||
|
PosterId int64
|
||||||
|
IssueId int64
|
||||||
|
CommitId int64
|
||||||
|
Line int
|
||||||
|
Content string
|
||||||
|
Created time.Time `xorm:"created"`
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func setEngine() {
|
|||||||
func NewEngine() {
|
func NewEngine() {
|
||||||
setEngine()
|
setEngine()
|
||||||
if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
|
if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
|
||||||
new(Action), new(Access)); err != nil {
|
new(Action), new(Access), new(Issue)); err != nil {
|
||||||
fmt.Printf("sync database struct error: %v\n", err)
|
fmt.Printf("sync database struct error: %v\n", err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
30
routers/repo/issue.go
Normal file
30
routers/repo/issue.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// 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 repo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/codegangsta/martini"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/models"
|
||||||
|
"github.com/gogits/gogs/modules/base"
|
||||||
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Issues(ctx *middleware.Context, params martini.Params) {
|
||||||
|
ctx.Data["IsRepoToolbarIssues"] = true
|
||||||
|
|
||||||
|
milestoneId, _ := base.StrTo(params["milestone"]).Int()
|
||||||
|
page, _ := base.StrTo(params["page"]).Int()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
ctx.Data["Issues"], err = models.GetIssues(0, ctx.Repo.Repository.Id, 0,
|
||||||
|
int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"])
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(200, "issue.Issues: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.HTML(200, "repo/issues")
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user