Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API allow to create closed milestones #11745

Merged
13 changes: 13 additions & 0 deletions integrations/api_issue_milestone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions modules/structs/issue_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions routers/api/v1/repo/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11257,6 +11257,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"
Expand Down