38803cbe75
* refactor codes to remove structs and depend them on code.gitea.io/gitea/modules/structs * fix testing
54 lines
2 KiB
Go
54 lines
2 KiB
Go
// 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
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"code.gitea.io/gitea/modules/structs"
|
|
)
|
|
|
|
// Milestone is equal to structs.Milestone
|
|
type Milestone = structs.Milestone
|
|
|
|
// 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)
|
|
}
|
|
|
|
// GetMilestone get one milestone by repo name and milestone id
|
|
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)
|
|
}
|
|
|
|
// CreateMilestone create one milestone with options
|
|
func (c *Client) CreateMilestone(owner, repo string, opt structs.CreateMilestoneOption) (*Milestone, error) {
|
|
body, err := json.Marshal(&opt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
milestone := new(Milestone)
|
|
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
|
}
|
|
|
|
// EditMilestone modify milestone with options
|
|
func (c *Client) EditMilestone(owner, repo string, id int64, opt structs.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)
|
|
}
|
|
|
|
// 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
|
|
}
|