Finish add new milestone

This commit is contained in:
Unknown 2014-05-12 14:06:42 -04:00
parent f1130ce5e9
commit 54e95fa367
14 changed files with 236 additions and 136 deletions

View file

@ -20,9 +20,9 @@ var (
// Issue represents an issue or pull request of repository.
type Issue struct {
Id int64
RepoId int64 `xorm:"INDEX"`
Index int64 // Index in one repository.
Name string
RepoId int64 `xorm:"INDEX"`
Repo *Repository `xorm:"-"`
PosterId int64
Poster *User `xorm:"-"`
@ -390,7 +390,7 @@ func UpdateIssueUserPairsByMentions(uids []int64, iid int64) error {
// Label represents a label of repository for issues.
type Label struct {
Id int64
Rid int64 `xorm:"INDEX"`
RepoId int64 `xorm:"INDEX"`
Name string
Color string
NumIssues int
@ -401,17 +401,53 @@ type Label struct {
// Milestone represents a milestone of repository.
type Milestone struct {
Id int64
Rid int64 `xorm:"INDEX"`
RepoId int64 `xorm:"INDEX"`
Index int64
Name string
Content string
RenderedContent string `xorm:"-"`
IsClosed bool
NumIssues int
NumClosedIssues int
NumOpenIssues int `xorm:"-"`
Completeness int // Percentage(1-100).
Deadline time.Time
ClosedDate time.Time
}
// CalOpenIssues calculates the open issues of milestone.
func (m *Milestone) CalOpenIssues() {
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
}
// NewMilestone creates new milestone of repository.
func NewMilestone(m *Milestone) (err error) {
sess := orm.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
if _, err = sess.Insert(m); err != nil {
sess.Rollback()
return err
}
rawSql := "UPDATE `repository` SET num_milestones = num_milestones + 1 WHERE id = ?"
if _, err = sess.Exec(rawSql, m.RepoId); err != nil {
sess.Rollback()
return err
}
return sess.Commit()
}
// GetMilestones returns a list of milestones of given repository and status.
func GetMilestones(repoId int64, isClosed bool) ([]*Milestone, error) {
miles := make([]*Milestone, 0, 10)
err := orm.Where("repo_id=?", repoId).And("is_closed=?", isClosed).Find(&miles)
return miles, err
}
// Issue types.
const (
IT_PLAIN = iota // Pure comment.

View file

@ -34,7 +34,8 @@ var (
func init() {
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow),
new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser))
new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser),
new(Milestone))
}
func LoadModelsConfig() {
@ -141,7 +142,7 @@ type Statistic struct {
Counter struct {
User, PublicKey, Repo, Watch, Action, Access,
Issue, Comment, Mirror, Oauth, Release,
LoginSource, Webhook int64
LoginSource, Webhook, Milestone int64
}
}
@ -159,6 +160,7 @@ func GetStatistic() (stats Statistic) {
stats.Counter.Release, _ = orm.Count(new(Release))
stats.Counter.LoginSource, _ = orm.Count(new(LoginSource))
stats.Counter.Webhook, _ = orm.Count(new(Webhook))
stats.Counter.Milestone, _ = orm.Count(new(Milestone))
return
}

View file

@ -92,28 +92,31 @@ func NewRepoContext() {
// Repository represents a git repository.
type Repository struct {
Id int64
OwnerId int64 `xorm:"unique(s)"`
Owner *User `xorm:"-"`
ForkId int64
LowerName string `xorm:"unique(s) index not null"`
Name string `xorm:"index not null"`
Description string
Website string
NumWatches int
NumStars int
NumForks int
NumIssues int
NumClosedIssues int
NumOpenIssues int `xorm:"-"`
NumTags int `xorm:"-"`
IsPrivate bool
IsMirror bool
IsBare bool
IsGoget bool
DefaultBranch string
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
Id int64
OwnerId int64 `xorm:"unique(s)"`
Owner *User `xorm:"-"`
ForkId int64
LowerName string `xorm:"unique(s) index not null"`
Name string `xorm:"index not null"`
Description string
Website string
NumWatches int
NumStars int
NumForks int
NumIssues int
NumClosedIssues int
NumOpenIssues int `xorm:"-"`
NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumOpenMilestones int `xorm:"-"`
NumTags int `xorm:"-"`
IsPrivate bool
IsMirror bool
IsBare bool
IsGoget bool
DefaultBranch string
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
}
func (repo *Repository) GetOwner() (err error) {