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:
parent
5d880baff1
commit
316d2391df
1 changed files with 13 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue