From 1ac46186ff004861a786a81fe045beddaf790407 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 10 Jun 2020 00:01:36 +0200 Subject: [PATCH] API allow to create closed milestones (#11745) * API allow to create closed milestones * set CloseDate too Co-authored-by: Lauris BH Co-authored-by: techknowlogick --- integrations/api_issue_milestone_test.go | 13 +++++++++++++ modules/structs/issue_milestone.go | 2 ++ routers/api/v1/repo/milestone.go | 5 +++++ templates/swagger/v1_json.tmpl | 8 ++++++++ 4 files changed, 28 insertions(+) diff --git a/integrations/api_issue_milestone_test.go b/integrations/api_issue_milestone_test.go index 35e5053cb..f1f306b76 100644 --- a/integrations/api_issue_milestone_test.go +++ b/integrations/api_issue_milestone_test.go @@ -44,4 +44,17 @@ func TestAPIIssuesMilestone(t *testing.T) { var apiMilestone2 structs.Milestone DecodeJSON(t, resp, &apiMilestone2) assert.EqualValues(t, "closed", apiMilestone2.State) + + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/milestones?token=%s", owner.Name, repo.Name, token), structs.CreateMilestoneOption{ + Title: "wow", + Description: "closed one", + State: "closed", + }) + resp = session.MakeRequest(t, req, http.StatusCreated) + DecodeJSON(t, resp, &apiMilestone) + assert.Equal(t, "wow", apiMilestone.Title) + assert.Equal(t, structs.StateClosed, apiMilestone.State) + + req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%d?token=%s", owner.Name, repo.Name, apiMilestone.ID, token)) + resp = session.MakeRequest(t, req, http.StatusNoContent) } diff --git a/modules/structs/issue_milestone.go b/modules/structs/issue_milestone.go index 2bfdcd6bf..ec940c260 100644 --- a/modules/structs/issue_milestone.go +++ b/modules/structs/issue_milestone.go @@ -28,6 +28,8 @@ type CreateMilestoneOption struct { Description string `json:"description"` // swagger:strfmt date-time Deadline *time.Time `json:"due_on"` + // enum: open,closed + State string `json:"state"` } // EditMilestoneOption options for editing a milestone diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index ee8393aec..adb9deaee 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -144,6 +144,11 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) { DeadlineUnix: timeutil.TimeStamp(form.Deadline.Unix()), } + if form.State == "closed" { + milestone.IsClosed = true + milestone.ClosedDateUnix = timeutil.TimeStampNow() + } + if err := models.NewMilestone(milestone); err != nil { ctx.Error(http.StatusInternalServerError, "NewMilestone", err) return diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 3c6186a93..bf011285f 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -11384,6 +11384,14 @@ "format": "date-time", "x-go-name": "Deadline" }, + "state": { + "type": "string", + "enum": [ + "open", + "closed" + ], + "x-go-name": "State" + }, "title": { "type": "string", "x-go-name": "Title"