diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-14 10:55:36 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-14 10:55:36 -0400 |
commit | 46fc36c3a63b5501ca154df885ae5446ebb66220 (patch) | |
tree | bf430623b1a1eb664b96759bff068d2a2624b92e /models/issue.go | |
parent | 99f2400e3b4f141671bd8f31d23afcd0cf511c05 (diff) | |
download | gitea-46fc36c3a63b5501ca154df885ae5446ebb66220.tar.gz gitea-46fc36c3a63b5501ca154df885ae5446ebb66220.zip |
Finish change issue’s milestone
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/models/issue.go b/models/issue.go index e708e54311..26380b6033 100644 --- a/models/issue.go +++ b/models/issue.go @@ -446,6 +446,18 @@ func NewMilestone(m *Milestone) (err error) { return sess.Commit() } +// GetMilestoneById returns the milestone by given ID. +func GetMilestoneById(id int64) (*Milestone, error) { + m := &Milestone{Id: id} + has, err := orm.Get(m) + if err != nil { + return nil, err + } else if !has { + return nil, ErrMilestoneNotExist + } + return m, nil +} + // GetMilestoneByIndex returns the milestone of given repository and index. func GetMilestoneByIndex(repoId, idx int64) (*Milestone, error) { m := &Milestone{RepoId: repoId, Index: idx} @@ -502,6 +514,51 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { return sess.Commit() } +// ChangeMilestoneAssign changes assignment of milestone for issue. +func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) { + sess := orm.NewSession() + defer sess.Close() + if err = sess.Begin(); err != nil { + return err + } + + if oldMid > 0 { + m, err := GetMilestoneById(oldMid) + if err != nil { + return err + } + + m.NumIssues-- + if isIssueClosed { + m.NumClosedIssues-- + } + if m.NumIssues > 0 { + m.Completeness = m.NumClosedIssues * 100 / m.NumIssues + } else { + m.Completeness = 0 + } + if _, err = sess.Id(m.Id).Update(m); err != nil { + sess.Rollback() + return err + } + } + + m, err := GetMilestoneById(mid) + if err != nil { + return err + } + m.NumIssues++ + if isIssueClosed { + m.NumClosedIssues++ + } + m.Completeness = m.NumClosedIssues * 100 / m.NumIssues + if _, err = sess.Id(m.Id).Update(m); err != nil { + sess.Rollback() + return err + } + return sess.Commit() +} + // DeleteMilestone deletes a milestone. func DeleteMilestone(m *Milestone) (err error) { sess := orm.NewSession() |