feat: added repo ListContents and changed GetContents doc to talk about a single file (#485)
fix #484 Co-authored-by: Cameron Braid <cameron@drivenow.com.au> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/485 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: cameronbraid <cameronbraid@noreply.gitea.io> Co-committed-by: cameronbraid <cameronbraid@noreply.gitea.io>
This commit is contained in:
parent
95ed973c8d
commit
757f8bdb90
1 changed files with 12 additions and 1 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileOptions options for all file APIs
|
// FileOptions options for all file APIs
|
||||||
|
@ -120,14 +121,24 @@ func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, *Response, error
|
||||||
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil)
|
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetContents get the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir
|
// GetContents get the metadata and contents of a file in a repository
|
||||||
// ref is optional
|
// ref is optional
|
||||||
func (c *Client) GetContents(owner, repo, ref, filepath string) (*ContentsResponse, *Response, error) {
|
func (c *Client) GetContents(owner, repo, ref, filepath string) (*ContentsResponse, *Response, error) {
|
||||||
cr := new(ContentsResponse)
|
cr := new(ContentsResponse)
|
||||||
|
filepath = strings.TrimPrefix(filepath, "/")
|
||||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/contents/%s?ref=%s", owner, repo, filepath, ref), jsonHeader, nil, cr)
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/contents/%s?ref=%s", owner, repo, filepath, ref), jsonHeader, nil, cr)
|
||||||
return cr, resp, err
|
return cr, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListContents gets a list of entries in a dir
|
||||||
|
// ref is optional
|
||||||
|
func (c *Client) ListContents(owner, repo, ref, filepath string) ([]*ContentsResponse, *Response, error) {
|
||||||
|
cr := make([]*ContentsResponse, 0)
|
||||||
|
filepath = strings.TrimPrefix(filepath, "/")
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/contents/%s?ref=%s", owner, repo, filepath, ref), jsonHeader, nil, &cr)
|
||||||
|
return cr, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
// CreateFile create a file in a repository
|
// CreateFile create a file in a repository
|
||||||
func (c *Client) CreateFile(owner, repo, filepath string, opt CreateFileOptions) (*FileResponse, *Response, error) {
|
func (c *Client) CreateFile(owner, repo, filepath string, opt CreateFileOptions) (*FileResponse, *Response, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
Loading…
Reference in a new issue