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 <art27@cantab.net>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
6543 2020-06-19 04:49:31 +00:00 committed by Lunny Xiao
parent 5d880baff1
commit 316d2391df

View file

@ -61,6 +61,7 @@ func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error)
type CreateMilestoneOption struct { type CreateMilestoneOption struct {
Title string `json:"title"` Title string `json:"title"`
Description string `json:"description"` Description string `json:"description"`
State StateType `json:"state"`
Deadline *time.Time `json:"due_on"` Deadline *time.Time `json:"due_on"`
} }
@ -82,7 +83,18 @@ func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption)
return nil, err return nil, err
} }
milestone := new(Milestone) 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 // EditMilestoneOption options for editing a milestone