Add create, list, view issue

This commit is contained in:
Unknown 2014-03-22 16:00:46 -04:00
parent b3cfd9fe0c
commit 59ffdbf6f8
11 changed files with 217 additions and 51 deletions

View file

@ -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"`
}

View file

@ -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 {

View file

@ -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"`
}

View file

@ -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
}

View file

@ -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
}