From 181ccc696caa21211e80f29d36925a69d9b85218 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 2 Aug 2016 11:59:14 -0700 Subject: [PATCH] #35 code cleanup --- gogs.go | 2 +- issue_label.go | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/gogs.go b/gogs.go index e3cbe41..f6c6648 100644 --- a/gogs.go +++ b/gogs.go @@ -14,7 +14,7 @@ import ( ) func Version() string { - return "0.9.0" + return "0.10.0" } // Client represents a Gogs API client. diff --git a/issue_label.go b/issue_label.go index 1a59b15..7c80bb2 100644 --- a/issue_label.go +++ b/issue_label.go @@ -22,13 +22,13 @@ type LabelOption struct { } func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) { - labels := make([]*Label, 0) + labels := make([]*Label, 0, 10) return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels) } -func (c *Client) GetRepoLabel(owner, repo string, index int64) (*Label, error) { +func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) { label := new(Label) - return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, index), nil, nil, label) + return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label) } func (c *Client) CreateLabel(owner, repo string, opt LabelOption) (*Label, error) { @@ -41,18 +41,17 @@ func (c *Client) CreateLabel(owner, repo string, opt LabelOption) (*Label, error jsonHeader, bytes.NewReader(body), label) } -func (c *Client) EditLabel(owner, repo string, index int64, opt LabelOption) (*Label, error) { +func (c *Client) EditLabel(owner, repo string, id int64, opt LabelOption) (*Label, error) { body, err := json.Marshal(&opt) if err != nil { return nil, err } label := new(Label) - return label, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, index), - jsonHeader, bytes.NewReader(body), label) + return label, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label) } -func (c *Client) DeleteLabel(owner, repo string, index int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, index), nil, nil) +func (c *Client) DeleteLabel(owner, repo string, id int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil) return err } @@ -61,7 +60,7 @@ type IssueLabelsOption struct { } func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, error) { - labels := make([]*Label, 0) + labels := make([]*Label, 0, 5) return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil, &labels) } @@ -71,8 +70,7 @@ func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabels return nil, err } labels := make([]*Label, 0) - return labels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), - jsonHeader, bytes.NewReader(body), &labels) + return labels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels) } func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) { @@ -81,11 +79,10 @@ func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLa return nil, err } labels := make([]*Label, 0) - return labels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), - jsonHeader, bytes.NewReader(body), &labels) + return labels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels) } -func (c *Client) DeleteIssueLabel(owner, repo string, index int64, label int64) error { +func (c *Client) DeleteIssueLabel(owner, repo string, index, label int64) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil) return err }