Browse Source

api/repo/milestone: fix change status didn't take effect

pull/3809/merge
Unknwon 8 years ago
parent
commit
3f95824e65
No known key found for this signature in database
GPG Key ID: FB9F411CDD69BEC1
  1. 6
      models/issue.go
  2. 8
      routers/api/v1/repo/milestone.go

6
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 {

8
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())
}

Loading…
Cancel
Save