From 316d2391df85dcf14a088c3423476945e26faf20 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Fri, 19 Jun 2020 04:49:31 +0000 Subject: [PATCH] Allow Creating Closed Milestones (#373) Allow Creating Closed Milestones Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/373 Reviewed-by: Andrew Thornton Reviewed-by: Lunny Xiao --- gitea/issue_milestone.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gitea/issue_milestone.go b/gitea/issue_milestone.go index 1c24873..1270925 100644 --- a/gitea/issue_milestone.go +++ b/gitea/issue_milestone.go @@ -61,6 +61,7 @@ func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) type CreateMilestoneOption struct { Title string `json:"title"` Description string `json:"description"` + State StateType `json:"state"` Deadline *time.Time `json:"due_on"` } @@ -82,7 +83,18 @@ func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) return nil, err } milestone := new(Milestone) - return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone) + err = c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone) + + // make creating closed milestones need gitea >= v1.13.0 + // this make it backwards compatible + if err == nil && opt.State == StateClosed && milestone.State != StateClosed { + closed := StateClosed + return c.EditMilestone(owner, repo, milestone.ID, EditMilestoneOption{ + State: &closed, + }) + } + + return milestone, err } // EditMilestoneOption options for editing a milestone