mirror of https://github.com/gogs/gogs.git
api/repo/milestone: fix change status didn't take effect
parent
29722af1ae
commit
3f95824e65
|
@ -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 {
|
||||
|
|
|
@ -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…
Reference in New Issue