#39 code clean up
This commit is contained in:
parent
82d9ef436f
commit
cdfad4c78c
2 changed files with 20 additions and 55 deletions
2
gogs.go
2
gogs.go
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return "0.12.1"
|
return "0.12.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client represents a Gogs API client.
|
// Client represents a Gogs API client.
|
||||||
|
|
|
@ -13,49 +13,45 @@ import (
|
||||||
|
|
||||||
type Milestone struct {
|
type Milestone struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
State StateType `json:"state"`
|
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
State StateType `json:"state"`
|
||||||
OpenIssues int `json:"open_issues"`
|
OpenIssues int `json:"open_issues"`
|
||||||
ClosedIssues int `json:"closed_issues"`
|
ClosedIssues int `json:"closed_issues"`
|
||||||
Closed *time.Time `json:"closed_at"`
|
Closed *time.Time `json:"closed_at"`
|
||||||
Deadline *time.Time `json:"due_on"`
|
Deadline *time.Time `json:"due_on"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
type CreateMilestoneOption struct {
|
type CreateMilestoneOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Deadline *time.Time `json:"due_on"`
|
Deadline *time.Time `json:"due_on"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EditMilestoneOption struct {
|
|
||||||
Title string `json:"title"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Deadline *time.Time `json:"due_on"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SetIssueMilestoneOption struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetRepoMilestone(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)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) {
|
func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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),
|
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
||||||
jsonHeader, bytes.NewReader(body), milestone)
|
}
|
||||||
|
|
||||||
|
type EditMilestoneOption struct {
|
||||||
|
Title *string `json:"title"`
|
||||||
|
Description *string `json:"description"`
|
||||||
|
State *string `json:"state"`
|
||||||
|
Deadline *time.Time `json:"due_on"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) {
|
func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) {
|
||||||
|
@ -71,34 +67,3 @@ 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)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ChangeMilestoneStatus(owner, repo string, id int64, open bool) (*Milestone, error) {
|
|
||||||
var action string
|
|
||||||
if open {
|
|
||||||
action = "open"
|
|
||||||
} else {
|
|
||||||
action = "close"
|
|
||||||
}
|
|
||||||
|
|
||||||
milestone := new(Milestone)
|
|
||||||
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones/%d/%s", owner, repo, id, action), nil, nil, milestone)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetIssueMilestone(owner, repo string, index int64) (*Milestone, error) {
|
|
||||||
milestone := new(Milestone)
|
|
||||||
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/milestone", owner, repo, index), nil, nil, &milestone)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) SetIssueMilestone(owner, repo string, index int64, opt SetIssueMilestoneOption) (*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/issues/%d/milestone", owner, repo, index), jsonHeader, bytes.NewReader(body), &milestone)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) DeleteIssueMilestone(owner, repo string, index int64) error {
|
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/milestone", owner, repo, index), nil, nil)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue