From 8068507b500ea3ededecacc9d53c10da5f6ddd01 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 22 Oct 2015 17:42:42 -0400 Subject: [PATCH] work on #7 and #8 --- gogs.go | 7 ++++++- repo.go | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gogs.go b/gogs.go index f921090..98bc529 100644 --- a/gogs.go +++ b/gogs.go @@ -14,7 +14,7 @@ import ( ) func Version() string { - return "0.0.2" + return "0.0.4" } // Client represents a Gogs API client. @@ -33,6 +33,11 @@ func NewClient(url, token string) *Client { } } +// SetHTTPClient replaces default http.Client with user given one. +func (c *Client) SetHTTPClient(client *http.Client) { + c.client = client +} + func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, error) { req, err := http.NewRequest(method, c.url+"/api/v1"+path, body) if err != nil { diff --git a/repo.go b/repo.go index 5f51944..83de2de 100644 --- a/repo.go +++ b/repo.go @@ -70,6 +70,13 @@ func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, e http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo) } +// GetRepo returns information of a repository of given owner. +func (c *Client) GetRepo(owner, reponame string) (*Repository, error) { + repo := new(Repository) + return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), + http.Header{"content-type": []string{"application/json"}}, nil, repo) +} + // DeleteRepo deletes a repository of user or organization. func (c *Client) DeleteRepo(owner, repo string) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil)