From cdfad4c78ca6a880476a8ce11db1364822959348 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 24 Aug 2016 14:36:36 -0700 Subject: [PATCH] #39 code clean up --- gogs.go | 2 +- issue_milestone.go | 73 ++++++++++++---------------------------------- 2 files changed, 20 insertions(+), 55 deletions(-) diff --git a/gogs.go b/gogs.go index bf8e847..8939918 100644 --- a/gogs.go +++ b/gogs.go @@ -14,7 +14,7 @@ import ( ) func Version() string { - return "0.12.1" + return "0.12.2" } // Client represents a Gogs API client. diff --git a/issue_milestone.go b/issue_milestone.go index 3451886..365cce6 100644 --- a/issue_milestone.go +++ b/issue_milestone.go @@ -13,49 +13,45 @@ import ( type Milestone struct { ID int64 `json:"id"` - State StateType `json:"state"` Title string `json:"title"` Description string `json:"description"` + State StateType `json:"state"` OpenIssues int `json:"open_issues"` ClosedIssues int `json:"closed_issues"` Closed *time.Time `json:"closed_at"` 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 { Title string `json:"title"` Description string `json:"description"` 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) { 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) + return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), 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) { @@ -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) 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 -}