forgejo-sdk/gitea/issue_milestone.go

81 lines
2.8 KiB
Go
Raw Normal View History

2016-03-14 03:18:27 +00:00
// Copyright 2016 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gitea
2016-03-14 03:18:27 +00:00
import (
"bytes"
"encoding/json"
"fmt"
"time"
)
2016-03-14 03:18:27 +00:00
2016-11-10 09:44:00 +00:00
// Milestone milestone is a collection of issues on one repository
2016-03-14 03:18:27 +00:00
type Milestone struct {
ID int64 `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
2016-08-24 22:36:36 +01:00
State StateType `json:"state"`
2016-03-14 03:18:27 +00:00
OpenIssues int `json:"open_issues"`
ClosedIssues int `json:"closed_issues"`
2017-11-12 09:10:33 +00:00
// swagger:strfmt date-time
2016-03-14 03:18:27 +00:00
Closed *time.Time `json:"closed_at"`
2017-11-12 09:10:33 +00:00
// swagger:strfmt date-time
2016-03-14 03:18:27 +00:00
Deadline *time.Time `json:"due_on"`
}
2016-11-10 09:44:00 +00:00
// ListRepoMilestones list all the milestones of one repository
func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) {
milestones := make([]*Milestone, 0, 10)
return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones)
}
2016-11-10 09:44:00 +00:00
// GetMilestone get one milestone by repo name and milestone id
2016-08-24 22:36:36 +01:00
func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) {
milestone := new(Milestone)
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
}
2017-11-12 09:10:33 +00:00
// CreateMilestoneOption options for creating a milestone
2016-08-24 22:36:36 +01:00
type CreateMilestoneOption struct {
Title string `json:"title"`
Description string `json:"description"`
2017-11-12 09:10:33 +00:00
// swagger:strfmt date-time
2016-08-24 22:36:36 +01:00
Deadline *time.Time `json:"due_on"`
}
2016-11-10 09:44:00 +00:00
// CreateMilestone create one milestone with options
func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
milestone := new(Milestone)
2016-08-24 22:36:36 +01:00
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
}
2017-11-12 09:10:33 +00:00
// EditMilestoneOption options for editing a milestone
2016-08-24 22:36:36 +01:00
type EditMilestoneOption struct {
Title string `json:"title"`
2016-08-24 22:36:36 +01:00
Description *string `json:"description"`
State *string `json:"state"`
Deadline *time.Time `json:"due_on"`
}
2016-11-10 09:44:00 +00:00
// EditMilestone modify milestone with options
func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
milestone := new(Milestone)
return milestone, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone)
}
2016-11-10 09:44:00 +00:00
// DeleteMilestone delete one milestone by milestone id
func (c *Client) DeleteMilestone(owner, repo string, id int64) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil)
return err
}