Skip to content

Commit 1ac4618

Browse files
6543lafrikstechknowlogick
authored
API allow to create closed milestones (#11745)
* API allow to create closed milestones * set CloseDate too Co-authored-by: Lauris BH <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 19db3f4 commit 1ac4618

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

integrations/api_issue_milestone_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,17 @@ func TestAPIIssuesMilestone(t *testing.T) {
4444
var apiMilestone2 structs.Milestone
4545
DecodeJSON(t, resp, &apiMilestone2)
4646
assert.EqualValues(t, "closed", apiMilestone2.State)
47+
48+
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/milestones?token=%s", owner.Name, repo.Name, token), structs.CreateMilestoneOption{
49+
Title: "wow",
50+
Description: "closed one",
51+
State: "closed",
52+
})
53+
resp = session.MakeRequest(t, req, http.StatusCreated)
54+
DecodeJSON(t, resp, &apiMilestone)
55+
assert.Equal(t, "wow", apiMilestone.Title)
56+
assert.Equal(t, structs.StateClosed, apiMilestone.State)
57+
58+
req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%d?token=%s", owner.Name, repo.Name, apiMilestone.ID, token))
59+
resp = session.MakeRequest(t, req, http.StatusNoContent)
4760
}

modules/structs/issue_milestone.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type CreateMilestoneOption struct {
2828
Description string `json:"description"`
2929
// swagger:strfmt date-time
3030
Deadline *time.Time `json:"due_on"`
31+
// enum: open,closed
32+
State string `json:"state"`
3133
}
3234

3335
// EditMilestoneOption options for editing a milestone

routers/api/v1/repo/milestone.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
144144
DeadlineUnix: timeutil.TimeStamp(form.Deadline.Unix()),
145145
}
146146

147+
if form.State == "closed" {
148+
milestone.IsClosed = true
149+
milestone.ClosedDateUnix = timeutil.TimeStampNow()
150+
}
151+
147152
if err := models.NewMilestone(milestone); err != nil {
148153
ctx.Error(http.StatusInternalServerError, "NewMilestone", err)
149154
return

templates/swagger/v1_json.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11384,6 +11384,14 @@
1138411384
"format": "date-time",
1138511385
"x-go-name": "Deadline"
1138611386
},
11387+
"state": {
11388+
"type": "string",
11389+
"enum": [
11390+
"open",
11391+
"closed"
11392+
],
11393+
"x-go-name": "State"
11394+
},
1138711395
"title": {
1138811396
"type": "string",
1138911397
"x-go-name": "Title"

0 commit comments

Comments
 (0)