|
9 | 9 | "bytes"
|
10 | 10 | "encoding/json"
|
11 | 11 | "fmt"
|
| 12 | + "strings" |
12 | 13 | )
|
13 | 14 |
|
14 | 15 | // FileOptions options for all file APIs
|
@@ -120,14 +121,24 @@ func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, *Response, error
|
120 | 121 | return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil)
|
121 | 122 | }
|
122 | 123 |
|
123 |
| -// GetContents get the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir |
| 124 | +// GetContents get the metadata and contents of a file in a repository |
124 | 125 | // ref is optional
|
125 | 126 | func (c *Client) GetContents(owner, repo, ref, filepath string) (*ContentsResponse, *Response, error) {
|
126 | 127 | cr := new(ContentsResponse)
|
| 128 | + filepath = strings.TrimPrefix(filepath, "/") |
127 | 129 | resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/contents/%s?ref=%s", owner, repo, filepath, ref), jsonHeader, nil, cr)
|
128 | 130 | return cr, resp, err
|
129 | 131 | }
|
130 | 132 |
|
| 133 | +// ListContents gets a list of entries in a dir |
| 134 | +// ref is optional |
| 135 | +func (c *Client) ListContents(owner, repo, ref, filepath string) ([]*ContentsResponse, *Response, error) { |
| 136 | + cr := make([]*ContentsResponse, 0) |
| 137 | + filepath = strings.TrimPrefix(filepath, "/") |
| 138 | + resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/contents/%s?ref=%s", owner, repo, filepath, ref), jsonHeader, nil, &cr) |
| 139 | + return cr, resp, err |
| 140 | +} |
| 141 | + |
131 | 142 | // CreateFile create a file in a repository
|
132 | 143 | func (c *Client) CreateFile(owner, repo, filepath string, opt CreateFileOptions) (*FileResponse, *Response, error) {
|
133 | 144 | var err error
|
|
0 commit comments