diff --git a/models/issue.go b/models/issue.go index cc3e4ad02..dbe01f6f4 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1405,6 +1405,10 @@ func (m *Milestone) State() api.StateType { return api.STATE_OPEN } +func (m *Milestone) ChangeStatus(isClosed bool) error { + return ChangeMilestoneStatus(m, isClosed) +} + func (m *Milestone) APIFormat() *api.Milestone { apiMilestone := &api.Milestone{ ID: m.ID, @@ -1513,6 +1517,8 @@ func MilestoneStats(repoID int64) (open int64, closed int64) { } // ChangeMilestoneStatus changes the milestone open/closed status. +// If milestone passes with changed values, those values will be +// updated to database as well. func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { repo, err := GetRepositoryByID(m.RepoID) if err != nil { diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index 2dcc3a52c..bd408f638 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -81,10 +81,16 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) { milestone.Deadline = *form.Deadline } - if err := models.UpdateMilestone(milestone); err != nil { + if form.State != nil { + if err = milestone.ChangeStatus(api.STATE_CLOSED == api.StateType(*form.State)); err != nil { + ctx.Error(500, "ChangeStatus", err) + return + } + } else if err = models.UpdateMilestone(milestone); err != nil { ctx.Handle(500, "UpdateMilestone", err) return } + ctx.JSON(200, milestone.APIFormat()) }