summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-22 16:00:46 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-22 16:00:46 -0400
commit59ffdbf6f80328f9b9074930444dedd936aeae51 (patch)
tree486e9ad694a510db04453e259010ed60bd215ffd /models
parentb3cfd9fe0c293ba9d84d38ec140db2c01b1e3109 (diff)
downloadgitea-59ffdbf6f80328f9b9074930444dedd936aeae51.tar.gz
gitea-59ffdbf6f80328f9b9074930444dedd936aeae51.zip
Add create, list, view issue
Diffstat (limited to 'models')
-rw-r--r--models/action.go2
-rw-r--r--models/issue.go46
-rw-r--r--models/publickey.go2
-rw-r--r--models/repo.go7
-rw-r--r--models/user.go7
5 files changed, 53 insertions, 11 deletions
diff --git a/models/action.go b/models/action.go
index a996e16aa8..cfb124363c 100644
--- a/models/action.go
+++ b/models/action.go
@@ -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"`
}
diff --git a/models/issue.go b/models/issue.go
index 0b6ca4c323..f78c240cbc 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -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 {
diff --git a/models/publickey.go b/models/publickey.go
index 9e7cc6f740..3f2fcabd3b 100644
--- a/models/publickey.go
+++ b/models/publickey.go
@@ -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"`
}
diff --git a/models/repo.go b/models/repo.go
index 317f936ece..a37923c8b1 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -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
}
diff --git a/models/user.go b/models/user.go
index 88c29ae43e..9333d1ee67 100644
--- a/models/user.go
+++ b/models/user.go
@@ -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
}