aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/models/issue.go b/models/issue.go
index e708e54311..7dd69267ae 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -167,6 +167,8 @@ type IssueUser struct {
Uid int64 // User ID.
IssueId int64
RepoId int64
+ MilestoneId int64
+ Labels string `xorm:"TEXT"`
IsRead bool
IsAssigned bool
IsMentioned bool
@@ -446,6 +448,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 +516,53 @@ 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
+ }
+ }
+
+ if mid > 0 {
+ 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()